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
24 'nl-NL': 'Nederlands',
27 'pt-BR': 'Português (Brasil)',
28 'pt-PT': 'Português (Portugal)',
32 'nn': 'norsk nynorsk',
33 'nb-NO': 'norsk bokmål',
35 'vi-VN': 'Tiếng Việt',
36 'zh-Hans-CN': '简体中文(中国)',
37 'zh-Hant-TW': '繁體中文(台灣)'
40 const I18N_LOCALE_ALIAS = {
64 'zh-CN': 'zh-Hans-CN',
65 'zh-Hans': 'zh-Hans-CN',
66 'zh-Hant': 'zh-Hant-TW',
67 'zh-TW': 'zh-Hant-TW',
71 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
72 .concat(Object.keys(I18N_LOCALE_ALIAS))
74 export function getDefaultLocale () {
78 export function isDefaultLocale (locale: string) {
79 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
82 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
83 if (!translations || !translations[str]) return str
85 return translations[str]
88 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
89 export function is18nPath (path: string) {
90 return possiblePaths.includes(path)
93 export function is18nLocale (locale: string) {
94 return POSSIBLE_LOCALES.includes(locale)
97 export function getCompleteLocale (locale: string) {
98 if (!locale) return locale
100 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
105 export function getShortLocale (locale: string) {
106 if (locale.includes('-') === false) return locale
108 return locale.split('-')[0]
111 export function buildFileLocale (locale: string) {
112 return getCompleteLocale(locale)