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