2018-06-06 11:37:13 -04:00
|
|
|
export const LOCALE_FILES = [ 'player', 'server' ]
|
|
|
|
|
2018-10-18 08:35:31 -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',
|
2019-05-13 02:54:01 -04:00
|
|
|
'ja-JP': '日本語',
|
2018-08-10 16:02:16 -04:00
|
|
|
'eu-ES': 'Euskara',
|
|
|
|
'ca-ES': 'Català',
|
|
|
|
'cs-CZ': 'Čeština',
|
2018-07-31 12:04:54 -04:00
|
|
|
'eo': 'Esperanto',
|
2019-07-25 06:06:11 -04:00
|
|
|
'el-GR': 'ελληνικά',
|
2018-07-31 12:04:54 -04:00
|
|
|
'de-DE': 'Deutsch',
|
2018-12-04 11:43:24 -05:00
|
|
|
'it-IT': 'Italiano',
|
2019-04-03 05:14:04 -04:00
|
|
|
'nl-NL': 'Nederlands',
|
2018-08-10 16:02:16 -04:00
|
|
|
'es-ES': 'Español',
|
|
|
|
'oc': 'Occitan',
|
2019-08-13 03:40:31 -04:00
|
|
|
'gd': 'Gàidhlig',
|
2018-09-25 05:53:20 -04:00
|
|
|
'zh-Hant-TW': '繁體中文(台灣)',
|
2018-08-27 05:20:06 -04:00
|
|
|
'pt-BR': 'Português (Brasil)',
|
2019-04-03 05:14:04 -04:00
|
|
|
'pt-PT': 'Português (Portugal)',
|
2018-09-25 05:53:20 -04:00
|
|
|
'sv-SE': 'svenska',
|
2018-12-04 11:43:24 -05:00
|
|
|
'pl-PL': 'Polski',
|
2019-08-22 08:45:16 -04:00
|
|
|
'fi-FI': 'suomi',
|
2018-12-04 11:43:24 -05:00
|
|
|
'ru-RU': 'русский',
|
2018-09-25 05:53:20 -04:00
|
|
|
'zh-Hans-CN': '简体中文(中国)'
|
2018-05-31 12:12:15 -04:00
|
|
|
}
|
|
|
|
|
2018-10-18 08:35:31 -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',
|
2018-08-27 05:20:06 -04:00
|
|
|
'es': 'es-ES',
|
2019-04-03 05:14:04 -04:00
|
|
|
'pt': 'pt-PT',
|
2019-08-22 08:45:16 -04:00
|
|
|
'fi': 'fi-FI',
|
2018-12-04 11:43:24 -05:00
|
|
|
'sv': 'sv-SE',
|
|
|
|
'pl': 'pl-PL',
|
2019-04-03 05:14:04 -04:00
|
|
|
'ru': 'ru-RU',
|
|
|
|
'nl': 'nl-NL',
|
2019-09-03 09:48:25 -04:00
|
|
|
'zh': 'zh-Hans-CN',
|
|
|
|
'zh-CN': 'zh-Hans-CN',
|
|
|
|
'zh-TW': 'zh-Hant-TW'
|
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-08-16 04:48:35 -04:00
|
|
|
export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
|
|
|
|
return translations && translations[str] ? translations[str] : str
|
|
|
|
}
|
|
|
|
|
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) {
|
2019-11-07 09:33:23 -05:00
|
|
|
return getCompleteLocale(locale)
|
2018-05-31 12:12:15 -04:00
|
|
|
}
|