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
20 'nl-NL': 'Nederlands',
23 'pt-BR': 'Português (Brasil)',
24 'pt-PT': 'Português (Portugal)',
28 'zh-Hans-CN': '简体中文(中国)',
29 'zh-Hant-TW': '繁體中文(台灣)'
32 const I18N_LOCALE_ALIAS = {
49 'zh-CN': 'zh-Hans-CN',
53 export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
54 .concat(Object.keys(I18N_LOCALE_ALIAS))
56 export function getDefaultLocale () {
60 export function isDefaultLocale (locale: string) {
61 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
64 export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
65 // FIXME: remove disable rule when the client is upgraded to typescript 3.7
66 // eslint-disable-next-line
67 return translations && translations[str] ? translations[str] : str
70 const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
71 export function is18nPath (path: string) {
72 return possiblePaths.indexOf(path) !== -1
75 export function is18nLocale (locale: string) {
76 return POSSIBLE_LOCALES.indexOf(locale) !== -1
79 export function getCompleteLocale (locale: string) {
80 if (!locale) return locale
82 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
87 export function getShortLocale (locale: string) {
88 if (locale.indexOf('-') === -1) return locale
90 return locale.split('-')[0]
93 export function buildFileLocale (locale: string) {
94 return getCompleteLocale(locale)