Skip to content

Commit 9b49003

Browse files
author
roman
committed
i18n
1 parent 03bb689 commit 9b49003

8 files changed

+59
-11
lines changed

karma.conf.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export = (config: any) => {
1111

1212
karma.set({
1313
files: [
14+
{ pattern: 'src/i18n/*.json', included: false },
1415
{ pattern: 'build/libs.js', watched: false },
1516
{ pattern: 'src/spec.module.js' },
1617
],
@@ -25,6 +26,9 @@ export = (config: any) => {
2526
});
2627

2728
config.set({
29+
proxies: {
30+
'/i18n': '/base/src/i18n',
31+
},
2832
mime: {
2933
'text/x-typescript': ['ts', 'tsx'],
3034
},

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
"@angular/platform-browser": "4.0.1",
4949
"@angular/platform-browser-dynamic": "4.0.1",
5050
"@angular/router": "4.0.1",
51+
"@ngx-translate/core": "6.0.1",
52+
"@ngx-translate/http-loader": "0.0.3",
5153
"core-js": "2.4.1",
5254
"rxjs": "5.3.0",
5355
"tslib": "1.6.0",

src/app/app.component.spec.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
import { AppComponent } from './app.component';
2-
import { TestBed } from '@angular/core/testing';
2+
import { TestBed, ComponentFixture, async } from '@angular/core/testing';
33
import { NO_ERRORS_SCHEMA } from '@angular/core';
44
import { AppModule } from './app.module';
55

66
describe('App component:', () => {
77

8-
beforeEach(() => {
8+
let component: AppComponent;
9+
let fixture: ComponentFixture<AppComponent>;
10+
11+
beforeEach(async(() => {
912
TestBed.configureTestingModule({
1013
imports: [AppModule],
1114
schemas: [NO_ERRORS_SCHEMA]
12-
});
13-
});
14-
15-
let component: AppComponent;
15+
})
16+
.compileComponents()
17+
.then(() => {
18+
fixture = TestBed.createComponent(AppComponent);
19+
component = fixture.componentInstance;
20+
});
21+
}));
1622

1723
it('smoke', () => {
18-
expect(AppComponent).toBeDefined();
24+
expect(component).toBeDefined();
1925
});
2026

21-
it('instance', () => {
22-
component = new AppComponent();
27+
it('title property', () => {
2328
expect(component.title).toBe('App');
2429
});
2530
});

src/app/app.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component } from '@angular/core';
2+
import { TranslateService } from '@ngx-translate/core';
23

34
@Component({
45
selector: 'app',
@@ -11,5 +12,11 @@ import { Component } from '@angular/core';
1112
styleUrls: ['app.component.scss'],
1213
})
1314
export class AppComponent {
15+
1416
title = 'App';
17+
18+
constructor(translate: TranslateService) {
19+
translate.setDefaultLang('en');
20+
translate.use('en');
21+
}
1522
}

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FormsModule } from '@angular/forms';
77
import { AppErrorHandler } from './app.errorhandler';
88
import { WelcomeComponent } from './welcome/welcome.component';
99
import { HomeComponent } from './home/home.component';
10+
import { TranslationModule } from './translation.module';
1011

1112
const routes: Routes = [
1213
{ path: '', component: HomeComponent },
@@ -18,7 +19,8 @@ const routes: Routes = [
1819
imports: [
1920
BrowserModule,
2021
FormsModule,
21-
RouterModule.forRoot(routes)
22+
RouterModule.forRoot(routes),
23+
TranslationModule,
2224
],
2325
declarations: [
2426
AppComponent,

src/app/translation.module.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Http, HttpModule } from '@angular/http';
2+
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
3+
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
4+
import { NgModule } from '@angular/core';
5+
import { BrowserModule } from '@angular/platform-browser';
6+
7+
// AoT requires an exported function for factories.
8+
export function createTranslateLoader(http: Http): TranslateHttpLoader {
9+
return new TranslateHttpLoader(http, 'i18n/', '.json');
10+
}
11+
12+
@NgModule({
13+
imports: [
14+
BrowserModule,
15+
HttpModule,
16+
TranslateModule.forRoot({
17+
loader: {
18+
provide: TranslateLoader,
19+
useFactory: createTranslateLoader,
20+
deps: [Http]
21+
}
22+
})
23+
]
24+
})
25+
export class TranslationModule { }

src/i18n/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"HELLO": "hello {{value}}"
3+
}

webpack.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export = (options: Options = {}) => {
105105
https: true,
106106
overlay: true,
107107
noInfo: false,
108-
contentBase: [buildPath],
108+
contentBase: [buildPath, sourcePath],
109109
port: 8087,
110110
historyApiFallback: true,
111111
hot: true,

0 commit comments

Comments
 (0)