diff --git a/cypress/e2e/title.cy.ts b/cypress/e2e/title.cy.ts new file mode 100644 index 0000000..791a546 --- /dev/null +++ b/cypress/e2e/title.cy.ts @@ -0,0 +1,6 @@ +describe('App Component Init - Check Nixng title', () => { + it('Should contain heading', () => { + cy.visit('http://localhost:4200/') + cy.contains("এটা হলো nixng") + }) +}) \ No newline at end of file diff --git a/cypress/e2e/translate.cy.ts b/cypress/e2e/translate.cy.ts new file mode 100644 index 0000000..cdccdea --- /dev/null +++ b/cypress/e2e/translate.cy.ts @@ -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") + }) +}) \ No newline at end of file diff --git a/src/app/transloco-root.module.ts b/src/app/transloco-root.module.ts new file mode 100644 index 0000000..b48e7a8 --- /dev/null +++ b/src/app/transloco-root.module.ts @@ -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(`/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 {} diff --git a/src/assets/i18n/bn.json b/src/assets/i18n/bn.json new file mode 100644 index 0000000..00af072 --- /dev/null +++ b/src/assets/i18n/bn.json @@ -0,0 +1,3 @@ +{ + "title":"এটা হলো" +} diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json new file mode 100644 index 0000000..9e8001a --- /dev/null +++ b/src/assets/i18n/en.json @@ -0,0 +1,3 @@ +{ + "title":"This is" +} diff --git a/src/assets/i18n/es.json b/src/assets/i18n/es.json new file mode 100644 index 0000000..e78ae4a --- /dev/null +++ b/src/assets/i18n/es.json @@ -0,0 +1,3 @@ +{ + "title":"Esto es" +} diff --git a/transloco.config.js b/transloco.config.js new file mode 100644 index 0000000..3850e06 --- /dev/null +++ b/transloco.config.js @@ -0,0 +1,5 @@ +module.exports = { + rootTranslationsPath: 'src/assets/i18n/', + langs: ['en', 'es', 'bn'], + keysManager: {} +}; \ No newline at end of file