How to use the i18next.exists 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
const t2: i18next.TranslationFunction<{ value: string }> = (
  key: string|string[],
  options?: i18next.TranslationOptions,
) => ({ value: 'asd' })
const t3: i18next.TranslationFunction = (
  key: string | string[],
  options?: i18next.TranslationOptions,
) => ''
const t4: i18next.TranslationFunction = (
  key: KeyList | KeyList[],
  options?: i18next.TranslationOptions,
) => ''

i18next.exists('friend');
i18next.exists(['friend', 'tree']);
i18next.exists('friend', { myVar: 'someValue' });
i18next.exists(['friend', 'tree'], { myVar: 'someValue' });

i18next.t("friend", { myVar: "someValue" });
i18next.t(["friend", "tree"], { myVar: "someValue" });
i18next.t("friend", { myVar: "someValue" });
i18next.t(["friend", "tree"], { myVar: "someValue" });

// NOTION: disable no-unnecessary-generics for generic pattern test.
/* tslint:disable:no-unnecessary-generics */
interface ExWithT extends i18next.WithT {
  t(keys: Keys|Keys[], options?: i18next.TranslationOptions): R;
  t(keys: Keys|Keys[], options?: i18next.TranslationOptions): R;
  t(keys: Keys|Keys[]): R;
}

type OtherKeyList = "private" | "public";
github i18next / i18next / test / typescript / i18next-tests.ts View on Github external
key: string|string[],
  options?: i18next.TranslationOptions,
) => ({ value: 'asd' })
const t3: i18next.TranslationFunction = (
  key: string | string[],
  options?: i18next.TranslationOptions,
) => ''
const t4: i18next.TranslationFunction = (
  key: KeyList | KeyList[],
  options?: i18next.TranslationOptions,
) => ''

i18next.exists('friend');
i18next.exists(['friend', 'tree']);
i18next.exists('friend', { myVar: 'someValue' });
i18next.exists(['friend', 'tree'], { myVar: 'someValue' });

i18next.t("friend", { myVar: "someValue" });
i18next.t(["friend", "tree"], { myVar: "someValue" });
i18next.t("friend", { myVar: "someValue" });
i18next.t(["friend", "tree"], { myVar: "someValue" });

// NOTION: disable no-unnecessary-generics for generic pattern test.
/* tslint:disable:no-unnecessary-generics */
interface ExWithT extends i18next.WithT {
  t(keys: Keys|Keys[], options?: i18next.TranslationOptions): R;
  t(keys: Keys|Keys[], options?: i18next.TranslationOptions): R;
  t(keys: Keys|Keys[]): R;
}

type OtherKeyList = "private" | "public";
github queicherius / react-globe / src / tPlural.js View on Github external
const handleZero = (messages, options) => {
  // When the language is no english, fallback to the 'one' string,
  // because the "t" translation function will pick the correct plural that way
  var fallback = i18next.language === 'en' || !i18next.exists(messages.one, options)
    ? messages.many
    : messages.one

  return t(messages.zero || fallback, options)
}
github pingcap / tidb-dashboard / ui / lib / client / index.tsx View on Github external
instance.interceptors.response.use(undefined, async function (err) {
    const { response, config } = err
    const errorStrategy = config.errorStrategy as ErrorStrategy
    const method = (config.method as string).toLowerCase()

    let errCode: string
    let content: string
    if (err.message === 'Network Error') {
      errCode = 'error.network'
    } else {
      errCode = response?.data?.code
    }
    if (errCode !== ERR_CODE_OTHER && i18next.exists(errCode)) {
      content = i18next.t(errCode)
    } else {
      content =
        response?.data?.message || err.message || i18next.t(ERR_CODE_OTHER)
    }
    err.message = content

    if (errCode === 'error.api.unauthorized') {
      // Handle unauthorized error in a unified way
      if (!routing.isLocationMatch('/') && !routing.isSignInPage()) {
        message.error({ content, key: errCode })
      }
      auth.clearAuthToken()
      singleSpa.navigateToUrl('#' + routing.signInRoute)
      err.handled = true
    } else if (errorStrategy === ErrorStrategy.Default) {
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 RocketChat / Rocket.Chat / .storybook / mocks / providers.js View on Github external
	translate.has = (key) => key && i18next.exists(key);
github openpitrix / dashboard / src / hoc / trans.js View on Github external
export const __ = (key, ...rest) => {
  return (exists(key) && t(key, ...rest)) || key;
};
github SAP / cloud-commerce-spartacus-storefront / projects / core / src / i18n / i18next / i18next-translation.service.ts View on Github external
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 Bit-Nation / BITNATION-Pangea-mobile / src / PangeaCommon / i18n.js View on Github external
i18n.tf = (key, fallbackKey) => (i18n.exists(key) ? i18n.t(key) : i18n.ifExists(fallbackKey));
github hubot-js / hubot.js / src / lib / i18n.js View on Github external
function t(key, vars) {
  if (isNaN(key) && i18n.exists(key)) {
    return vars ? i18n.t(key, vars) : i18n.t(key);
  }

  return key;
}