]>
Commit | Line | Data |
---|---|---|
74b7c6d4 C |
1 | export const LOCALE_FILES = [ 'player', 'server' ] |
2 | ||
989e526a C |
3 | export const I18N_LOCALES = { |
4 | 'en-US': 'English (US)', | |
9c2e0dbf | 5 | 'fr-FR': 'Français (France)' |
989e526a C |
6 | } |
7 | ||
74b7c6d4 | 8 | const I18N_LOCALE_ALIAS = { |
9f164722 C |
9 | 'en': 'en-US', |
10 | 'fr': 'fr-FR' | |
74b7c6d4 C |
11 | } |
12 | ||
13 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) | |
14 | .concat(Object.keys(I18N_LOCALE_ALIAS)) | |
15 | ||
16 | const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l) | |
17 | ||
989e526a C |
18 | export function getDefaultLocale () { |
19 | return 'en-US' | |
20 | } | |
21 | ||
e945b184 | 22 | export function isDefaultLocale (locale: string) { |
74b7c6d4 | 23 | return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale()) |
e945b184 C |
24 | } |
25 | ||
989e526a C |
26 | export function is18nPath (path: string) { |
27 | return possiblePaths.indexOf(path) !== -1 | |
28 | } | |
29 | ||
989e526a | 30 | export function is18nLocale (locale: string) { |
74b7c6d4 C |
31 | return POSSIBLE_LOCALES.indexOf(locale) !== -1 |
32 | } | |
33 | ||
34 | export function getCompleteLocale (locale: string) { | |
35 | if (!locale) return locale | |
36 | ||
37 | if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale] | |
38 | ||
39 | return locale | |
989e526a C |
40 | } |
41 | ||
9f164722 C |
42 | export function getShortLocale (locale: string) { |
43 | if (locale.indexOf('-') === -1) return locale | |
44 | ||
45 | return locale.split('-')[0] | |
46 | } | |
47 | ||
989e526a | 48 | export function buildFileLocale (locale: string) { |
74b7c6d4 | 49 | const completeLocale = getCompleteLocale(locale) |
989e526a | 50 | |
74b7c6d4 | 51 | return completeLocale.replace('-', '_') |
989e526a | 52 | } |