Skip to content

Commit af771a5

Browse files
author
mru
committed
(enhancement) i18n: added translation file
1 parent f043eb5 commit af771a5

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

src/client/app/i18n.providers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core';
33
export function getTranslationProviders(): Promise<Object[]> {
44

55
// Get the locale id from the global
6-
const locale: string = 'fr';
6+
const locale: string = localStorage.getItem('lang') || 'en-US';
77

88
// return no providers if fail to get translation file for locale
99
const noProviders: Object[] = [];

src/client/app/shared/navbar/navbar.component.css

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ nav a {
1515
margin-right: 20px;
1616
text-decoration: none;
1717
vertical-align: middle;
18+
cursor: pointer;
1819
}
1920

2021
nav a.router-link-active {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<nav>
2-
<a [routerLink]="['/']" [routerLinkActive]="['router-link-active']" [routerLinkActiveOptions]="{exact:true}">HOME</a>
3-
<a [routerLink]="['/about']" [routerLinkActive]="['router-link-active']" [routerLinkActiveOptions]="{exact:true}">ABOUT</a>
2+
<a [routerLink]="['/']" [routerLinkActive]="['router-link-active']" [routerLinkActiveOptions]="{exact:true}" i18n>HOME</a>
3+
<a [routerLink]="['/about']" [routerLinkActive]="['router-link-active']" [routerLinkActiveOptions]="{exact:true}" i18n>ABOUT</a>
4+
<a (click)="selectLanguage('fr')" *ngIf="lang !== 'fr'">FRANCAIS</a>
5+
<a (click)="selectLanguage('en-US')" *ngIf="lang !== 'en-US'">ENGLISH</a>
46
</nav>

src/client/app/shared/navbar/navbar.component.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component } from '@angular/core';
2+
import { Router } from '@angular/router';
23

34
/**
45
* This class represents the navigation bar component.
@@ -10,4 +11,13 @@ import { Component } from '@angular/core';
1011
styleUrls: ['navbar.component.css'],
1112
})
1213

13-
export class NavbarComponent {}
14+
export class NavbarComponent {
15+
public lang: string;
16+
public constructor(private _router: Router) {
17+
this.lang = localStorage.getItem('lang') || 'en-US';
18+
}
19+
public selectLanguage = (lang: string): void => {
20+
localStorage.setItem('lang', lang);
21+
window.location.href = '/';
22+
}
23+
}

src/client/assets/locale/messages.en.xlf

-17
This file was deleted.

src/client/assets/locale/messages.fr.xlf

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
12
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
23
<file source-language="en" datatype="plaintext" original="ng2.template">
34
<body>
5+
<trans-unit id="dcf8f15418a05a2f5b06cfe12eecbb46e94b13e1" datatype="html">
6+
<source>HOME</source>
7+
<target>ACCUEIL</target>
8+
</trans-unit>
9+
<trans-unit id="2ccc315673e88d7490220d465da566e3acff72d5" datatype="html">
10+
<source>ABOUT</source>
11+
<target>A PROPOS</target>
12+
</trans-unit>
413
<trans-unit id="c53afdd1dce2f12953e8b7098a5772a76975db03" datatype="html">
514
<source>
615
Howdy! Here&apos;s a list of awesome computer scientists. Do you know any others? Add to the list yourself.
716
</source>
8-
<target>Hello! Voici une liste d'informaticiens brilliants. Est-ce que tu en connais d'autres? Ajoute-les!</target>
17+
<target>
18+
Voici une liste d'informaticiens brilliants. Si tu en connais d'autres, ajoute-les!
19+
</target>
920
</trans-unit>
1021
<trans-unit id="f6755cff4957d5c3c89bafce5651f1b6fa2b1fd9" datatype="html">
1122
<source>Add</source>

0 commit comments

Comments
 (0)