How to use the i18next.loadNamespaces function in i18next

To help you get started, we’ve selected a few i18next examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github i18next / i18next / test / typescript / i18next-tests.ts View on Github external
// or fix the namespace to anotherNamespace
const anotherNamespace = i18next.getFixedT(null, 'anotherNamespace')
const x: string = anotherNamespace('anotherNamespaceKey') // no need to prefix ns i18n.t('anotherNamespace:anotherNamespaceKey');

i18next.changeLanguage('en', (err: any, t: i18next.TranslationFunction) => {
  if (err) {
    console.log('something went wrong loading', err)
    return
  }
  t('key') // -> same as i18next.t
})

i18next.loadNamespaces('myNamespace', (err: any, t: i18next.TranslationFunction) => {
  /* resources have been loaded */
})
i18next.loadNamespaces(
  ['myNamespace1', 'myNamespace2'],
  (err: any, t: i18next.TranslationFunction) => {
    /* resources have been loaded */
  },
)

i18next.loadLanguages('de', (err: any, t: i18next.TranslationFunction) => {
  /* resources have been loaded */
})
i18next.loadLanguages(['de', 'fr'], (err: any, t: i18next.TranslationFunction) => {
  /* resources have been loaded */
})

// reload all
i18next.reloadResources()
github i18next / i18next / test / typescript / i18next-tests.ts View on Github external
updateContent()
  },
)

i18next.init(
  {
    ns: ['common', 'moduleA', 'moduleB'],
    defaultNS: 'moduleA',
  },
  (err: any, t: i18next.TranslationFunction) => {
    i18next.t('myKey') // key in moduleA namespace (defined default)
    i18next.t('common:myKey') // key in common namespace
  },
)

i18next.loadNamespaces('anotherNamespace', (err: any, t: i18next.TranslationFunction) => {
  /* ... */
})

// fallback to one language
i18next.init(
  {
    lng: 'en-GB',
  },
  () => {
    i18next.t('i18n') // -> "Internationalisation"
    i18next.t('i18n_short') // -> "i18n" (from en.json)

    // force loading en
    i18next.t('i18n', { lng: 'en' }) // -> "Internationalization"
  },
)
github i18next / i18next / test / typescript / i18next-tests.ts View on Github external
const de = i18next.getFixedT('de')
const z: string = de('myKey')

// or fix the namespace to anotherNamespace
const anotherNamespace = i18next.getFixedT(null, 'anotherNamespace')
const x: string = anotherNamespace('anotherNamespaceKey') // no need to prefix ns i18n.t('anotherNamespace:anotherNamespaceKey');

i18next.changeLanguage('en', (err: any, t: i18next.TranslationFunction) => {
  if (err) {
    console.log('something went wrong loading', err)
    return
  }
  t('key') // -> same as i18next.t
})

i18next.loadNamespaces('myNamespace', (err: any, t: i18next.TranslationFunction) => {
  /* resources have been loaded */
})
i18next.loadNamespaces(
  ['myNamespace1', 'myNamespace2'],
  (err: any, t: i18next.TranslationFunction) => {
    /* resources have been loaded */
  },
)

i18next.loadLanguages('de', (err: any, t: i18next.TranslationFunction) => {
  /* resources have been loaded */
})
i18next.loadLanguages(['de', 'fr'], (err: any, t: i18next.TranslationFunction) => {
  /* resources have been loaded */
})
github node-red / node-red / packages / node_modules / @node-red / util / lib / i18n.js View on Github external
fs.readdir(dir,function(err, files) {
                if (err) {
                    resolve();
                } else {
                    files.forEach(function(f) {
                        if (fs.existsSync(path.join(dir,f,file))) {
                            resourceMap[namespace].lngs.push(f);
                        }
                    });
                    i18n.loadNamespaces(namespace,function() {
                        resolve();
                    });
                }
            })
        });
github SAP / cloud-commerce-spartacus-storefront / projects / core / src / i18n / i18next / i18next-translation.service.ts View on Github external
const translate = () => {
        if (i18next.exists(namespacedKey, options)) {
          subscriber.next(i18next.t(namespacedKey, options));
        } else {
          if (whitespaceUntilLoaded) {
            subscriber.next(this.NON_BREAKING_SPACE);
          }
          i18next.loadNamespaces(chunkName, () => {
            if (!i18next.exists(namespacedKey, options)) {
              this.reportMissingKey(key, chunkName);
              subscriber.next(this.getFallbackValue(namespacedKey));
            } else {
              subscriber.next(i18next.t(namespacedKey, options));
            }
          });
        }
      };
github BadrIT / bractal / src / modules / modulesDocs / locales / index.js View on Github external
const loadLocales = () => {
  i18next.addResourceBundle('en', 'modulesDocs', {
    metadata: {
      name: 'modulesDocs',
      displayName: 'Modules Docs Module',
      description: 'This module shows the very basic usage of Bractal, and it simply does only one job, which is loading and showing all home pages of all the loaded modules',
    },
    home: {
      menuTitle: 'Modules Docs',
    },
  }, true, true);

  i18next.loadNamespaces('modulesDocs');
};
github SAP / cloud-commerce-spartacus-storefront / projects / core / src / i18n / i18next / i18next-translation.service.ts View on Github external
loadChunks(chunkNames: string | string[]): Promise {
    return i18next.loadNamespaces(chunkNames);
  }
github crimx / ext-saladict / src / _helpers / storybook.tsx View on Github external
return fn => {
    i18next.loadNamespaces(ns)
    return 
  }
}
github i18next / i18nextify / src / index.js View on Github external
function changeNamespace(ns) {
  if (!ns && lastOptions.namespaceFromPath) ns = getPathname();
  lastOptions.ns.push(ns);
  lastOptions.defaultNS = ns;

  i18next.loadNamespaces(lastOptions.ns, () => {
    i18next.setDefaultNamespace(ns);
  });
}