1 export const LOCALE_FILES = [ 'player', 'server' ]
3 export const I18N_LOCALES = {
4 // Always first to avoid issues when using express acceptLanguages function when no accept language header is set
23 'nl-NL': 'Nederlands',
26 'pt-BR': 'Português (Brasil)',
27 'pt-PT': 'Português (Portugal)',
31 'vi-VN': 'Tiếng Việt',
32 'zh-Hans-CN': '简体中文(中国)',
33 'zh-Hant-TW': '繁體中文(台灣)'
36 const I18N_LOCALE_ALIAS = {
58 'zh-CN': 'zh-Hans-CN',
59 'zh-Hans': 'zh-Hans-CN',
60 'zh-Hant': 'zh-Hant-TW',
61 'zh-TW': 'zh-Hant-TW',
65 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
66 .concat(Object.keys(I18N_LOCALE_ALIAS))
68 export function getDefaultLocale () {
72 export function isDefaultLocale (locale: string) {
73 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
76 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
77 // FIXME: remove disable rule when the client is upgraded to typescript 3.7
78 // eslint-disable-next-line
79 return translations && translations[str] ? translations[str] : str
82 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
83 export function is18nPath (path: string) {
84 return possiblePaths.includes(path)
87 export function is18nLocale (locale: string) {
88 return POSSIBLE_LOCALES.includes(locale)
91 export function getCompleteLocale (locale: string) {
92 if (!locale) return locale
94 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
99 export function getShortLocale (locale: string) {
100 if (locale.includes('-') === false) return locale
102 return locale.split('-')[0]
105 export function buildFileLocale (locale: string) {
106 return getCompleteLocale(locale)