Skip to content

Commit

Permalink
tested with cypress #13
Browse files Browse the repository at this point in the history
  • Loading branch information
sefatanam committed Nov 10, 2022
1 parent c90dce8 commit b9b13f3
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cypress/e2e/title.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('App Component Init - Check Nixng title', () => {
it('Should contain heading', () => {
cy.visit('http://localhost:4200/')
cy.contains("এটা হলো nixng")
})
})
19 changes: 19 additions & 0 deletions cypress/e2e/translate.cy.ts
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")
})
})
38 changes: 38 additions & 0 deletions src/app/transloco-root.module.ts
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 {}
3 changes: 3 additions & 0 deletions src/assets/i18n/bn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"title":"এটা হলো"
}
3 changes: 3 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"title":"This is"
}
3 changes: 3 additions & 0 deletions src/assets/i18n/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"title":"Esto es"
}
5 changes: 5 additions & 0 deletions transloco.config.js
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: {}
};

0 comments on commit b9b13f3

Please sign in to comment.