Skip to content

Instantly share code, notes, and snippets.

@honzabilek4
Created February 3, 2021 09:53
Show Gist options
  • Save honzabilek4/09c97f576e1825deca88d2095a3fa41c to your computer and use it in GitHub Desktop.
Save honzabilek4/09c97f576e1825deca88d2095a3fa41c to your computer and use it in GitHub Desktop.
import i18next from "i18next";
import LocalazyMeta from "./localazy-meta";
import enJson from "./locales/en.json";
import frJson from "./locales/fr.json";
import csJson from "./locales/cs.json";
export const i18n = i18next;
export const getSupportedLangCodes = () => {
return LocalazyMeta.languages.map((l) => l.language);
};
export const getBaseLanguage = () => {
return LocalazyMeta.baseLocale;
};
export const getCurrentLanguage = () => {
return window.localStorage.i18nextLng || "en";
};
export const getLanguages = () => {
return LocalazyMeta.languages;
};
export const initI18n = (callback) => {
i18next.init(
{
lng: getBaseLanguage(),
fallbackLng: getBaseLanguage(),
debug: true,
supportedLngs: getSupportedLangCodes(),
resources: {
en: {
translation: enJson,
},
fr: {
translation: frJson,
},
cs: {
translation: csJson,
},
},
},
function (err, t) {
callback();
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment