-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Locales: Folder names follow ISO 639 & 3166
- Loading branch information
Showing
7 changed files
with
68 additions
and
27 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
import i18next from 'i18next' | ||
import backend from 'i18next-node-fs-backend' | ||
import { getItem } from '../utilities/localStorage' | ||
import { readdirSync } from 'fs' | ||
import { join } from 'path' | ||
|
||
/** Initialize a i18next instance. */ | ||
i18next | ||
.use(backend) | ||
.init({ | ||
fallbackLng: getItem('language') || 'en', | ||
ns: ['wallet'], | ||
defaultNS: 'wallet', | ||
debug: process.env.NODE_ENV === 'dev', | ||
backend: { | ||
loadPath: join(__dirname, '/../locales/{{lng}}/{{ns}}.json'), | ||
addPath: join(__dirname, '/../locales/{{lng}}/{{ns}}.missing.json'), | ||
jsonIndent: 2 | ||
}, | ||
load: 'current', | ||
languages: ['en', 'sl'], | ||
interpolation: { escapeValue: false } | ||
}) | ||
/** | ||
* Start i18next. | ||
* @function start | ||
* @return {object} i18next instance. | ||
*/ | ||
const start = () => { | ||
/** Get available languages. */ | ||
const languages = readdirSync(join(__dirname, '..', 'locales')) | ||
|
||
export default i18next | ||
/** Get saved language. */ | ||
let fallbackLng = getItem('language') | ||
|
||
/** Check if the language exists or revert to default. */ | ||
fallbackLng = languages.includes(fallbackLng) === true | ||
? fallbackLng | ||
: 'en-US' | ||
|
||
/** Initialize a i18next instance. */ | ||
return i18next | ||
.use(backend) | ||
.init({ | ||
fallbackLng, | ||
ns: ['wallet'], | ||
defaultNS: 'wallet', | ||
debug: process.env.NODE_ENV === 'dev', | ||
backend: { | ||
loadPath: join(__dirname, '..', 'locales', '{{lng}}', '{{ns}}.json'), | ||
addPath: join(__dirname, '..', 'locales', '{{lng}}', '{{ns}}.missing.json'), | ||
jsonIndent: 2 | ||
}, | ||
load: 'currentOnly', | ||
languages, | ||
interpolation: { escapeValue: false } | ||
}) | ||
} | ||
|
||
/** Export i18next instance. */ | ||
export default start() |