PeerTube/shared/models/i18n/i18n.ts

100 lines
2.4 KiB
TypeScript
Raw Normal View History

2018-06-06 10:37:13 -05:00
export const LOCALE_FILES = [ 'player', 'server' ]
2018-10-18 07:35:31 -05:00
export const I18N_LOCALES = {
2020-02-06 09:09:03 -06:00
// Always first to avoid issues when using express acceptLanguages function when no accept language header is set
'en-US': 'English',
'ca-ES': 'Català',
'cs-CZ': 'Čeština',
'de-DE': 'Deutsch',
2020-02-04 09:48:54 -06:00
'el-GR': 'ελληνικά',
'eo': 'Esperanto',
'es-ES': 'Español',
'eu-ES': 'Euskara',
'fi-FI': 'suomi',
'fr-FR': 'Français',
'gd': 'Gàidhlig',
'hu-HU': 'magyar',
2018-12-04 10:43:24 -06:00
'it-IT': 'Italiano',
2020-02-04 09:48:54 -06:00
'ja-JP': '日本語',
'nl-NL': 'Nederlands',
2020-02-04 09:48:54 -06:00
'pl-PL': 'Polski',
2018-08-27 04:20:06 -05:00
'pt-BR': 'Português (Brasil)',
'pt-PT': 'Português (Portugal)',
2018-12-04 10:43:24 -06:00
'ru-RU': 'русский',
2020-02-04 09:48:54 -06:00
'sv-SE': 'svenska',
'th-TH': 'ไทย',
'zh-Hans-CN': '简体中文(中国)',
'zh-Hant-TW': '繁體中文(台灣)'
2018-05-31 11:12:15 -05:00
}
2018-10-18 07:35:31 -05:00
const I18N_LOCALE_ALIAS = {
'ca': 'ca-ES',
'cs': 'cs-CZ',
'de': 'de-DE',
2020-04-03 07:55:16 -05:00
'el': 'el-GR',
2020-02-04 09:48:54 -06:00
'en': 'en-US',
2018-08-27 04:20:06 -05:00
'es': 'es-ES',
2020-02-04 09:48:54 -06:00
'eu': 'eu-ES',
2019-08-22 07:45:16 -05:00
'fi': 'fi-FI',
2020-02-04 09:48:54 -06:00
'fr': 'fr-FR',
2020-04-03 07:55:16 -05:00
'ja': 'ja-JP',
'it': 'it-IT',
2020-02-04 09:48:54 -06:00
'hu': 'hu-HU',
'nl': 'nl-NL',
2018-12-04 10:43:24 -06:00
'pl': 'pl-PL',
2020-04-03 07:55:16 -05:00
'pt': 'pt-BR',
'ru': 'ru-RU',
2020-02-04 09:48:54 -06:00
'sv': 'sv-SE',
'th': 'th-TH',
2019-09-03 08:48:25 -05:00
'zh': 'zh-Hans-CN',
2020-04-03 07:55:16 -05:00
'zh-Hans': 'zh-Hans-CN',
2019-09-03 08:48:25 -05:00
'zh-CN': 'zh-Hans-CN',
2020-04-03 07:55:16 -05:00
'zh-Hant': 'zh-Hant-TW',
2019-09-03 08:48:25 -05:00
'zh-TW': 'zh-Hant-TW'
2018-06-06 10:37:13 -05:00
}
export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
.concat(Object.keys(I18N_LOCALE_ALIAS))
2018-05-31 11:12:15 -05:00
export function getDefaultLocale () {
return 'en-US'
}
2018-06-06 07:23:40 -05:00
export function isDefaultLocale (locale: string) {
2018-06-06 10:37:13 -05:00
return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
2018-06-06 07:23:40 -05:00
}
2018-08-16 03:48:35 -05:00
export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
2020-01-31 09:56:52 -06:00
// FIXME: remove disable rule when the client is upgraded to typescript 3.7
// eslint-disable-next-line
2018-08-16 03:48:35 -05:00
return translations && translations[str] ? translations[str] : str
}
2018-06-28 06:59:48 -05:00
const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
2018-05-31 11:12:15 -05:00
export function is18nPath (path: string) {
2020-02-28 09:03:39 -06:00
return possiblePaths.includes(path)
2018-05-31 11:12:15 -05:00
}
export function is18nLocale (locale: string) {
2020-02-28 09:03:39 -06:00
return POSSIBLE_LOCALES.includes(locale)
2018-06-06 10:37:13 -05:00
}
export function getCompleteLocale (locale: string) {
if (!locale) return locale
if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
return locale
2018-05-31 11:12:15 -05:00
}
2018-06-06 11:04:33 -05:00
export function getShortLocale (locale: string) {
2020-02-28 09:03:39 -06:00
if (locale.includes('-') === false) return locale
2018-06-06 11:04:33 -05:00
return locale.split('-')[0]
}
2018-05-31 11:12:15 -05:00
export function buildFileLocale (locale: string) {
2019-11-07 08:33:23 -06:00
return getCompleteLocale(locale)
2018-05-31 11:12:15 -05:00
}