Skip to content

Commit

Permalink
add ngx translate
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime GRIS committed Dec 4, 2017
1 parent f4bc5b2 commit facda37
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-electron",
"version": "2.2.0",
"version": "2.3.0",
"description": "Angular 5 with Electron (Typescript + SASS + Hot Reload)",
"homepage": "https://github.com/maximegris/angular-electron",
"author": {
Expand Down Expand Up @@ -45,6 +45,8 @@
"@angular/platform-browser": "5.0.3",
"@angular/platform-browser-dynamic": "5.0.3",
"@angular/router": "5.0.3",
"@ngx-translate/core": "9.0.1",
"@ngx-translate/http-loader": "2.0.0",
"core-js": "2.4.1",
"enhanced-resolve": "3.3.0",
"rxjs": "5.5.2",
Expand All @@ -61,8 +63,8 @@
"autoprefixer": "7.1.4",
"circular-dependency-plugin": "3.0.0",
"codelyzer": "3.2.0",
"copyfiles": "1.2.0",
"copy-webpack-plugin": "4.1.1",
"copyfiles": "1.2.0",
"cross-env": "5.0.5",
"css-loader": "0.28.7",
"cssnano": "3.10.0",
Expand All @@ -87,7 +89,8 @@
"less-loader": "4.0.5",
"minimist": "1.2.0",
"mkdirp": "0.5.1",
"npm-run-all": "^4.1.1",
"npm-run-all": "4.1.1",
"npx": "9.7.1",
"postcss-loader": "2.0.6",
"postcss-url": "7.1.2",
"protractor": "5.1.2",
Expand Down
6 changes: 5 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { Component } from '@angular/core';
import { ElectronService } from './providers/electron.service';
import { TranslateService } from '@ngx-translate/core';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(public electronService: ElectronService) {
constructor(public electronService: ElectronService,
private translate: TranslateService) {

translate.setDefaultLang('en');

if (electronService.isElectron()) {
console.log('Mode electron');
Expand Down
27 changes: 22 additions & 5 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@ import 'polyfills';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { HomeComponent } from './components/home/home.component';
import { HttpClientModule, HttpClient } from '@angular/common/http';

import { AppRoutingModule } from './app-routing.module';

// NG Translate
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';

import { ElectronService } from './providers/electron.service';

import { AppComponent } from './app.component';
import { HomeComponent } from './components/home/home.component';

// AoT requires an exported function for factories
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

@NgModule({
declarations: [
AppComponent,
Expand All @@ -21,8 +31,15 @@ import { ElectronService } from './providers/electron.service';
imports: [
BrowserModule,
FormsModule,
HttpModule,
AppRoutingModule
HttpClientModule,
AppRoutingModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (HttpLoaderFactory),
deps: [HttpClient]
}
})
],
providers: [ElectronService],
bootstrap: [AppComponent]
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="container">
<h1 class="title">
{{title}}
{{ 'PAGES.HOME.TITLE' | translate }}
</h1>
</div>
1 change: 0 additions & 1 deletion src/app/components/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
title = `App works !`;

constructor() { }

Expand Down
7 changes: 7 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"PAGES": {
"HOME": {
"TITLE": "App works !"
}
}
}

0 comments on commit facda37

Please sign in to comment.