Skip to content

Instantly share code, notes, and snippets.

@ljmotta
Last active August 12, 2020 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljmotta/170d9ce61765c9623c68d35d90e17181 to your computer and use it in GitHub Desktop.
Save ljmotta/170d9ce61765c9623c68d35d90e17181 to your computer and use it in GitHub Desktop.
// The Context typed with your Dictionary, which will be used by your components
export const myI18nCtx React.createContext<I18nContextType<MyDictionary>>({} as any);
export function App(props: Props) {
// Fallback locale and respective dictionary
const myI18nDefaults = { locale: "en", dictionary: english };
// All your dictionaries. The key of the Map object should follow the browser pattern
const myI18nDictionaries = new Map([
["en", english],
["pt", portuguese]
]);
return (
<I18nDictionariesProvider defaults={myI18nDefaults} dictionaries={myI18nDictionaries} ctx={myI18nCtx}>
<MyComponent />
</I18nDictionariesProvider>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment