Skip to content

Commit df099e0

Browse files
author
Alain BOUDARD
committed
ajout de transloco i18n et flag icons
1 parent 1c713e6 commit df099e0

File tree

10 files changed

+273
-71
lines changed

10 files changed

+273
-71
lines changed
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
<todosws-navbar></todosws-navbar>
2-
<div class="container">
3-
<h1>Welcome to todosws!</h1>
4-
<div class="row">
5-
<div class="col-md-3">
6-
<todosws-counter></todosws-counter>
7-
<todosws-counter-active></todosws-counter-active>
8-
<img
9-
src="../assets/img/ngrx-data-nestjs.png"
10-
class="img-fluid"
11-
alt="NgRx Data & NestJS"
12-
/>
13-
</div>
14-
<div class="col-md-9">
15-
<p>
16-
This is an Angular app built with <a href="https://nx.dev">Nx</a>,
17-
<a href="https://docs.nestjs.com/">Nest Server</a> and
18-
<a href="https://ngrx.io/guide/data">NgRx Data</a> in monorepo.
19-
</p>
20-
<todosws-todo-list></todosws-todo-list>
2+
<ng-container *transloco="let t">
3+
<div class="container">
4+
<h1>{{ t.title }}</h1>
5+
<div class="row">
6+
<div class="col-md-3">
7+
<todosws-counter></todosws-counter>
8+
<todosws-counter-active></todosws-counter-active>
9+
<img
10+
src="../assets/img/ngrx-data-nestjs.png"
11+
class="img-fluid"
12+
alt="NgRx Data & NestJS"
13+
/>
14+
</div>
15+
<div class="col-md-9">
16+
<p [innerHTML]="t.baseline"></p>
17+
<todosws-todo-list></todosws-todo-list>
2118

22-
<div>Message: {{ hello$ | async | json }}</div>
19+
<div>Message: {{ hello$ | async | json }}</div>
20+
</div>
2321
</div>
2422
</div>
25-
</div>
23+
</ng-container>

apps/todosws/src/app/app.module.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { TodoListComponent } from './comp/todo-list/todo-list.component';
1414
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
1515
import { UtilsService } from './services/utils.service';
1616
import { CounterActiveComponent } from './comp/counter-active/counter-active.component';
17+
import { translocoLoader } from './transloco.loader';
18+
import { TranslocoModule, TRANSLOCO_CONFIG, TranslocoConfig } from '@ngneat/transloco';
1719

1820
// font awesome icons
1921
UtilsService.initFaIcons();
@@ -33,9 +35,19 @@ UtilsService.initFaIcons();
3335
StoreModule.forRoot([]),
3436
EffectsModule.forRoot([]),
3537
!environment.production ? StoreDevtoolsModule.instrument() : [],
36-
EntityDataModule.forRoot(entityConfig)
38+
EntityDataModule.forRoot(entityConfig),
39+
TranslocoModule
40+
],
41+
providers: [{
42+
provide: TRANSLOCO_CONFIG,
43+
useValue: {
44+
listenToLangChange: true,
45+
defaultLang: 'en',
46+
prodMode: environment.production
47+
} as TranslocoConfig
48+
},
49+
translocoLoader
3750
],
38-
providers: [],
3951
bootstrap: [AppComponent]
4052
})
4153
export class AppModule {}

apps/todosws/src/app/comp/navbar/navbar.component.html

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,24 @@
1010
<div class="collapse navbar-collapse" [ngClass]="{ show: navbarOpen }">
1111
<ul class="navbar-nav mr-auto">
1212
<li class="nav-item">
13-
<a class="nav-link" href="#">Item 1</a>
14-
</li>
15-
16-
<li class="nav-item">
17-
<a class="nav-link" href="#">Item 2</a>
13+
<div class="btn-group btn-group-sm" role="group">
14+
<button
15+
[disabled]="transService.getActiveLang() == 'fr'"
16+
type="button"
17+
(click)="setLang('fr')"
18+
class="btn btn-sm btn-outline-light"
19+
>
20+
<span class="flag-icon flag-icon-fr"></span>
21+
</button>
22+
<button
23+
[disabled]="transService.getActiveLang() == 'en'"
24+
type="button"
25+
(click)="setLang('en')"
26+
class="btn btn-sm btn-outline-light"
27+
>
28+
<span class="flag-icon flag-icon-gb"></span>
29+
</button>
30+
</div>
1831
</li>
1932
</ul>
2033
</div>
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { TranslocoService } from '@ngneat/transloco';
23

34
@Component({
45
selector: 'todosws-navbar',
56
templateUrl: './navbar.component.html',
67
styleUrls: ['./navbar.component.css']
78
})
89
export class NavbarComponent implements OnInit {
9-
1010
navbarOpen = false;
1111

12-
constructor() { }
13-
12+
constructor(public transService: TranslocoService) {}
13+
1414
toggleNavbar() {
1515
this.navbarOpen = !this.navbarOpen;
1616
}
1717

18-
ngOnInit() {
19-
}
18+
ngOnInit() {}
2019

20+
setLang(lang: string): void {
21+
this.transService.setActiveLang(lang);
22+
}
2123
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { HttpClient } from '@angular/common/http';
2+
import { Translation, TRANSLOCO_LOADER, TranslocoLoader } from '@ngneat/transloco';
3+
import { Injectable } from '@angular/core';
4+
5+
@Injectable({ providedIn: 'root' })
6+
export class HttpLoader implements TranslocoLoader {
7+
constructor(private http: HttpClient) {}
8+
9+
getTranslation(langPath: string) {
10+
return this.http.get<Translation>(`/assets/i18n/${langPath}.json`);
11+
}
12+
}
13+
14+
export const translocoLoader = { provide: TRANSLOCO_LOADER, useClass: HttpLoader };
15+

apps/todosws/src/assets/i18n/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"title": "Angular and Nest JS with NgRx Data",
3+
"baseline": "This is an Angular app built with <a href=\"https://nx.dev\">Nx</a>, <a href=\"https://docs.nestjs.com/\">Nest Server</a> and <a href=\"https://ngrx.io/guide/data\">NgRx Data</a> in monorepo."
4+
}

apps/todosws/src/assets/i18n/fr.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"title": "Angular et Nest JS avec NgRx Data",
3+
"baseline": "Ceci est une application Angular générée avec <a href=\"https://nx.dev\">Nx</a>, <a href=\"https://docs.nestjs.com/\">Nest Server</a> et <a href=\"https://ngrx.io/guide/data\">NgRx Data</a> dans un monorepo."
4+
}

apps/todosws/src/assets/vendor.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
@import 'variables';
22
@import '~bootstrap/scss/bootstrap';
3+
@import '~flag-icon-css/css/flag-icon.min.css';

0 commit comments

Comments
 (0)