Search code examples
reactjsinternationalizationi18nextreact-i18next

react JS i18n locales


I'm using react-i18next in my reactJS app

is something like this possible:

i18n
    .use(LanguageDetector)
    .init({
        // we init with resources
        resources: {
            en: {en},
            de: {
                application: {
                    name: 'Dashbord DE',
                }
            }
        },

Nesting/grouping the locales

and print them like this:

t('application.dashboard')

Problem is that not the translation is printet ... my key application.dashboard is printed ...

Thanks.

update:

de: {
   application: {
      foo: "adsad",
      name: {
        firstname: 'max'
      },
   }
 }

This is not working:

t('application:name.firstname')

Solution

  • t('application:name') will do the trick. application acts as namespace (loaded filename) and needs per default be separated with :. While all other nestings are separated with ., eg.:

    de: {
           application: {
              name: {
                firstname: 'max'
              },
           }
        }
    

    t('application:name.firstname'); // -> max