diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-10-26 21:54:36 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-10-26 21:54:36 +0200 |
| commit | ed9f269a78062f0d9a805b91b95fff5f479098ac (patch) | |
| tree | a6794933b3994ded3dcc8992b353ec9e9c07532f /htdocs/src/js/i18n/i18n.js | |
| parent | 1d272eac38ebb310e360891a3a717447a1d0547a (diff) | |
feat: translate the app - two locales available: fr and en
Diffstat (limited to 'htdocs/src/js/i18n/i18n.js')
| -rw-r--r-- | htdocs/src/js/i18n/i18n.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/htdocs/src/js/i18n/i18n.js b/htdocs/src/js/i18n/i18n.js new file mode 100644 index 0000000..6bdc7cd --- /dev/null +++ b/htdocs/src/js/i18n/i18n.js @@ -0,0 +1,42 @@ +import I18n from 'i18n-js'; +import en from './locales/en'; +import fr from './locales/fr'; + +const supportedLanguages = [ + { + code: 'en', + label: 'English', + translations: en, + }, + { + code: 'fr', + label: 'Français', + translations: fr, + }, +]; + +supportedLanguages.forEach((locale) => { + I18n.translations[locale.code] = locale.translations; +}); + +function setLocale(locale) { + I18n.locale = locale; +} + +function currentLocale() { + return I18n.currentLocale(); +} + +function translate(name, params = {}) { + return I18n.t(name, params); +} + +const { defaultLocale } = I18n; + +export { + supportedLanguages, + setLocale, + translate, + defaultLocale, + currentLocale, +}; |
