-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): use Intl.PluralRules (#1486)
* refactor(core): i18n.loadLocaleData() is deprecated. Intl.PluralRules used instead. * refactor(core): use normalized locales in plural rules - always provide fallback to english. This is useful for cases with pseudo localization - allow to pass locales[] for all formatters, this unlocks possibility to override fallback for some locales * docs(core): add migration notes for PluralRules
- Loading branch information
1 parent
839f0b7
commit 3433452
Showing
29 changed files
with
339 additions
and
523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,39 @@ | ||
import React from 'react' | ||
import { getByText, render, act } from '@testing-library/react' | ||
import { i18n } from '@lingui/core' | ||
import { I18nProvider } from '@lingui/react' | ||
import { en, cs } from 'make-plural/plurals' | ||
import React from "react" | ||
import { getByText, render, act } from "@testing-library/react" | ||
import { i18n } from "@lingui/core" | ||
import { I18nProvider } from "@lingui/react" | ||
|
||
import { messages } from './locales/en/messages' | ||
import { messages as csMessages } from './locales/cs/messages' | ||
import App from './App' | ||
import { messages } from "./locales/en/messages" | ||
import { messages as csMessages } from "./locales/cs/messages" | ||
import App from "./App" | ||
|
||
i18n.load({ | ||
en: messages, | ||
cs: csMessages | ||
cs: csMessages, | ||
}) | ||
i18n.loadLocaleData({ | ||
en: { plurals: en }, | ||
cs: { plurals: cs } | ||
}); | ||
|
||
const TestingProvider = ({ children }: any) => ( | ||
<I18nProvider i18n={i18n}> | ||
{children} | ||
</I18nProvider> | ||
<I18nProvider i18n={i18n}>{children}</I18nProvider> | ||
) | ||
|
||
test('Test that lang is translated correctly in English' , () => { | ||
test("Test that lang is translated correctly in English", () => { | ||
act(() => { | ||
i18n.activate('en') | ||
i18n.activate("en") | ||
}) | ||
const { getByTestId, container } = render(<App />, { wrapper: TestingProvider }); | ||
expect(getByTestId('h3-title')).toBeInTheDocument() | ||
const { getByTestId, container } = render(<App />, { | ||
wrapper: TestingProvider, | ||
}) | ||
expect(getByTestId("h3-title")).toBeInTheDocument() | ||
expect(getByText(container, "Language switcher example:")).toBeDefined() | ||
}); | ||
}) | ||
|
||
test('Test that lang is translated correctly in Czech', () => { | ||
test("Test that lang is translated correctly in Czech", () => { | ||
act(() => { | ||
i18n.activate('cs') | ||
i18n.activate("cs") | ||
}) | ||
const { getByTestId, container } = render(<App />, { wrapper: TestingProvider }); | ||
expect(getByTestId('h3-title')).toBeInTheDocument() | ||
const { getByTestId, container } = render(<App />, { | ||
wrapper: TestingProvider, | ||
}) | ||
expect(getByTestId("h3-title")).toBeInTheDocument() | ||
expect(getByText(container, "Příklad přepínače jazyků:")).toBeDefined() | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.