Skip to content

Commit

Permalink
feat(translate): improvement for translate module
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Apr 24, 2017
1 parent 8c9e41a commit 0871eb6
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 18 deletions.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -27,7 +27,9 @@
"lint": "ng lint",
"e2e": "ng e2e --app demo",
"clean": "rimraf dist && rimraf bundle",
"i18n.extract": "ngx-translate-extract -i ./src/lib -o ./src/assets/locale/fr.json ./src/assets/locale/en.json -s -f namespaced-json -m _ -c"
"language.extract": "npm run language.extract.lib && npm run language.extract.demo",
"language.extract.lib": "ngx-translate-extract -i ./src/lib -o ./src/assets/locale/fr.json ./src/assets/locale/en.json -s -f namespaced-json -m _ -c",
"language.extract.demo": "ngx-translate-extract -i ./src/demo-app -o ./src/demo-app/assets/locale/fr.json ./src/demo-app/assets/locale/en.json -s -f namespaced-json -m _ -c"
},
"dependencies": {
"@angular/animations": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/locale/en.json
Expand Up @@ -10,4 +10,4 @@
"showLayer": "Show Layer",
"startDate": "Start Date"
}
}
}
2 changes: 1 addition & 1 deletion src/assets/locale/fr.json
Expand Up @@ -10,4 +10,4 @@
"showLayer": "Afficher la couche",
"startDate": "Date de début"
}
}
}
5 changes: 4 additions & 1 deletion src/demo-app/app/app.component.spec.ts
@@ -1,5 +1,7 @@
import { TestBed, async } from '@angular/core/testing';
import { MaterialModule } from '@angular/material';

import { IgoTestModule } from '../../test/module';
import { IgoModule, provideDefaultSearchSources } from '../../lib';

import { AppComponent } from './app.component';
Expand All @@ -9,7 +11,8 @@ describe('AppComponent', () => {
TestBed.configureTestingModule({
imports: [
MaterialModule,
IgoModule.forRoot()
IgoModule.forRoot(),
IgoTestModule
],
declarations: [
AppComponent
Expand Down
7 changes: 7 additions & 0 deletions src/demo-app/app/language.extract.ts
@@ -0,0 +1,7 @@
import { _ } from '@biesbjerg/ngx-translate-extract';

_('Tool 1');
_('tooltip1');

_('Tool 2');
_('tooltip2');
6 changes: 5 additions & 1 deletion src/demo-app/assets/locale/en.json
@@ -1,3 +1,7 @@
{
"Search for an address or a place": "Search for an address or a place"
"Search for an address or a place": "Search for an address or a place",
"Tool 1": "Tool 1",
"Tool 2": "Tool 2",
"tooltip1": "Tooltip 1",
"tooltip2": "Tooltip 2"
}
6 changes: 5 additions & 1 deletion src/demo-app/assets/locale/fr.json
@@ -1,3 +1,7 @@
{
"Search for an address or a place": "Rechercher une adresse, un lieu ou une couche"
"Search for an address or a place": "Rechercher une adresse, un lieu ou une couche",
"Tool 1": "Outil 1",
"Tool 2": "Outil 2",
"tooltip1": "Tooltip 1",
"tooltip2": "Tooltip 2"
}
3 changes: 1 addition & 2 deletions src/lib/language/shared/index.ts
@@ -1,5 +1,4 @@
export * from './language.service';
export * from './language.service.provider';
export * from './language-loader';
export * from './missing-translation.guard';

export * from './language.service.provider';
2 changes: 0 additions & 2 deletions src/lib/language/shared/language-loader.ts
Expand Up @@ -2,8 +2,6 @@ import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';

import { TranslateLoader } from '@ngx-translate/core';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/combineLatest';

declare function require(arg: string): any;

Expand Down
6 changes: 4 additions & 2 deletions src/lib/language/shared/missing-translation.guard.ts
Expand Up @@ -5,7 +5,9 @@ export class IgoMissingTranslationHandler
implements MissingTranslationHandler {

handle(params: MissingTranslationHandlerParams) {
console.log(`The Key "${params.key}" is missing in locale file.`);
// throw new Error(`The Key "${params.key}" is missing in locale file.`);
if (!params.translateService.langs.length) {
throw new Error(`LanguageService must be injected.`);
}
throw new Error(`The Key "${params.key}" is missing in locale file.`);
}
}
1 change: 1 addition & 0 deletions src/lib/module.ts
Expand Up @@ -8,6 +8,7 @@ import 'rxjs/add/operator/map';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/finally';
import 'rxjs/add/operator/combineLatest';

import 'openlayers';

Expand Down
17 changes: 11 additions & 6 deletions src/test/module.ts
@@ -1,7 +1,7 @@
import { NgModule } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { Http } from '@angular/http';

import { IgoLanguageModule } from '../lib/language';
import { IgoLanguageModule, LanguageLoader, provideLanguageService } from '../lib/language';

import 'rxjs/add/operator/debounceTime.js';
import 'rxjs/add/operator/distinctUntilChanged';
Expand All @@ -13,13 +13,18 @@ import 'rxjs/add/operator/finally';

import 'openlayers';

export function translateLoader(http: Http) {
return new LanguageLoader(http, './base/src/demo-app/assets/locale/', '.json');
}

@NgModule({
imports: [
TranslateModule.forRoot(),
IgoLanguageModule.forRoot()
],
exports: [
TranslateModule
]
providers: [
provideLanguageService({
loader: translateLoader
})
],
})
export class IgoTestModule { }

0 comments on commit 0871eb6

Please sign in to comment.