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
7 // Keep it alphabetically sorted
27 'nb-NO': 'norsk bokmål',
28 'nl-NL': 'Nederlands',
29 'nn': 'norsk nynorsk',
32 'pt-BR': 'Português (Brasil)',
33 'pt-PT': 'Português (Portugal)',
39 'uk-UA': 'украї́нська мо́ва',
40 'vi-VN': 'Tiếng Việt',
41 'zh-Hans-CN': '简体中文(中国)',
42 'zh-Hant-TW': '繁體中文(台灣)'
45 // Keep it alphabetically sorted
46 const I18N_LOCALE_ALIAS = {
71 'zh-CN': 'zh-Hans-CN',
72 'zh-Hans': 'zh-Hans-CN',
73 'zh-Hant': 'zh-Hant-TW',
74 'zh-TW': 'zh-Hant-TW',
78 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
79 .concat(Object.keys(I18N_LOCALE_ALIAS))
81 export function getDefaultLocale () {
85 export function isDefaultLocale (locale: string) {
86 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
89 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
90 if (!translations?.[str]) return str
92 return translations[str]
95 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
96 export function is18nPath (path: string) {
97 return possiblePaths.includes(path)
100 export function is18nLocale (locale: string) {
101 return POSSIBLE_LOCALES.includes(locale)
104 export function getCompleteLocale (locale: string) {
105 if (!locale) return locale
107 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
112 export function getShortLocale (locale: string) {
113 if (locale.includes('-') === false) return locale
115 return locale.split('-')[0]
118 export function buildFileLocale (locale: string) {
119 return getCompleteLocale(locale)