diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-31 18:12:15 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-05 08:43:01 +0200 |
commit | 989e526abf0c0dd7958deb630df009608561bb67 (patch) | |
tree | 5d948bf953a7006b1d6b8c34fb03da1df612a50f /shared/models | |
parent | 1dd59831f80ff4d49f3b60c8c3b2aabfb1512eeb (diff) | |
download | PeerTube-989e526abf0c0dd7958deb630df009608561bb67.tar.gz PeerTube-989e526abf0c0dd7958deb630df009608561bb67.tar.zst PeerTube-989e526abf0c0dd7958deb630df009608561bb67.zip |
Prepare i18n files
Diffstat (limited to 'shared/models')
-rw-r--r-- | shared/models/i18n/i18n.ts | 30 | ||||
-rw-r--r-- | shared/models/i18n/index.ts | 1 | ||||
-rw-r--r-- | shared/models/index.ts | 1 |
3 files changed, 32 insertions, 0 deletions
diff --git a/shared/models/i18n/i18n.ts b/shared/models/i18n/i18n.ts new file mode 100644 index 000000000..2d3a1d3e2 --- /dev/null +++ b/shared/models/i18n/i18n.ts | |||
@@ -0,0 +1,30 @@ | |||
1 | export const I18N_LOCALES = { | ||
2 | 'en-US': 'English (US)', | ||
3 | fr: 'French' | ||
4 | } | ||
5 | |||
6 | export function getDefaultLocale () { | ||
7 | return 'en-US' | ||
8 | } | ||
9 | |||
10 | const possiblePaths = Object.keys(I18N_LOCALES).map(l => '/' + l) | ||
11 | export function is18nPath (path: string) { | ||
12 | return possiblePaths.indexOf(path) !== -1 | ||
13 | } | ||
14 | |||
15 | const possibleLanguages = Object.keys(I18N_LOCALES) | ||
16 | export function is18nLocale (locale: string) { | ||
17 | return possibleLanguages.indexOf(locale) !== -1 | ||
18 | } | ||
19 | |||
20 | // Only use in dev mode, so relax | ||
21 | // In production, the locale always match with a I18N_LANGUAGES key | ||
22 | export function buildFileLocale (locale: string) { | ||
23 | if (!is18nLocale(locale)) { | ||
24 | // Some working examples for development purpose | ||
25 | if (locale.split('-')[ 0 ] === 'en') return 'en_US' | ||
26 | else if (locale === 'fr') return 'fr' | ||
27 | } | ||
28 | |||
29 | return locale.replace('-', '_') | ||
30 | } | ||
diff --git a/shared/models/i18n/index.ts b/shared/models/i18n/index.ts new file mode 100644 index 000000000..8f7cbe2c7 --- /dev/null +++ b/shared/models/i18n/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './i18n' | |||
diff --git a/shared/models/index.ts b/shared/models/index.ts index 95bc402d6..c8ce71f17 100644 --- a/shared/models/index.ts +++ b/shared/models/index.ts | |||
@@ -3,6 +3,7 @@ export * from './activitypub' | |||
3 | export * from './users' | 3 | export * from './users' |
4 | export * from './videos' | 4 | export * from './videos' |
5 | export * from './feeds' | 5 | export * from './feeds' |
6 | export * from './i18n' | ||
6 | export * from './server/job.model' | 7 | export * from './server/job.model' |
7 | export * from './oauth-client-local.model' | 8 | export * from './oauth-client-local.model' |
8 | export * from './result-list.model' | 9 | export * from './result-list.model' |