PeerTube/shared/models/i18n/i18n.ts

79 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-06-06 10:37:13 -05:00
export const LOCALE_FILES = [ 'player', 'server' ]
2018-10-18 07:35:31 -05:00
export const I18N_LOCALES = {
2018-06-28 06:59:48 -05:00
'en-US': 'English',
2018-06-28 07:56:46 -05:00
'fr-FR': 'Français',
'eu-ES': 'Euskara',
'ca-ES': 'Català',
'cs-CZ': 'Čeština',
'eo': 'Esperanto',
'de-DE': 'Deutsch',
2018-12-04 10:43:24 -06:00
'it-IT': 'Italiano',
'es-ES': 'Español',
'oc': 'Occitan',
2018-09-25 04:53:20 -05:00
'zh-Hant-TW': '繁體中文(台灣)',
2018-08-27 04:20:06 -05:00
'pt-BR': 'Português (Brasil)',
2018-09-25 04:53:20 -05:00
'sv-SE': 'svenska',
2018-12-04 10:43:24 -06:00
'pl-PL': 'Polski',
'ru-RU': 'русский',
2018-09-25 04:53:20 -05:00
'zh-Hans-CN': '简体中文(中国)'
2018-05-31 11:12:15 -05:00
}
2018-10-18 07:35:31 -05:00
const I18N_LOCALE_ALIAS = {
2018-06-06 11:04:33 -05:00
'en': 'en-US',
2018-06-28 07:56:46 -05:00
'fr': 'fr-FR',
'eu': 'eu-ES',
'ca': 'ca-ES',
'cs': 'cs-CZ',
'de': 'de-DE',
2018-08-27 04:20:06 -05:00
'es': 'es-ES',
'pt': 'pt-BR',
2018-12-04 10:43:24 -06:00
'sv': 'sv-SE',
'pl': 'pl-PL',
'ru': 'ru-RU'
2018-06-06 10:37:13 -05:00
}
export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
.concat(Object.keys(I18N_LOCALE_ALIAS))
2018-05-31 11:12:15 -05:00
export function getDefaultLocale () {
return 'en-US'
}
2018-06-06 07:23:40 -05:00
export function isDefaultLocale (locale: string) {
2018-06-06 10:37:13 -05:00
return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
2018-06-06 07:23:40 -05:00
}
2018-08-16 03:48:35 -05:00
export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
return translations && translations[str] ? translations[str] : str
}
2018-06-28 06:59:48 -05:00
const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
2018-05-31 11:12:15 -05:00
export function is18nPath (path: string) {
return possiblePaths.indexOf(path) !== -1
}
export function is18nLocale (locale: string) {
2018-06-06 10:37:13 -05: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 11:12:15 -05:00
}
2018-06-06 11:04:33 -05:00
export function getShortLocale (locale: string) {
if (locale.indexOf('-') === -1) return locale
return locale.split('-')[0]
}
2018-05-31 11:12:15 -05:00
export function buildFileLocale (locale: string) {
2018-06-06 10:37:13 -05:00
const completeLocale = getCompleteLocale(locale)
2018-05-31 11:12:15 -05:00
return completeLocale.replace(/-/g, '_')
2018-05-31 11:12:15 -05:00
}