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