]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/models/i18n/i18n.ts
Add server localization
[github/Chocobozzz/PeerTube.git] / shared / models / i18n / i18n.ts
CommitLineData
989e526a
C
1export const I18N_LOCALES = {
2 'en-US': 'English (US)',
3 fr: 'French'
4}
5
6export function getDefaultLocale () {
7 return 'en-US'
8}
9
e945b184
C
10export function isDefaultLocale (locale: string) {
11 return locale === getDefaultLocale()
12}
13
989e526a
C
14const possiblePaths = Object.keys(I18N_LOCALES).map(l => '/' + l)
15export function is18nPath (path: string) {
16 return possiblePaths.indexOf(path) !== -1
17}
18
19const possibleLanguages = Object.keys(I18N_LOCALES)
20export function is18nLocale (locale: string) {
21 return possibleLanguages.indexOf(locale) !== -1
22}
23
24// Only use in dev mode, so relax
25// In production, the locale always match with a I18N_LANGUAGES key
26export function buildFileLocale (locale: string) {
27 if (!is18nLocale(locale)) {
28 // Some working examples for development purpose
29 if (locale.split('-')[ 0 ] === 'en') return 'en_US'
30 else if (locale === 'fr') return 'fr'
31 }
32
33 return locale.replace('-', '_')
34}