PeerTube/shared/core-utils/i18n/i18n.ts

116 lines
2.7 KiB
TypeScript
Raw Normal View History

2018-06-06 17:37:13 +02:00
export const LOCALE_FILES = [ 'player', 'server' ]
2018-10-18 14:35:31 +02:00
export const I18N_LOCALES = {
2020-02-06 16:09:03 +01:00
// Always first to avoid issues when using express acceptLanguages function when no accept language header is set
'en-US': 'English',
2020-07-02 14:08:02 +02:00
'ar': 'العربية',
'ca-ES': 'Català',
'cs-CZ': 'Čeština',
'de-DE': 'Deutsch',
2020-02-04 16:48:54 +01:00
'el-GR': 'ελληνικά',
'eo': 'Esperanto',
'es-ES': 'Español',
'eu-ES': 'Euskara',
'fi-FI': 'suomi',
'fr-FR': 'Français',
'gd': 'Gàidhlig',
2020-12-16 11:45:12 +01:00
'gl-ES': 'galego',
2022-07-11 16:25:43 +02:00
'hr': 'hrvatski',
2020-02-04 16:48:54 +01:00
'hu-HU': 'magyar',
2022-03-03 10:54:52 +01:00
'fa-IR': 'فارسی',
2018-12-04 17:43:24 +01:00
'it-IT': 'Italiano',
2020-02-04 16:48:54 +01:00
'ja-JP': '日本語',
2020-06-04 11:01:54 +02:00
'kab': 'Taqbaylit',
'nl-NL': 'Nederlands',
'oc': 'Occitan',
2020-02-04 16:48:54 +01:00
'pl-PL': 'Polski',
2018-08-27 11:20:06 +02:00
'pt-BR': 'Português (Brasil)',
'pt-PT': 'Português (Portugal)',
2018-12-04 17:43:24 +01:00
'ru-RU': 'русский',
2021-03-09 11:34:46 +01:00
'sq': 'Shqip',
'sv-SE': 'Svenska',
2021-12-13 17:06:44 +01:00
'nn': 'norsk nynorsk',
'nb-NO': 'norsk bokmål',
2020-02-04 16:48:54 +01:00
'th-TH': 'ไทย',
2020-06-04 11:01:54 +02:00
'vi-VN': 'Tiếng Việt',
2022-06-24 11:51:30 +02:00
'tok': 'Toki Pona',
2020-02-04 16:48:54 +01:00
'zh-Hans-CN': '简体中文(中国)',
'zh-Hant-TW': '繁體中文(台灣)'
2018-05-31 18:12:15 +02:00
}
2018-10-18 14:35:31 +02:00
const I18N_LOCALE_ALIAS = {
2020-07-02 14:08:02 +02:00
'ar-001': 'ar',
'ca': 'ca-ES',
'cs': 'cs-CZ',
'de': 'de-DE',
2020-04-03 14:55:16 +02:00
'el': 'el-GR',
2020-02-04 16:48:54 +01:00
'en': 'en-US',
2018-08-27 11:20:06 +02:00
'es': 'es-ES',
2020-02-04 16:48:54 +01:00
'eu': 'eu-ES',
2019-08-22 14:45:16 +02:00
'fi': 'fi-FI',
2020-12-16 11:45:12 +01:00
'gl': 'gl-ES',
2022-03-03 10:54:52 +01:00
'fa': 'fa-IR',
2020-02-04 16:48:54 +01:00
'fr': 'fr-FR',
'hu': 'hu-HU',
2020-06-04 11:01:54 +02:00
'it': 'it-IT',
'ja': 'ja-JP',
2020-02-04 16:48:54 +01:00
'nl': 'nl-NL',
2018-12-04 17:43:24 +01:00
'pl': 'pl-PL',
2020-04-03 14:55:16 +02:00
'pt': 'pt-BR',
2021-12-13 17:06:44 +01:00
'nb': 'nb-NO',
'ru': 'ru-RU',
2020-02-04 16:48:54 +01:00
'sv': 'sv-SE',
'th': 'th-TH',
2020-06-04 11:01:54 +02:00
'vi': 'vi-VN',
2019-09-03 15:48:25 +02:00
'zh-CN': 'zh-Hans-CN',
2020-06-04 11:01:54 +02:00
'zh-Hans': 'zh-Hans-CN',
2020-04-03 14:55:16 +02:00
'zh-Hant': 'zh-Hant-TW',
2020-06-04 11:01:54 +02:00
'zh-TW': 'zh-Hant-TW',
'zh': 'zh-Hans-CN'
2018-06-06 17:37:13 +02:00
}
export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
.concat(Object.keys(I18N_LOCALE_ALIAS))
2018-05-31 18:12:15 +02:00
export function getDefaultLocale () {
return 'en-US'
}
2018-06-06 14:23:40 +02:00
export function isDefaultLocale (locale: string) {
2018-06-06 17:37:13 +02:00
return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
2018-06-06 14:23:40 +02:00
}
2018-08-16 10:48:35 +02:00
export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
2022-11-15 15:00:19 +01:00
if (!translations?.[str]) return str
return translations[str]
2018-08-16 10:48:35 +02:00
}
2018-06-28 13:59:48 +02:00
const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
2018-05-31 18:12:15 +02:00
export function is18nPath (path: string) {
2020-02-28 16:03:39 +01:00
return possiblePaths.includes(path)
2018-05-31 18:12:15 +02:00
}
export function is18nLocale (locale: string) {
2020-02-28 16:03:39 +01:00
return POSSIBLE_LOCALES.includes(locale)
2018-06-06 17:37:13 +02: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 18:12:15 +02:00
}
2018-06-06 18:04:33 +02:00
export function getShortLocale (locale: string) {
2020-02-28 16:03:39 +01:00
if (locale.includes('-') === false) return locale
2018-06-06 18:04:33 +02:00
return locale.split('-')[0]
}
2018-05-31 18:12:15 +02:00
export function buildFileLocale (locale: string) {
2019-11-07 15:33:23 +01:00
return getCompleteLocale(locale)
2018-05-31 18:12:15 +02:00
}