Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lazy loading import for i18n files #2

Merged
merged 2 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions angular-lib/src/angular/modules/translate.module.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { HttpClient } from '@angular/common/http';
import { Observable, from, of } from 'rxjs';
import { catchError } from 'rxjs/operators'

export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
export class LazyTranslateLoader implements TranslateLoader {
getTranslation(lang: string): Observable<any> {
return from(import(`../../../../.ng/src/i18n/${lang}.json`)).pipe(catchError(err=>of({})));
}
}

export function getTranslateModule() {
return TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
useClass: (LazyTranslateLoader)
}
});
}
File renamed without changes.
2 changes: 1 addition & 1 deletion cli/scripts/extract-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {cwd, appBaseDir, workNg, work} = require("../lib/dirs");
syncNgDir()
.then(() => extractLabels([
`--input`, `${work}/src`,
`--output`, `${work}/src/assets/i18n/labels.json`,
`--output`, `${work}/src/i18n/labels.json`,
`--clean`,`--sort`, `--format`, `namespaced-json`
]))
.catch(error => {
Expand Down