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 'nn': 'norsk nynorsk',
32 'nb-NO': 'norsk bokmål',
34 'vi-VN': 'Tiếng Việt',
35 'zh-Hans-CN': '简体中文(中国)',
36 'zh-Hant-TW': '繁體中文(台灣)'
39 const I18N_LOCALE_ALIAS = {
62 'zh-CN': 'zh-Hans-CN',
63 'zh-Hans': 'zh-Hans-CN',
64 'zh-Hant': 'zh-Hant-TW',
65 'zh-TW': 'zh-Hant-TW',
69 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
70 .concat(Object.keys(I18N_LOCALE_ALIAS))
72 export function getDefaultLocale () {
76 export function isDefaultLocale (locale: string) {
77 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
80 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
81 if (!translations || !translations[str]) return str
83 return translations[str]
86 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
87 export function is18nPath (path: string) {
88 return possiblePaths.includes(path)
91 export function is18nLocale (locale: string) {
92 return POSSIBLE_LOCALES.includes(locale)
95 export function getCompleteLocale (locale: string) {
96 if (!locale) return locale
98 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
103 export function getShortLocale (locale: string) {
104 if (locale.includes('-') === false) return locale
106 return locale.split('-')[0]
109 export function buildFileLocale (locale: string) {
110 return getCompleteLocale(locale)