Skip to content

Commit

Permalink
Language translation issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratikshakhandagale committed Jul 10, 2024
1 parent d3a442a commit 6235d50
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { StorageService } from 'src/app/services';
import { LanguageService } from './language.service';

@Component({
selector: 'app-langauge-select',
Expand All @@ -14,6 +15,7 @@ export class LangaugeSelectComponent implements OnInit {
constructor(private translateService: TranslateService,
private navParams: NavParams,
private modalCtrl: ModalController,
private languageService: LanguageService,
private storage: StorageService) { }

async ngOnInit() {
Expand All @@ -34,6 +36,7 @@ export class LangaugeSelectComponent implements OnInit {
this.translateService.use(val);
// }
this.selectedLanguage = val;
this.languageService.setLanguage(val)
this.dismissModal();
}

Expand Down
15 changes: 15 additions & 0 deletions src/app/components/langauge-select/language.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class LanguageService {
private languageSubject = new BehaviorSubject<string>(localStorage.getItem('DJPData.lang') || 'en');
currentLanguage$ = this.languageSubject.asObservable();

setLanguage(language: string) {
localStorage.setItem('DJPData.lang', language);
this.languageSubject.next(language);
}
}
12 changes: 9 additions & 3 deletions src/app/tabs/tabs.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@

<ion-tab-button tab="story" href="">
<ion-icon aria-hidden="true" src="assets/icon/book.svg"></ion-icon>
<ion-label>{{ configVariables?.kathaSakhiBotName }}</ion-label>
<ion-label *ngIf="isTitleChanged">{{ configVariables?.[language]?.kathaSakhiBotName }}</ion-label>
<ion-label *ngIf="!isTitleChanged">{{'Katha Sakhi' | translate }}</ion-label>

</ion-tab-button>

<ion-tab-button tab="parent-sakhi" href="">
<ion-icon aria-hidden="true" src="assets/icon/parents.svg"></ion-icon>
<ion-label>{{ configVariables?.parentTaraBotName }}</ion-label>
<ion-label *ngIf="isTitleChanged">{{ configVariables?.[language]?.parentTaraBotName }}</ion-label>
<ion-label *ngIf="!isTitleChanged">{{'Parent Tara' | translate }}</ion-label>

</ion-tab-button>

<ion-tab-button tab="teacher-sakhi" href="">
<ion-icon aria-hidden="true" src="assets/icon/teacher.svg"></ion-icon>
<ion-label>{{ configVariables?.teacherTaraBotName }}</ion-label>
<ion-label *ngIf="isTitleChanged">{{ configVariables?.[language]?.teacherTaraBotName }}</ion-label>
<ion-label *ngIf="!isTitleChanged">{{'Teacher Tara' | translate }}</ion-label>

</ion-tab-button>

<ion-tab-button tab="my-pitara" href="/tabs/my-pitara">
Expand Down
31 changes: 29 additions & 2 deletions src/app/tabs/tabs.page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewChild } from '@angular/core';
import { Component, ViewChild, OnInit } from '@angular/core';
import { IonTabs, ModalController, Platform } from '@ionic/angular';
import { OnTabViewWillEnter } from './on-tabs-view-will-enter';
import { Router } from '@angular/router';
Expand All @@ -7,21 +7,29 @@ import { TelemetryGeneratorService } from '../services/telemetry/telemetry.gener
import { AppExitComponent } from '../components/app-exit/app-exit.component';
import { App } from '@capacitor/app';
import { ConfigVariables } from "../config";
import { LanguageService } from '../components/langauge-select/language.service';
import { StorageService } from 'src/app/services';

@Component({
selector: 'app-tabs',
templateUrl: 'tabs.page.html',
styleUrls: ['tabs.page.scss']
})
export class TabsPage implements OnTabViewWillEnter{
export class TabsPage implements OnTabViewWillEnter, OnInit{
subscription: any;
optModalOpen = false;
configVariables: any;
languageSubscription: any;
isTitleChanged : boolean = false;
language: string = '';

@ViewChild('tabRef', { static: false }) tabRef!: IonTabs;
constructor(private platform: Platform,
private router: Router,
private tabService: TabsService,
private telemetry: TelemetryGeneratorService,
private languageService: LanguageService,
private storage : StorageService,
private modalCtrl: ModalController) {
ConfigVariables.then(config => {
console.log('Configuration:', config);
Expand All @@ -36,6 +44,25 @@ export class TabsPage implements OnTabViewWillEnter{
this.tabService.show();
}

async ngOnInit() {
this.language = await this.storage.getData('lang') || 'en';
this.isTitleChanged = this.configVariables.titleCode.includes(this.language);
console.log(`Loading data for language: ${this.language}`);

this.languageSubscription = this.languageService.currentLanguage$.subscribe(
(language) => {
this.loadTabData(language);
}
);
}

loadTabData(language: string) {
this.language = language;
this.isTitleChanged = this.configVariables.titleCode.includes(language);
console.log(`Loading data for language: ${language}`);
// Example data loading logic:
}

// Prevent back naviagtion
ionViewDidEnter() {
this.tabService.show()
Expand Down
8 changes: 5 additions & 3 deletions src/assets/appConfig/garhwal-school.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@
"default": true
}
],
"kathaSakhiBotName": "Story GEMS",
"parentTaraBotName": "Parent GEMS",
"teacherTaraBotName": "Teacher GEMS",
"en": {
"kathaSakhiBotName": "Story GEMS",
"parentTaraBotName": "Parent GEMS",
"teacherTaraBotName": "Teacher GEMS"
},
"footerText": "Developed with ❤️ by Tekdi Technologies ",
"headerColor": "brown",
"headerFontSize": "16",
Expand Down
9 changes: 6 additions & 3 deletions src/assets/appConfig/hummingbird-school.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@
"default": true
}
],
"kathaSakhiBotName": "Story Baideo",
"parentTaraBotName": "Parent Bondhu",
"teacherTaraBotName": "Teacher Bondhu",
"en": {
"kathaSakhiBotName": "Story Baideo",
"parentTaraBotName": "Parent Bondhu",
"teacherTaraBotName": "Teacher Bondhu"
},

"footerText": "Developed with ❤️ by Tekdi Technologies ",
"headerColor": "brown",
"headerFontSize": "16",
Expand Down
94 changes: 51 additions & 43 deletions src/assets/appConfig/localhost.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,48 @@
"key": "agegroup",
"value": "3-6"
},
"headerFilters": [{
"defaultFilter": {
"id": "All",
"label": "All",
"query": "",
"filters": "All"
},
"additionalFilters": [
{
"id": "Stories",
"label": "Stories",
"query": "Stories",
"filters": "Stories"
},
{
"id": "Activities",
"label": "Activities",
"query": "Activities",
"filters": "Activities"
},
{
"id": "Songs",
"label": "Songs",
"query": "Songs",
"filters": "Songs"
},
{
"id": "Audio Books",
"label": "Audio Books",
"query": "Audio Books",
"filters": "Audio Books"
"headerFilters": [
{
"defaultFilter": {
"id": "All",
"label": "All",
"query": "",
"filters": "All"
},
{
"id": "Handbooks",
"label": "Handbooks",
"query": "Handbooks",
"filters": "Handbooks"
}
]
}],
"additionalFilters": [
{
"id": "Stories",
"label": "Stories",
"query": "Stories",
"filters": "Stories"
},
{
"id": "Activities",
"label": "Activities",
"query": "Activities",
"filters": "Activities"
},
{
"id": "Songs",
"label": "Songs",
"query": "Songs",
"filters": "Songs"
},
{
"id": "Audio Books",
"label": "Audio Books",
"query": "Audio Books",
"filters": "Audio Books"
},
{
"id": "Handbooks",
"label": "Handbooks",
"query": "Handbooks",
"filters": "Handbooks"
}
]
}
],
"languages": [
{
"id": "en",
Expand All @@ -59,12 +61,18 @@
"default": true
}
],
"kathaSakhiBotName": "Story GEMS",
"parentTaraBotName": "Parent GEMS",
"teacherTaraBotName": "Teacher GEMS",

"titleCode": [
"en"
],
"en": {
"kathaSakhiBotName": "Story GEMS",
"parentTaraBotName": "Parent GEMS",
"teacherTaraBotName": "Teacher GEMS"
},
"footerText": "Developed with ❤️ by Tekdi Technologies ",
"headerColor": "brown",
"headerFontSize": "16",
"footerColor": "brown",
"footerFontSize": "16"
}
}

0 comments on commit 6235d50

Please sign in to comment.