Skip to content

Commit 33b6712

Browse files
committed
create translate module and add select transtlate and fix toolbar component
1 parent 39ffe26 commit 33b6712

File tree

11 files changed

+104
-14
lines changed

11 files changed

+104
-14
lines changed

src/app/app.component.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component } from '@angular/core';
22
import { MetaService } from '@ngx-meta/core';
3-
import { TranslateService } from '@ngx-translate/core';
43

54
@Component({
65
selector: 'app-root',
@@ -9,13 +8,7 @@ import { TranslateService } from '@ngx-translate/core';
98
})
109
export class AppComponent {
1110

12-
constructor(private readonly meta: MetaService,
13-
private translate: TranslateService) {
14-
this.translate.setDefaultLang('en');
11+
constructor(private readonly meta: MetaService) {
1512
this.meta.setTag('og:title', 'home ctor');
1613
}
17-
18-
changeLang(lang: string): void {
19-
this.translate.use(lang);
20-
}
2114
}
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
<ul>
2-
<li><button (click)="changeLang('en')">EN</button></li>
3-
<li><button (click)="changeLang('ru')">RU</button></li>
4-
</ul>

src/app/shared/layouts/layouts.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { RouterModule } from '@angular/router';
44

5+
import { TranslateModule } from '@shared/translate/translate.module';
6+
57
import { FooterComponent } from './footer/footer.component';
68
import { SidebarComponent } from './sidebar/sidebar.component';
79
import { ToolbarComponent } from './toolbar/toolbar.component';
@@ -11,6 +13,7 @@ import { WrapperComponent } from './wrapper/wrapper.component';
1113
imports: [
1214
CommonModule,
1315
RouterModule,
16+
TranslateModule
1417
],
1518
declarations: [
1619
FooterComponent,
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
<span>Angular RU Universal Starter</span>
1+
<span class="toolbar__logo">Angular RU Universal Starter</span>
2+
3+
<select class="toolbar__lang" (change)="changeLang($event.target.value)">
4+
<option *ngFor="let lang of languages" [value]="lang.value">
5+
{{ lang.name }}
6+
</option>
7+
</select>
8+
<a href="https://github.com/Angular-RU/angular-universal-starter"
9+
class="toolbar__github">
10+
<img alt="angular" class="docs-angular-logo"
11+
src="/assets/img/github-circle-white-transparent.svg">
12+
GitHub
13+
</a>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
import { Component } from '@angular/core';
22

3+
import { TranslateService } from '@shared/translate/translate.service';
4+
5+
const LANGUAGES: any[] = [
6+
{ value: 'ru', name: 'Русский' },
7+
{ value: 'en', name: 'English' }
8+
];
9+
310
@Component({
411
selector: 'app-toolbar',
512
templateUrl: './toolbar.component.html'
613
})
714
export class ToolbarComponent {
15+
public languages: any[] = LANGUAGES;
16+
17+
constructor(private _translateService: TranslateService) {
18+
}
19+
20+
public changeLang(lang: string): void {
21+
this._translateService.changeLang(lang);
22+
}
823
}

src/app/shared/shared.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { ModuleWithProviders, NgModule } from '@angular/core';
22

33
import { LayoutsModule } from './layouts/layouts.module';
4+
import { TranslateModule } from './translate/translate.module';
45

56
@NgModule({
67
exports: [
7-
LayoutsModule
8+
LayoutsModule,
9+
TranslateModule
810
],
911
providers: []
1012
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { NgModule } from '@angular/core';
2+
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
3+
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
4+
5+
import { TranslateService } from './translate.service';
6+
7+
@NgModule({
8+
imports: [],
9+
providers: [TranslateService]
10+
})
11+
export class TranslateModule {
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Injectable } from '@angular/core';
2+
import { TranslateService } from '@ngx-translate/core';
3+
4+
const DEFAULT_LANG: string = 'ru';
5+
6+
@Injectable()
7+
export class TranslateService {
8+
constructor(private _translateService: TranslateService) {
9+
this._translateService.setDefaultLang(DEFAULT_LANG);
10+
}
11+
12+
public changeLang(lang: string): void {
13+
this._translateService.use(lang);
14+
}
15+
}
Lines changed: 1 addition & 0 deletions
Loading

src/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<link rel="manifest" href="manifest.json">
88
<meta name="theme-color" content="#000000">
99
<base href="/">
10+
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
1011
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
1112
<meta name="viewport" content="width=device-width, initial-scale=1">
1213
<link rel="icon" type="image/x-icon" href="favicon.ico">

0 commit comments

Comments
 (0)