How to use the i18next.createInstance 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 Talend / ui / packages / datagrid / src / translate.js View on Github external
import { createInstance } from 'i18next';
import { setI18n, getI18n } from 'react-i18next';

export default function getDefaultT() {
	return getI18n().t.bind(getI18n());
}

if (!getI18n()) {
	// eslint-disable-next-line no-console
	console.warn('@talend/react-datagrid used without i18n host.');
	setI18n(createInstance({}, () => {}));
}
github poooi / poi / views / env-parts / i18next.es View on Github external
switch (window.language.substr(0, 2).toLowerCase()) {
    case 'zh':
      window.language = 'zh-TW'
      break
    case 'ja':
      window.language = 'ja-JP'
      break
    case 'ko':
      window.language = 'ko-KR'
      break
    default:
      window.language = 'en-US'
  }
}

const i18next = I18next.createInstance()

i18next.use(reactI18nextModule).init({
  lng: window.language,
  fallbackLng: false,
  resources: mainPoiRes,
  ns: mainPoiNs,
  defaultNS: 'others',
  interpolation: {
    escapeValue: false,
  },
  returnObjects: true, // allow returning objects
  debug: dbg && dbg.extra('i18next').isEnabled(),
  react: {
    wait: false,
    nsMode: 'fallback',
    usePureComponent: true,
github antvis / gatsby-theme-antv / @antv / gatsby-theme-antv / site / components / withProvider.tsx View on Github external
import React from 'react';
import { I18nextProvider, initReactI18next } from 'react-i18next';
import i18next from 'i18next';
import source from '../common.json';

const i18n = i18next.createInstance();
i18n
  .use(initReactI18next) // passes i18n down to react-i18next
  .init({
    initImmediate: false,
    resources: {
      en: {
        translation: { ...source },
      },
    },
    fallbackLng: 'zh',
    keySeparator: false,
    react: {
      useSuspense: false,
    },
  });
github ProjectMirador / mirador / src / i18n.js View on Github external
export default () => {
  // Load translations for each language
  const resources = {
    de,
    en,
    fr,
    ja,
    nl,
    'pt-BR': ptBr,
    'zh-CN': zhCn,
    'zh-TW': zhTw,
  };

  const instance = i18n.createInstance();
  instance
    .use(initReactI18next)
    .init({
      fallbackLng: 'en',
      interpolation: {
        escapeValue: false, // react is already safe from xss
      },
      lng: 'en',
      resources,
    });

  return instance;
};
github perrin4869 / i18next-fetch-backend / test / index.js View on Github external
it('should fail to load non existent language translation', (cb) => {
    const i18next = createInstance();

    i18next.use(FetchBackend).init(
      {
        fallbackLng: 'de',
        ns: 'translation',
        backend: {
          loadPath: 'http://localhost:3000/{{lng}}/{{ns}}.json',
        },
      },
      (err) => {
        expect(err).to.deep.equal([
          'failed loading http://localhost:3000/de/translation.json',
        ]);

        cb();
      },
github fullstack-development / react-redux-starter-kit / src / services / i18n / i18nContainer.ts View on Github external
const initializeI18n = () => {
  const i18n = i18next.createInstance();
  i18n
    .use(languageDetector)
    .use(initReactI18next)
    .init({
      resources,
      fallbackLng: FALLBACK_LANGUAGE,
      interpolation: {
        format: (value, format) => {
          if (format === 'uppercase') { return value.toUpperCase(); }
          return value;
        },
      },
    });

  const originalTranslator = i18n.t.bind(i18n);
  i18n.t = ((key: string | string[] | ITranslateObject | ITranslateKey, options: {}) => {
github acl-services / paprika / packages / L10n / src / i18n.js View on Github external
export const i18n = locales => {
  const i18nConfig = {
    lng: defaultLocale,
    fallbackLng: defaultLocale,
    lowerCaseLng: true,
    resources: locales || paprikaLocales,
  };

  const newInstance = i18next.createInstance(i18nConfig, err => {
    if (err) return console.log("something went wrong loading i18next", err);
    return null;
  });

  return newInstance;
};
github SilverDecisions / SilverDecisions / src / i18n / i18n.js View on Github external
static init(lng){
        i18n.language = lng;
        i18n.$instance = i18next.createInstance({
            lng: lng,
            fallbackLng: 'en',
            resources: {
                en: {
                    translation: en
                },
                pl: {
                    translation: pl
                },
                it: {
                    translation: it
                },
                de: {
                    translation: de
                },
                fr: {