Created
February 3, 2021 09:53
-
-
Save honzabilek4/09c97f576e1825deca88d2095a3fa41c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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