2018-06-06 11:37:13 -04:00
|
|
|
export const LOCALE_FILES = [ 'player', 'server' ]
|
|
|
|
|
2018-05-31 12:12:15 -04:00
|
|
|
export const I18N_LOCALES = {
|
2018-06-28 07:59:48 -04:00
|
|
|
'en-US': 'English',
|
2018-06-28 08:56:46 -04:00
|
|
|
'fr-FR': 'Français',
|
|
|
|
'eu-ES': 'euskara',
|
2018-07-09 09:03:52 -04:00
|
|
|
'ca-ES': 'català',
|
|
|
|
'cs-CZ': 'čeština',
|
2018-07-31 12:04:54 -04:00
|
|
|
'eo': 'Esperanto',
|
|
|
|
'de-DE': 'Deutsch',
|
|
|
|
'es-ES': 'español',
|
2018-08-08 10:00:06 -04:00
|
|
|
'oc': 'occitan',
|
2018-07-31 12:04:54 -04:00
|
|
|
'zh-Hant-TW': '中文 (繁體, 台灣)'
|
2018-06-28 08:56:46 -04:00
|
|
|
// 'pl-PL': 'polski'
|
2018-05-31 12:12:15 -04:00
|
|
|
}
|
|
|
|
|
2018-06-06 11:37:13 -04:00
|
|
|
const I18N_LOCALE_ALIAS = {
|
2018-06-06 12:04:33 -04:00
|
|
|
'en': 'en-US',
|
2018-06-28 08:56:46 -04:00
|
|
|
'fr': 'fr-FR',
|
|
|
|
'eu': 'eu-ES',
|
2018-07-09 09:03:52 -04:00
|
|
|
'ca': 'ca-ES',
|
2018-07-31 12:04:54 -04:00
|
|
|
'cs': 'cs-CZ',
|
|
|
|
'de': 'de-DE',
|
|
|
|
'es': 'es-ES'
|
2018-06-28 08:56:46 -04:00
|
|
|
// 'pl': 'pl-PL'
|
2018-06-06 11:37:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
|
|
|
|
.concat(Object.keys(I18N_LOCALE_ALIAS))
|
|
|
|
|
2018-05-31 12:12:15 -04:00
|
|
|
export function getDefaultLocale () {
|
|
|
|
return 'en-US'
|
|
|
|
}
|
|
|
|
|
2018-06-06 08:23:40 -04:00
|
|
|
export function isDefaultLocale (locale: string) {
|
2018-06-06 11:37:13 -04:00
|
|
|
return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
|
2018-06-06 08:23:40 -04:00
|
|
|
}
|
|
|
|
|
2018-06-28 07:59:48 -04:00
|
|
|
const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
|
2018-05-31 12:12:15 -04:00
|
|
|
export function is18nPath (path: string) {
|
|
|
|
return possiblePaths.indexOf(path) !== -1
|
|
|
|
}
|
|
|
|
|
|
|
|
export function is18nLocale (locale: string) {
|
2018-06-06 11:37:13 -04:00
|
|
|
return POSSIBLE_LOCALES.indexOf(locale) !== -1
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCompleteLocale (locale: string) {
|
|
|
|
if (!locale) return locale
|
|
|
|
|
|
|
|
if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
|
|
|
|
|
|
|
|
return locale
|
2018-05-31 12:12:15 -04:00
|
|
|
}
|
|
|
|
|
2018-06-06 12:04:33 -04:00
|
|
|
export function getShortLocale (locale: string) {
|
|
|
|
if (locale.indexOf('-') === -1) return locale
|
|
|
|
|
|
|
|
return locale.split('-')[0]
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:12:15 -04:00
|
|
|
export function buildFileLocale (locale: string) {
|
2018-06-06 11:37:13 -04:00
|
|
|
const completeLocale = getCompleteLocale(locale)
|
2018-05-31 12:12:15 -04:00
|
|
|
|
2018-07-31 12:04:54 -04:00
|
|
|
return completeLocale.replace(/-/g, '_')
|
2018-05-31 12:12:15 -04:00
|
|
|
}
|