-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from nixgram/13-global-translate-configuration
13 global translate configuration
- Loading branch information
Showing
13 changed files
with
386 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
describe('App Component Init - Check Nixng title', () => { | ||
it('Should contain heading', () => { | ||
cy.visit('http://localhost:4200/') | ||
cy.contains("This is nixng") | ||
cy.contains("এটা হলো nixng") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
describe('App Component - Translation Check', () => { | ||
|
||
beforeEach(() => { | ||
cy.visit('http://localhost:4200/') | ||
}) | ||
|
||
it('Should contain english title', () => { | ||
cy.get('[data-cy="language"]').select('en') | ||
cy.contains("This is nixng") | ||
}) | ||
it('Should contain spanish title', () => { | ||
cy.get('[data-cy="language"]').select('es') | ||
cy.contains("Esto es nixng") | ||
}) | ||
it('Should contain Bangla title', () => { | ||
cy.get('[data-cy="language"]').select('bn') | ||
cy.contains("এটা হলো nixng") | ||
}) | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
<div class="h-screen flex justify-center items-center"> | ||
<h1 class="text-5xl font-bold"> | ||
This is | ||
<div class="absolute top-1 right-1 space-x-4"> | ||
<label for="language" class="text-white font-semibold">Translate in :</label> | ||
<select | ||
data-cy="language" | ||
name="language" | ||
id="language" | ||
class="p-2 outline-none" | ||
[(ngModel)]="selectedLanguage" | ||
(change)="onLanguageChange($event)" | ||
> | ||
<option data-cy="en" value="en">English 🇺🇸</option> | ||
<option data-cy="es" value="es">Spanish 🇪🇸</option> | ||
<option data-cy="bn" value="bn">বাংলা 🇧🇩</option> | ||
</select> | ||
</div> | ||
<div | ||
class="h-screen flex justify-center items-center bg-slate-800" | ||
*transloco="let translate" | ||
> | ||
<h1 | ||
class="text-5xl font-bold text-white shadow-md shadow-slate-900 rounded-md p-4" | ||
> | ||
{{ translate('title') }} | ||
<span | ||
class="bg-gradient-to-r text-transparent from-violet-600 to-red-600 bg-clip-text" | ||
>nixng</span | ||
> | ||
>nixng | ||
</span> | ||
🚀 | ||
</h1> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { TranslocoService } from '@ngneat/transloco'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.scss'] | ||
}) | ||
export class AppComponent implements OnInit { | ||
selectedLanguage: 'en' | 'es' | 'bn' = 'bn'; | ||
|
||
constructor(private translocoService: TranslocoService) {} | ||
|
||
ngOnInit(): void {} | ||
|
||
onLanguageChange($event: Event) { | ||
this.selectedLanguage = $event.target['value']; | ||
this.translocoService.setActiveLang($event.target['value']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { | ||
TRANSLOCO_LOADER, | ||
Translation, | ||
TranslocoLoader, | ||
TRANSLOCO_CONFIG, | ||
translocoConfig, | ||
TranslocoModule | ||
} from '@ngneat/transloco'; | ||
import { Injectable, NgModule } from '@angular/core'; | ||
import { environment } from '../environments/environment'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class TranslocoHttpLoader implements TranslocoLoader { | ||
constructor(private http: HttpClient) {} | ||
|
||
getTranslation(lang: string) { | ||
return this.http.get<Translation>(`/assets/i18n/${lang}.json`); | ||
} | ||
} | ||
|
||
@NgModule({ | ||
exports: [TranslocoModule], | ||
providers: [ | ||
{ | ||
provide: TRANSLOCO_CONFIG, | ||
useValue: translocoConfig({ | ||
availableLangs: ['en', 'es', 'bn'], | ||
defaultLang: 'bn', | ||
// Remove this option if your application doesn't support changing language in runtime. | ||
reRenderOnLangChange: true, | ||
prodMode: environment.production | ||
}) | ||
}, | ||
{ provide: TRANSLOCO_LOADER, useClass: TranslocoHttpLoader } | ||
] | ||
}) | ||
export class TranslocoRootModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"title":"এটা হলো" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"title":"This is" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"title":"Esto es" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
rootTranslationsPath: 'src/assets/i18n/', | ||
langs: ['en', 'es', 'bn'], | ||
keysManager: {} | ||
}; |