diff options
author | Chocobozzz <me@florianbigard.com> | 2020-02-07 15:51:19 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-02-10 16:39:28 +0100 |
commit | 361dcebc75dea74947b6c3aafd9d7d720c054b01 (patch) | |
tree | 5edf2a0d871097ba7da2b974b8ccdef9c6b73261 /client/src | |
parent | f77eb73b5e02bed9e223dafc1c203ceb7c05b6e5 (diff) | |
download | PeerTube-361dcebc75dea74947b6c3aafd9d7d720c054b01.tar.gz PeerTube-361dcebc75dea74947b6c3aafd9d7d720c054b01.tar.zst PeerTube-361dcebc75dea74947b6c3aafd9d7d720c054b01.zip |
Support i18n build
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/app/app.module.ts | 13 | ||||
-rw-r--r-- | client/src/environments/environment.ts | 3 | ||||
-rw-r--r-- | client/src/main.ts | 28 |
3 files changed, 11 insertions, 33 deletions
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index 62915ec54..14fdb7588 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts | |||
@@ -4,7 +4,6 @@ import { ServerService } from '@app/core' | |||
4 | import { ResetPasswordModule } from '@app/reset-password' | 4 | import { ResetPasswordModule } from '@app/reset-password' |
5 | 5 | ||
6 | import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core' | 6 | import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core' |
7 | import { ClipboardModule } from 'ngx-clipboard' | ||
8 | import 'focus-visible' | 7 | import 'focus-visible' |
9 | 8 | ||
10 | import { AppRoutingModule } from './app-routing.module' | 9 | import { AppRoutingModule } from './app-routing.module' |
@@ -15,11 +14,10 @@ import { LoginModule } from './login' | |||
15 | import { AvatarNotificationComponent, LanguageChooserComponent, MenuComponent } from './menu' | 14 | import { AvatarNotificationComponent, LanguageChooserComponent, MenuComponent } from './menu' |
16 | import { SharedModule } from './shared' | 15 | import { SharedModule } from './shared' |
17 | import { VideosModule } from './videos' | 16 | import { VideosModule } from './videos' |
18 | import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '../../../shared/models/i18n' | ||
19 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' | ||
20 | import { SearchModule } from '@app/search' | 17 | import { SearchModule } from '@app/search' |
21 | import { WelcomeModalComponent } from '@app/modal/welcome-modal.component' | 18 | import { WelcomeModalComponent } from '@app/modal/welcome-modal.component' |
22 | import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component' | 19 | import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component' |
20 | import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '@shared/models' | ||
23 | 21 | ||
24 | export function metaFactory (serverService: ServerService): MetaLoader { | 22 | export function metaFactory (serverService: ServerService): MetaLoader { |
25 | return new MetaStaticLoader({ | 23 | return new MetaStaticLoader({ |
@@ -67,17 +65,12 @@ export function metaFactory (serverService: ServerService): MetaLoader { | |||
67 | 65 | ||
68 | AppRoutingModule // Put it after all the module because it has the 404 route | 66 | AppRoutingModule // Put it after all the module because it has the 404 route |
69 | ], | 67 | ], |
68 | |||
70 | providers: [ | 69 | providers: [ |
71 | { | 70 | { |
72 | provide: TRANSLATIONS, | 71 | provide: TRANSLATIONS, |
73 | useFactory: (locale: string) => { | 72 | useFactory: (locale: string) => { |
74 | // On dev mode, test localization | 73 | // Default locale, nothing to translate |
75 | if (isOnDevLocale()) { | ||
76 | locale = buildFileLocale(getDevLocale()) | ||
77 | return require(`raw-loader!../locale/angular.${locale}.xlf`) | ||
78 | } | ||
79 | |||
80 | // Default locale, nothing to translate | ||
81 | const completeLocale = getCompleteLocale(locale) | 74 | const completeLocale = getCompleteLocale(locale) |
82 | if (isDefaultLocale(completeLocale)) return '' | 75 | if (isDefaultLocale(completeLocale)) return '' |
83 | 76 | ||
diff --git a/client/src/environments/environment.ts b/client/src/environments/environment.ts index 1ea483554..b6bc784b5 100644 --- a/client/src/environments/environment.ts +++ b/client/src/environments/environment.ts | |||
@@ -6,8 +6,7 @@ | |||
6 | // | 6 | // |
7 | // In order to load these polyfills early enough (before app code), polyfill.ts imports this file to | 7 | // In order to load these polyfills early enough (before app code), polyfill.ts imports this file to |
8 | // to change the order in the final bundle. | 8 | // to change the order in the final bundle. |
9 | import 'core-js/es6/reflect' | 9 | import 'core-js/features/reflect' |
10 | import 'core-js/es7/reflect' | ||
11 | 10 | ||
12 | export const environment = { | 11 | export const environment = { |
13 | production: false, | 12 | production: false, |
diff --git a/client/src/main.ts b/client/src/main.ts index 2b65072ad..3fb9b346e 100644 --- a/client/src/main.ts +++ b/client/src/main.ts | |||
@@ -1,31 +1,17 @@ | |||
1 | import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core' | 1 | import { enableProdMode } from '@angular/core' |
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' | 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' |
3 | 3 | ||
4 | import { AppModule } from './app/app.module' | 4 | import { AppModule } from './app/app.module' |
5 | import { environment } from './environments/environment' | 5 | import { environment } from './environments/environment' |
6 | 6 | ||
7 | import { hmrBootstrap } from './hmr' | 7 | import { hmrBootstrap } from './hmr' |
8 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' | ||
9 | import { buildFileLocale } from '../../shared' | ||
10 | 8 | ||
11 | let providers: any[] = [] | ||
12 | if (environment.production) { | 9 | if (environment.production) { |
13 | enableProdMode() | 10 | enableProdMode() |
14 | } | 11 | } |
15 | 12 | ||
16 | // Template translation, should be in the bootstrap step | ||
17 | if (isOnDevLocale()) { | ||
18 | const locale = buildFileLocale(getDevLocale()) | ||
19 | const translations = require(`raw-loader!./locale/angular.${locale}.xlf`) | ||
20 | |||
21 | providers = [ | ||
22 | { provide: TRANSLATIONS, useValue: translations }, | ||
23 | { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' } | ||
24 | ] | ||
25 | } | ||
26 | |||
27 | const bootstrap = () => platformBrowserDynamic() | 13 | const bootstrap = () => platformBrowserDynamic() |
28 | .bootstrapModule(AppModule, { providers }) | 14 | .bootstrapModule(AppModule) |
29 | .then(bootstrapModule => { | 15 | .then(bootstrapModule => { |
30 | // TODO: Uncomment and remove unregistration when https://github.com/angular/angular/issues/21191 is fixed | 16 | // TODO: Uncomment and remove unregistration when https://github.com/angular/angular/issues/21191 is fixed |
31 | // TODO: Remove when https://github.com/angular/angular-cli/issues/8779 is fixed? | 17 | // TODO: Remove when https://github.com/angular/angular-cli/issues/8779 is fixed? |
@@ -36,11 +22,11 @@ const bootstrap = () => platformBrowserDynamic() | |||
36 | 22 | ||
37 | if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') { | 23 | if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') { |
38 | navigator.serviceWorker.getRegistrations() | 24 | navigator.serviceWorker.getRegistrations() |
39 | .then(registrations => { | 25 | .then(registrations => { |
40 | for (const registration of registrations) { | 26 | for (const registration of registrations) { |
41 | registration.unregister() | 27 | registration.unregister() |
42 | } | 28 | } |
43 | }) | 29 | }) |
44 | } | 30 | } |
45 | 31 | ||
46 | return bootstrapModule | 32 | return bootstrapModule |