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
26 'nl-NL': 'Nederlands',
29 'pt-BR': 'Português (Brasil)',
30 'pt-PT': 'Português (Portugal)',
34 'nn': 'norsk nynorsk',
35 'nb-NO': 'norsk bokmål',
37 'vi-VN': 'Tiếng Việt',
39 'zh-Hans-CN': '简体中文(中国)',
40 'zh-Hant-TW': '繁體中文(台灣)'
43 const I18N_LOCALE_ALIAS = {
67 'zh-CN': 'zh-Hans-CN',
68 'zh-Hans': 'zh-Hans-CN',
69 'zh-Hant': 'zh-Hant-TW',
70 'zh-TW': 'zh-Hant-TW',
74 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
75 .concat(Object.keys(I18N_LOCALE_ALIAS))
77 export function getDefaultLocale () {
81 export function isDefaultLocale (locale: string) {
82 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
85 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
86 if (!translations?.[str]) return str
88 return translations[str]
91 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
92 export function is18nPath (path: string) {
93 return possiblePaths.includes(path)
96 export function is18nLocale (locale: string) {
97 return POSSIBLE_LOCALES.includes(locale)
100 export function getCompleteLocale (locale: string) {
101 if (!locale) return locale
103 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
108 export function getShortLocale (locale: string) {
109 if (locale.includes('-') === false) return locale
111 return locale.split('-')[0]
114 export function buildFileLocale (locale: string) {
115 return getCompleteLocale(locale)