How to use the i18next.options 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 antvis / gatsby-theme-antv / @antv / gatsby-theme-antv / site / layouts / layout.tsx View on Github external
// empty
  }
  const pathPrefix = withPrefix('/').replace(/\/$/, '');
  const path = location.pathname.replace(pathPrefix, '');
  const currentLangKey = getCurrentLangKey(lngs, 'zh', path);

  const isHomePage =
    path === '/' ||
    path === `/${currentLangKey}` ||
    path === `/${currentLangKey}/`;

  i18n.init({
    lng: currentLangKey,
  });

  if (!i18n.options.resources) {
    i18n.init({
      resources,
    });
  }

  if (
    location.pathname === pathPrefix ||
    (children && children.type && (children as any).type.noLayout)
  ) {
    return children;
  }

  const getRediectUrl = () => {
    const list = redirects || [];
    for (let i = 0; i < list.length; i += 1) {
      const { from = '', to, keepUrl } = list[i] as {
github i18next / i18nextify / src / localize.js View on Github external
node,
  tOptions,
  parent,
  parentOverrideKey,
  currentDepth = 0,
  opts
) {
  const nodeIsNotExcluded = isNotExcluded(node);
  const nodeIsUnTranslated = isUnTranslated(node, opts);
  const realNodeIsUnTranslated = isUnTranslated(node); // ignoring forced threatment
  tOptions = getTOptions(tOptions, node);
  let parentKey = currentDepth === 0 ? parentOverrideKey : '';
  if (
    currentDepth > 0 &&
    parentOverrideKey &&
    !i18next.options.ignoreWithoutKey
  ) {
    parentKey = `${parentOverrideKey}.${currentDepth}`;
  }
  const overrideKey = getAttribute(node, i18next.options.keyAttr) || parentKey; // normally we use content as key, but optionally we allow to override it

  // translate node as one block
  const mergeFlag = getAttribute(node, 'merge');
  if (
    mergeFlag !== 'false' &&
    (mergeFlag === '' || canInline(node, tOptions))
  ) {
    if (nodeIsNotExcluded && nodeIsUnTranslated) {
      // wrap children into dummy node and remove that outer from translation
      const dummyNode = new VNode('I18NEXTIFYDUMMY', null, node.children);
      let key = removeIndent(toHTML(dummyNode), '')
        .replace('', '')
github MyBitFoundation / MyBit-Go.website / i18n.js View on Github external
i18n.getInitialProps = (req, namespaces) => {
  if (!namespaces) namespaces = i18n.options.defaultNS
  if (typeof namespaces === 'string') namespaces = [namespaces]

  req.i18n.toJSON = () => null // do not serialize i18next instance and send to client

  const initialI18nStore = {}
  req.i18n.languages.forEach(l => {
    initialI18nStore[l] = {}
    namespaces.forEach(ns => {
      initialI18nStore[l][ns] =
        (req.i18n.services.resourceStore.data[l] || {})[ns] || {}
    })
  })

  return {
    i18n: req.i18n, // use the instance on req - fixed language on request (avoid issues in race conditions with lngs of different users)
    initialI18nStore,
github revskill10 / next-template / packages / lib / i18n.js View on Github external
i18n.getInitialProps = (req, namespaces) => {
  if (!namespaces) namespaces = i18n.options.defaultNS
  if (typeof namespaces === 'string') namespaces = [namespaces]

  req.i18n.toJSON = () => {} // do not serialize i18next instance to prevent circular references on the client

  const initialI18nStore = {}
  req.i18n.languages.forEach((l) => {
    initialI18nStore[l] = {}
    namespaces.forEach((ns) => {
      initialI18nStore[l][ns] = (req.i18n.services.resourceStore.data[l] || {})[ns] || {}
    })
  })

  return {
    i18n: req.i18n, // use the instance on req - fixed language on request (avoid issues in race conditions with lngs of different users)
    initialI18nStore,
    initialLanguage: req.i18n.language
github mercari / mtc2018-web / web / i18n.js View on Github external
i18n.getInitialProps = (req, namespaces) => {
  if (!namespaces) { namespaces = i18n.options.defaultNS }
  if (typeof namespaces === 'string') { namespaces = [namespaces] }

  req.i18n.toJSON = () => null // do not serialize i18next instance and send to client

  const initialI18nStore = {}
  req.i18n.languages.forEach((l) => {
    initialI18nStore[l] = {}
    namespaces.forEach((ns) => {
      initialI18nStore[l][ns] = (req.i18n.services.resourceStore.data[l] || {})[ns] || {}
    })
  })

  return {
    i18n: req.i18n, // use the instance on req - fixed language on request (avoid issues in race conditions with lngs of different users)
    initialI18nStore,
    initialLanguage: req.i18n.language
github icebob / kantab / backend / mixins / i18next.mixin.js View on Github external
namespaces.forEach(ns => {
							if (i18next.options.ns && i18next.options.ns.indexOf(ns) < 0) i18next.options.ns.push(ns);
						});
github spaxjs / spax / packages / i18n / src / index.tsx View on Github external
export function useT(
  ns: string = i18n.options.defaultNS[0],
): [TFunction, (resources: ObjectOf) => void] {
  const { t } = useTranslation(ns.toLowerCase(), { useSuspense: false });
  return [
    t,
    (resources: ObjectOf) => {
      i18n.addResourceBundle(
        i18n.language, ns.toLowerCase(), resources, true, true,
      );
    },
  ];
}