How to use the i18next.on 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
(err: any, t: i18next.TranslationFunction) => {
    if (err) {
      console.log('something went wrong loading', err)
      return
    }
    t('key') // -> same as i18next.t
  },
)

i18next.on('initialized', options => {})
i18next.on('loaded', loaded => {})
i18next.on('failedLoading', (lng: string, ns: string, msg: string) => {})
i18next.on('missingKey', (lngs: string[], namespace: string, key: string, res: string) => {})
i18next.on('added', (lng: string, ns: string) => {})
i18next.on('removed', (lng: string, ns: string) => {})
i18next.on('languageChanged', (lng: string) => {})
i18next.on('customEvent', () => {})

i18next.getResource('en', 'test', 'key')
i18next.getResource('en', 'test', 'key', { keySeparator: '-' })

i18next.addResource('en', 'test', 'key', 'value')
i18next.addResource('en', 'test', 'key', 'value', {
  keySeparator: '-',
  silent: false,
})

i18next.addResources('en', 'test', { key: 'value' })

i18next.addResourceBundle(
  'en',
  'translations',
github i18next / i18next / test / typescript / i18next-tests.ts View on Github external
},
  (err: any, t: i18next.TranslationFunction) => {
    if (err) {
      console.log('something went wrong loading', err)
      return
    }
    t('key') // -> same as i18next.t
  },
)

i18next.on('initialized', options => {})
i18next.on('loaded', loaded => {})
i18next.on('failedLoading', (lng: string, ns: string, msg: string) => {})
i18next.on('missingKey', (lngs: string[], namespace: string, key: string, res: string) => {})
i18next.on('added', (lng: string, ns: string) => {})
i18next.on('removed', (lng: string, ns: string) => {})
i18next.on('languageChanged', (lng: string) => {})
i18next.on('customEvent', () => {})

i18next.getResource('en', 'test', 'key')
i18next.getResource('en', 'test', 'key', { keySeparator: '-' })

i18next.addResource('en', 'test', 'key', 'value')
i18next.addResource('en', 'test', 'key', 'value', {
  keySeparator: '-',
  silent: false,
})

i18next.addResources('en', 'test', { key: 'value' })

i18next.addResourceBundle(
  'en',
github berty / berty / client / react-native / common / i18n / index.web.js View on Github external
resources: languages,
  interpolation: { escapeValue: false }, // not needed for react
  react: {
    wait: true,
    nsMode: 'default',
  },
}

i18n
  .use(LanguageDetector)
  .use(reactI18nextModule) // passes i18n down to react-i18next
  .init(options, () => {
    I18nManager.forceRTL(isRTL())
  })

i18n.on('languageChanged', language => {
  if (!languages.hasOwnProperty(language)) {
    return
  }

  console.log(i18n.language)
  console.log(i18n.dir(i18n.language))
  I18nManager.forceRTL(isRTL())
})

export default i18n
export { languages, isRTL }
github balance-io / balance-common / src / languages / index.js View on Github external
cz: czech,
  pt: portuguese,
  ru: russian,
  pl: polish,
  el: greek,
};

i18next.init({
  lng: 'en',
  debug: true, // TODO: only debug in dev mode
  resources,
});

export const updateLanguage = code => i18next.changeLanguage(code);

i18next.on('languageChanged', () => {});

export default i18next;
github funsocietyirc / MrNodeBot / lib / i18next.js View on Github external
initImmediate: _.getBoolean(_.get(config, 'localization.initImmediate'), false),
        // path where resources get loaded from
        backend: {
            loadPath: path.normalize(`${__dirname}/../localization/{{lng}}/{{ns}}.json`),
            // path to post missing resources
            addPath: path.normalize(`${__dirname}/../localization/{{lng}}/{{ns}}.missing.json`),
            // jsonIndent to use when storing json files
            jsonIndent: 2,
        },
    });

// Log Initialization
i18next.on('initialized', options => logger.info('Localization Initialized'));

// Log loaded
i18next.on('loaded', loaded => logger.info('Localization has finished loading assets'));

// Log added
i18next.on('added', (lng, ns) => logger.info(`Translation added ${lng} ${ns}`));

// Log Failed loading
i18next.on('failedLoading', (lng, ns, msg) => logger.error('Invalid Translation', {
    lng,
    ns,
    msg,
}));

// Log Missing key
i18next.on('missingKey', (lng, namespace, key, res) => logger.error('Translation is missing key', {
    lng,
    namespace,
    key,
github pnp / PnP / Solutions / Business.StarterIntranet / app / src / modules / LocalizationModule.ts View on Github external
public ensureResourcesLoaded(callback: any) {

        // We need to ensure the i18n global object is set up before getting resources
        // In some cases, the object was not initialized during the viewmodel execution resulting of empty strings for translations (i.e display templates loading are not managed by our code)
        // If translation returns 'undefined', the i18next object was not initialized, so we wait for init using the native i18next event
        if (!i18n.t("LCID")) {
            i18n.on("initialized", (options) => {

                this.initMomentLocale(options.lng);
                callback();
            });
        } else {
            this.initMomentLocale(i18n.t("languageLabel").toLowerCase());
            callback();
        }
    }
github allure-framework / allure2 / allure-generator / src / main / javascript / utils / translation.js View on Github external
export function addTranslation(lang, json) {
    i18next.on('initialized', () => {
        i18next.services.resourceStore.addResourceBundle(lang, i18next.options.ns[0], json, true, true);
    });
}
github wavesplatform / WavesGUI / src / modules / app / initialize / AppConfig.js View on Github external
i18next.on('initialized', () => {
                    const localeData = WavesApp.getLocaleData().separators;

                    BigNumber.config.set({
                        ROUNDING_MODE: BigNumber.ROUND_MODE.ROUND_DOWN,
                        FORMAT: tsUtils.merge(Object.create(null), BIG_NUMBER_FORMAT, {
                            groupSeparator: localeData.group,
                            decimalSeparator: localeData.decimal
                        })
                    });

                    if (WavesApp.isDesktop()) {
                        transfer('setLanguage', i18next.language);
                    }

                    i18next.on('languageChanged', () => {
                        if (WavesApp.isDesktop()) {
                            transfer('setLanguage', i18next.language);
                        }

                        const localeData = WavesApp.getLocaleData().separators;

                        BigNumber.config.set({
                            ROUNDING_MODE: BigNumber.ROUND_MODE.ROUND_DOWN,
                            FORMAT: tsUtils.merge(Object.create(null), BIG_NUMBER_FORMAT, {
                                groupSeparator: localeData.group,
                                decimalSeparator: localeData.decimal
                            })
                        });
                    });
                });
            }
github SAP / cloud-commerce-spartacus-storefront / projects / core / src / i18n / i18next / i18next-translation.service.ts View on Github external
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));
            }
          });
        }
      };

      translate();
      i18next.on('languageChanged', translate);
      return () => i18next.off('languageChanged', translate);
    });
  }
github springtype-org / springtype / src / packages / i18n / src / Translator.ts View on Github external
onLanguageChanged(eventHandler: LanguageChangedHandler) {
        i18next.on('languageChanged', eventHandler);
    }