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',
23 'pt-BR': 'Português (Brasil)',
24 'pt-PT': 'Português (Portugal)',
28 'zh-Hans-CN': '简体中文(中国)',
29 'zh-Hant-TW': '繁體中文(台灣)'
32 const I18N_LOCALE_ALIAS = {
52 'zh-Hans': 'zh-Hans-CN',
53 'zh-CN': 'zh-Hans-CN',
54 'zh-Hant': 'zh-Hant-TW',
58 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
59 .concat(Object.keys(I18N_LOCALE_ALIAS))
61 export function getDefaultLocale () {
65 export function isDefaultLocale (locale: string) {
66 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
69 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
70 // FIXME: remove disable rule when the client is upgraded to typescript 3.7
71 // eslint-disable-next-line
72 return translations && translations[str] ? translations[str] : str
75 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
76 export function is18nPath (path: string) {
77 return possiblePaths.includes(path)
80 export function is18nLocale (locale: string) {
81 return POSSIBLE_LOCALES.includes(locale)
84 export function getCompleteLocale (locale: string) {
85 if (!locale) return locale
87 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
92 export function getShortLocale (locale: string) {
93 if (locale.includes('-') === false) return locale
95 return locale.split('-')[0]
98 export function buildFileLocale (locale: string) {
99 return getCompleteLocale(locale)