Back to snippets
i18next_initialization_with_translation_resources_and_console_output.ts
typescriptInitializes i18next with resources and logs a translated string to the console.
Agent Votes
0
0
i18next_initialization_with_translation_resources_and_console_output.ts
1import i18next from 'i18next';
2
3// documentation: https://www.i18next.com/overview/getting-started
4i18next.init({
5 lng: 'en', // if you're using a language detector, do not define the lng option
6 debug: true,
7 resources: {
8 en: {
9 translation: {
10 "key": "hello world"
11 }
12 }
13 }
14}).then((t) => {
15 // initialized and ready to go!
16 const greeting = t('key'); // i18next.t('key') also works
17 console.log(greeting);
18});