]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/models/i18n/i18n.ts
Merge branch 'release/v1.3.0' into develop
[github/Chocobozzz/PeerTube.git] / shared / models / i18n / i18n.ts
CommitLineData
74b7c6d4
C
1export const LOCALE_FILES = [ 'player', 'server' ]
2
c199c427 3export const I18N_LOCALES = {
8afc19a6 4 'en-US': 'English',
10e63b68 5 'fr-FR': 'Français',
e31e6015 6 'ja-JP': '日本語',
7f768064
Q
7 'eu-ES': 'Euskara',
8 'ca-ES': 'Català',
9 'cs-CZ': 'Čeština',
fb9e6cb0
C
10 'eo': 'Esperanto',
11 'de-DE': 'Deutsch',
d7aea77b 12 'it-IT': 'Italiano',
8137c8b9 13 'nl-NL': 'Nederlands',
7f768064
Q
14 'es-ES': 'Español',
15 'oc': 'Occitan',
1e45c78f 16 'zh-Hant-TW': '繁體中文(台灣)',
a9155ee6 17 'pt-BR': 'Português (Brasil)',
8137c8b9 18 'pt-PT': 'Português (Portugal)',
1e45c78f 19 'sv-SE': 'svenska',
d7aea77b
C
20 'pl-PL': 'Polski',
21 'ru-RU': 'русский',
1e45c78f 22 'zh-Hans-CN': '简体中文(中国)'
989e526a
C
23}
24
c199c427 25const I18N_LOCALE_ALIAS = {
9f164722 26 'en': 'en-US',
10e63b68
C
27 'fr': 'fr-FR',
28 'eu': 'eu-ES',
a55e5579 29 'ca': 'ca-ES',
fb9e6cb0
C
30 'cs': 'cs-CZ',
31 'de': 'de-DE',
a9155ee6 32 'es': 'es-ES',
8137c8b9 33 'pt': 'pt-PT',
d7aea77b
C
34 'sv': 'sv-SE',
35 'pl': 'pl-PL',
8137c8b9
C
36 'ru': 'ru-RU',
37 'nl': 'nl-NL',
38 'zh': 'zh-Hans-CN'
74b7c6d4
C
39}
40
41export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
42 .concat(Object.keys(I18N_LOCALE_ALIAS))
43
989e526a
C
44export function getDefaultLocale () {
45 return 'en-US'
46}
47
e945b184 48export function isDefaultLocale (locale: string) {
74b7c6d4 49 return getCompleteLocale(locale) === getCompleteLocale(getDefaultLocale())
e945b184
C
50}
51
3dfa8494
C
52export function peertubeTranslate (str: string, translations?: { [ id: string ]: string }) {
53 return translations && translations[str] ? translations[str] : str
54}
55
8afc19a6 56const possiblePaths = POSSIBLE_LOCALES.map(l => '/' + l)
989e526a
C
57export function is18nPath (path: string) {
58 return possiblePaths.indexOf(path) !== -1
59}
60
989e526a 61export function is18nLocale (locale: string) {
74b7c6d4
C
62 return POSSIBLE_LOCALES.indexOf(locale) !== -1
63}
64
65export function getCompleteLocale (locale: string) {
66 if (!locale) return locale
67
68 if (I18N_LOCALE_ALIAS[locale]) return I18N_LOCALE_ALIAS[locale]
69
70 return locale
989e526a
C
71}
72
9f164722
C
73export function getShortLocale (locale: string) {
74 if (locale.indexOf('-') === -1) return locale
75
76 return locale.split('-')[0]
77}
78
989e526a 79export function buildFileLocale (locale: string) {
74b7c6d4 80 const completeLocale = getCompleteLocale(locale)
989e526a 81
fb9e6cb0 82 return completeLocale.replace(/-/g, '_')
989e526a 83}