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
20 'nl-NL': 'Nederlands',
22 'pt-BR': 'Português (Brasil)',
23 'pt-PT': 'Português (Portugal)',
27 'zh-Hans-CN': '简体中文(中国)',
28 'zh-Hant-TW': '繁體中文(台灣)'
31 const I18N_LOCALE_ALIAS = {
51 'zh-Hans': 'zh-Hans-CN',
52 'zh-CN': 'zh-Hans-CN',
53 'zh-Hant': 'zh-Hant-TW',
57 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
58 .concat(Object.keys(I18N_LOCALE_ALIAS))
60 export function getDefaultLocale () {
64 export function isDefaultLocale (locale: string) {
65 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
68 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
69 // FIXME: remove disable rule when the client is upgraded to typescript 3.7
70 // eslint-disable-next-line
71 return translations && translations[str] ? translations[str] : str
74 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
75 export function is18nPath (path: string) {
76 return possiblePaths.includes(path)
79 export function is18nLocale (locale: string) {
80 return POSSIBLE_LOCALES.includes(locale)
83 export function getCompleteLocale (locale: string) {
84 if (!locale) return locale
86 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
91 export function getShortLocale (locale: string) {
92 if (locale.includes('-') === false) return locale
94 return locale.split('-')[0]
97 export function buildFileLocale (locale: string) {
98 return getCompleteLocale(locale)