This commit is contained in:
crusader 2018-03-08 12:04:32 +09:00
parent 48d7216e77
commit 3cb9345ca3
2 changed files with 61 additions and 48 deletions

View File

@ -0,0 +1,53 @@
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { BrowserModule, Title } from '@angular/platform-browser';
import {
L10nConfig,
L10nLoader,
LocalizationModule,
LocaleValidationModule,
StorageStrategy,
ProviderType
} from 'angular-l10n';
const l10nConfig: L10nConfig = {
locale: {
languages: [
{ code: 'en', dir: 'ltr' },
{ code: 'kr', dir: 'ltr' },
],
defaultLocale: { languageCode: 'en', countryCode: 'US' },
storage: StorageStrategy.Cookie,
cookieExpiration: 30
},
translation: {
providers: [
{ type: ProviderType.Static, prefix: './assets/translations/of-' }
],
caching: true,
composedKeySeparator: '.',
missingValue: 'No key',
i18nPlural: true
}
};
export function initL10n(l10nLoader: L10nLoader): Function {
return () => l10nLoader.load();
}
@NgModule({
imports: [
LocalizationModule.forRoot(l10nConfig),
LocaleValidationModule.forRoot()
],
providers: [
Title,
{
provide: APP_INITIALIZER,
useFactory: initL10n,
deps: [L10nLoader],
multi: true
}
],
})
export class AppL10NModule { }

View File

@ -1,12 +1,14 @@
import { NgModule, APP_INITIALIZER } from '@angular/core'; import { NgModule } from '@angular/core';
import { BrowserModule, Title } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { AppStoreModule } from './app-store.module'; import { AppStoreModule } from './app-store.module';
import { AppL10NModule } from './app-l10n.module';
import { MaterialModule } from './commons/ui/material/material.module'; import { MaterialModule } from './commons/ui/material/material.module';
import { CovalentModule } from './commons/ui/covalent/covalent.module'; import { CovalentModule } from './commons/ui/covalent/covalent.module';
@ -16,66 +18,24 @@ import { environment } from '../environments/environment';
import { RESTService } from 'packages/commons/service/rest.service'; import { RESTService } from 'packages/commons/service/rest.service';
import { RPCService } from 'packages/commons/service/rpc.service'; import { RPCService } from 'packages/commons/service/rpc.service';
import {
L10nConfig,
L10nLoader,
LocalizationModule,
LocaleValidationModule,
StorageStrategy,
ProviderType
} from 'angular-l10n';
const l10nConfig: L10nConfig = {
locale: {
languages: [
{ code: 'en', dir: 'ltr' },
{ code: 'kr', dir: 'ltr' },
],
defaultLocale: { languageCode: 'en', countryCode: 'US' },
storage: StorageStrategy.Cookie,
cookieExpiration: 30
},
translation: {
providers: [
{ type: ProviderType.Static, prefix: './assets/translations/of-' }
],
caching: true,
composedKeySeparator: '.',
missingValue: 'No key',
i18nPlural: true
}
};
export function initL10n(l10nLoader: L10nLoader): Function {
return () => l10nLoader.load();
}
@NgModule({ @NgModule({
declarations: [
AppComponent,
],
imports: [ imports: [
BrowserModule, BrowserModule,
BrowserAnimationsModule, BrowserAnimationsModule,
AppRoutingModule, AppRoutingModule,
AppStoreModule, AppStoreModule,
AppL10NModule,
MaterialModule, MaterialModule,
CovalentModule, CovalentModule,
HttpClientModule, HttpClientModule,
LocalizationModule.forRoot(l10nConfig),
LocaleValidationModule.forRoot()
], ],
providers: [ providers: [
{provide: 'REST_BASE_URL', useValue: environment.restBaseURL}, {provide: 'REST_BASE_URL', useValue: environment.restBaseURL},
{provide: 'RPC_BASE_URL', useValue: environment.rpcBaseURL}, {provide: 'RPC_BASE_URL', useValue: environment.rpcBaseURL},
RESTService, RPCService, RESTService, RPCService,
Title, ],
{ declarations: [
provide: APP_INITIALIZER, AppComponent,
useFactory: initL10n,
deps: [L10nLoader],
multi: true
}
], ],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })