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) as string[]).concat(Object.keys(I18N_LOCALE_ALIAS))
80 export function getDefaultLocale () {
84 export function isDefaultLocale (locale: string) {
85 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
88 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
89 if (!translations?.[str]) return str
91 return translations[str]
94 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
95 export function is18nPath (path: string) {
96 return possiblePaths.includes(path)
99 export function is18nLocale (locale: string) {
100 return POSSIBLE_LOCALES.includes(locale)
103 export function getCompleteLocale (locale: string) {
104 if (!locale) return locale
106 const found = (I18N_LOCALE_ALIAS as any)[locale] as string
108 return found || locale
111 export function getShortLocale (locale: string) {
112 if (locale.includes('-') === false) return locale
114 return locale.split('-')[0]
117 export function buildFileLocale (locale: string) {
118 return getCompleteLocale(locale)