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