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)',
32 'vi-VN': 'Tiếng Việt',
33 'zh-Hans-CN': '简体中文(中国)',
34 'zh-Hant-TW': '繁體中文(台灣)'
37 const I18N_LOCALE_ALIAS = {
59 'zh-CN': 'zh-Hans-CN',
60 'zh-Hans': 'zh-Hans-CN',
61 'zh-Hant': 'zh-Hant-TW',
62 'zh-TW': 'zh-Hant-TW',
66 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
67 .concat(Object.keys(I18N_LOCALE_ALIAS))
69 export function getDefaultLocale () {
73 export function isDefaultLocale (locale: string) {
74 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
77 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
78 if (!translations || !translations[str]) return str
80 return translations[str]
83 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
84 export function is18nPath (path: string) {
85 return possiblePaths.includes(path)
88 export function is18nLocale (locale: string) {
89 return POSSIBLE_LOCALES.includes(locale)
92 export function getCompleteLocale (locale: string) {
93 if (!locale) return locale
95 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
100 export function getShortLocale (locale: string) {
101 if (locale.includes('-') === false) return locale
103 return locale.split('-')[0]
106 export function buildFileLocale (locale: string) {
107 return getCompleteLocale(locale)