From 361dcebc75dea74947b6c3aafd9d7d720c054b01 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 7 Feb 2020 15:51:19 +0100 Subject: Support i18n build --- client/src/app/app.module.ts | 13 +++---------- client/src/environments/environment.ts | 3 +-- client/src/main.ts | 28 +++++++--------------------- 3 files changed, 11 insertions(+), 33 deletions(-) (limited to 'client/src') 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' import { ResetPasswordModule } from '@app/reset-password' import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core' -import { ClipboardModule } from 'ngx-clipboard' import 'focus-visible' import { AppRoutingModule } from './app-routing.module' @@ -15,11 +14,10 @@ import { LoginModule } from './login' import { AvatarNotificationComponent, LanguageChooserComponent, MenuComponent } from './menu' import { SharedModule } from './shared' import { VideosModule } from './videos' -import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '../../../shared/models/i18n' -import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' import { SearchModule } from '@app/search' import { WelcomeModalComponent } from '@app/modal/welcome-modal.component' import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component' +import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '@shared/models' export function metaFactory (serverService: ServerService): MetaLoader { return new MetaStaticLoader({ @@ -67,17 +65,12 @@ export function metaFactory (serverService: ServerService): MetaLoader { AppRoutingModule // Put it after all the module because it has the 404 route ], + providers: [ { provide: TRANSLATIONS, useFactory: (locale: string) => { - // On dev mode, test localization - if (isOnDevLocale()) { - locale = buildFileLocale(getDevLocale()) - return require(`raw-loader!../locale/angular.${locale}.xlf`) - } - - // Default locale, nothing to translate + // Default locale, nothing to translate const completeLocale = getCompleteLocale(locale) if (isDefaultLocale(completeLocale)) return '' 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 @@ // // In order to load these polyfills early enough (before app code), polyfill.ts imports this file to // to change the order in the final bundle. -import 'core-js/es6/reflect' -import 'core-js/es7/reflect' +import 'core-js/features/reflect' export const environment = { 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 @@ -import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core' +import { enableProdMode } from '@angular/core' import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' import { AppModule } from './app/app.module' import { environment } from './environments/environment' import { hmrBootstrap } from './hmr' -import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' -import { buildFileLocale } from '../../shared' -let providers: any[] = [] if (environment.production) { enableProdMode() } -// Template translation, should be in the bootstrap step -if (isOnDevLocale()) { - const locale = buildFileLocale(getDevLocale()) - const translations = require(`raw-loader!./locale/angular.${locale}.xlf`) - - providers = [ - { provide: TRANSLATIONS, useValue: translations }, - { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' } - ] -} - const bootstrap = () => platformBrowserDynamic() - .bootstrapModule(AppModule, { providers }) + .bootstrapModule(AppModule) .then(bootstrapModule => { // TODO: Uncomment and remove unregistration when https://github.com/angular/angular/issues/21191 is fixed // TODO: Remove when https://github.com/angular/angular-cli/issues/8779 is fixed? @@ -36,11 +22,11 @@ const bootstrap = () => platformBrowserDynamic() if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') { navigator.serviceWorker.getRegistrations() - .then(registrations => { - for (const registration of registrations) { - registration.unregister() - } - }) + .then(registrations => { + for (const registration of registrations) { + registration.unregister() + } + }) } return bootstrapModule -- cgit v1.2.3