How to use the i18next.changeLanguage 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 Frojd / Wagtail-Pipit / Company-Project / frontend / src / i18n / index.js View on Github external
i18next.init({
    languages: ['sv'],
    fallbackLng: ['sv'],
    resources: {
        sv: {
            translation: sv,
        },
    },
});

// Update this to reflect what language your page should use
const lang = () => {
    return 'sv';
};

i18next.changeLanguage(lang());

export default i18next;
github altola / sitecore-jss-react-starter / src / src / RouteHandler.js View on Github external
updateLanguage() {
    const newLanguage = this.props.route.match.params.lang || this.state.defaultLanguage;

    if (i18n.language !== newLanguage) {
      this.languageIsChanging = true;

      i18n.changeLanguage(newLanguage, () => {
        this.languageIsChanging = false;

        // if the component is not mounted, we don't care
        // (next time it mounts, it will render with the right language context)
        if (this.componentIsMounted) {
          // after we change the i18n language, we need to force-update React,
          // since otherwise React won't know that the dictionary has changed
          // because it is stored in i18next state not React state
          this.forceUpdate();
        }
      });
    }
  }
github i18next / i18next / test / typescript / i18next-tests.ts View on Github external
const changeLng = (lng: string) => {
  i18next.changeLanguage(lng)
}
github berty / berty / client / react-native / app / common / locale / index.js View on Github external
AsyncStorage.getItem('@BertyApp:i18n-language', (err, language) => {
      if (err) {
        return
      }

      if (!languages.hasOwnProperty(language)) {
        return
      }

      i18n.changeLanguage(language)
    })
  })
github springtype-org / springtype / src / packages / i18n / src / Translator.ts View on Github external
return new Promise((resolve) => {
            i18next.changeLanguage(language, resolve);
        });
    }
github berty / berty / client / react-native / common / i18n / index.js View on Github external
AsyncStorage.getItem('@BertyApp:i18n-language', (err, language) => {
      if (err) {
        return
      }

      if (!languages.hasOwnProperty(language)) {
        return
      }

      i18n.changeLanguage(language)
    })
  })
github Sitecore / jss / samples / advanced-sample-react / src / app / actions.js View on Github external
const dispatchRoute = (dispatch, routeUrl, params) => {
  const routeParams = parseRouteUrl(routeUrl);
  if (!routeParams) {
    return;
  }

  if (routeParams.lang) {
    i18n.changeLanguage(routeParams.lang);
  }

  const route = routeParams.sitecoreRoute ? `/${routeParams.sitecoreRoute}` : '/';
  dispatch({
    type: types.ROUTE_CHANGE_STARTED,
    payload: {
      path: route,
    },
  });

  const language = routeParams.lang || DEFAULT_LANGUAGE;
  fetchRouteData(route, language, params)
    .then((data) => {
      dispatch(push(routeUrl));
      dispatch({
        type: types.ROUTE_CHANGE_COMPLETED,
github spaxjs / spax / packages / i18n / src / index.tsx View on Github external
(lng: string) => {
      i18n.changeLanguage(lng);
      setV(i18n.language);
    },
  ];
github ronggang / PT-Plugin-Plus / src / background / i18n.ts View on Github external
i18next.changeLanguage(langCode).then(() => {
                resolve(langCode);
              });
            })
            .fail(e => {
              if (langCode != "en") {
                this.reset("en").then(() => {
                  resolve(langCode);
                });
                return;
              }
              reject(e);
            });
          return;
        }
        i18next.changeLanguage(langCode).then(() => {
          resolve(langCode);
        });
        return;
      }
      resolve(langCode);
    });
  }
github CKGrafico / Frontend-Boilerplates / src / app / app.i18n.ts View on Github external
export function changeCurrentLanguage(language: Language): void {
  i18n.changeLanguage(language);
}