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
22 'nl-NL': 'Nederlands',
25 'pt-BR': 'Português (Brasil)',
26 'pt-PT': 'Português (Portugal)',
30 'vi-VN': 'Tiếng Việt',
31 'zh-Hans-CN': '简体中文(中国)',
32 'zh-Hant-TW': '繁體中文(台灣)'
35 const I18N_LOCALE_ALIAS = {
56 'zh-CN': 'zh-Hans-CN',
57 'zh-Hans': 'zh-Hans-CN',
58 'zh-Hant': 'zh-Hant-TW',
59 'zh-TW': 'zh-Hant-TW',
63 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
64 .concat(Object.keys(I18N_LOCALE_ALIAS))
66 export function getDefaultLocale () {
70 export function isDefaultLocale (locale: string) {
71 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
74 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
75 // FIXME: remove disable rule when the client is upgraded to typescript 3.7
76 // eslint-disable-next-line
77 return translations && translations[str] ? translations[str] : str
80 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
81 export function is18nPath (path: string) {
82 return possiblePaths.includes(path)
85 export function is18nLocale (locale: string) {
86 return POSSIBLE_LOCALES.includes(locale)
89 export function getCompleteLocale (locale: string) {
90 if (!locale) return locale
92 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
97 export function getShortLocale (locale: string) {
98 if (locale.includes('-') === false) return locale
100 return locale.split('-')[0]
103 export function buildFileLocale (locale: string) {
104 return getCompleteLocale(locale)