aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-06 17:37:13 +0200
committerChocobozzz <me@florianbigard.com>2018-06-06 17:37:13 +0200
commit74b7c6d48e9ca377fe938c8134ed74b612e62ba0 (patch)
treecb848dec054a71669fef5ea3986bdd0d2c354248 /shared
parent7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac (diff)
downloadPeerTube-74b7c6d48e9ca377fe938c8134ed74b612e62ba0.tar.gz
PeerTube-74b7c6d48e9ca377fe938c8134ed74b612e62ba0.tar.zst
PeerTube-74b7c6d48e9ca377fe938c8134ed74b612e62ba0.zip
Little i18n refractoring
Diffstat (limited to 'shared')
-rw-r--r--shared/models/i18n/i18n.ts35
1 files changed, 23 insertions, 12 deletions
diff --git a/shared/models/i18n/i18n.ts b/shared/models/i18n/i18n.ts
index 4d50bc36e..be1420150 100644
--- a/shared/models/i18n/i18n.ts
+++ b/shared/models/i18n/i18n.ts
@@ -1,34 +1,45 @@
1export const LOCALE_FILES = [ 'player', 'server' ]
2
1export const I18N_LOCALES = { 3export const I18N_LOCALES = {
2 'en-US': 'English (US)', 4 'en-US': 'English (US)',
3 fr: 'French' 5 fr: 'French'
4} 6}
5 7
8const I18N_LOCALE_ALIAS = {
9 'en': 'en-US'
10}
11
12export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
13 .concat(Object.keys(I18N_LOCALE_ALIAS))
14
15const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
16
6export function getDefaultLocale () { 17export function getDefaultLocale () {
7 return 'en-US' 18 return 'en-US'
8} 19}
9 20
10export function isDefaultLocale (locale: string) { 21export function isDefaultLocale (locale: string) {
11 return locale === getDefaultLocale() 22 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
12} 23}
13 24
14const possiblePaths = Object.keys(I18N_LOCALES).map(l => '/' + l)
15export function is18nPath (path: string) { 25export function is18nPath (path: string) {
16 return possiblePaths.indexOf(path) !== -1 26 return possiblePaths.indexOf(path) !== -1
17} 27}
18 28
19const possibleLanguages = Object.keys(I18N_LOCALES)
20export function is18nLocale (locale: string) { 29export function is18nLocale (locale: string) {
21 return possibleLanguages.indexOf(locale) !== -1 30 return POSSIBLE_LOCALES.indexOf(locale) !== -1
31}
32
33export function getCompleteLocale (locale: string) {
34 if (!locale) return locale
35
36 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
37
38 return locale
22} 39}
23 40
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) { 41export function buildFileLocale (locale: string) {
27 if (!is18nLocale(locale)) { 42 const completeLocale = getCompleteLocale(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 43
33 return locale.replace('-', '_') 44 return completeLocale.replace('-', '_')
34} 45}