Browse Source

localization service updated

pull/24731/head
erdemcaygor 8 months ago
parent
commit
cdad015f89
  1. 25
      npm/ng-packs/packages/core/src/lib/services/ui-localization.service.ts

25
npm/ng-packs/packages/core/src/lib/services/ui-localization.service.ts

@ -1,8 +1,7 @@
import { Injectable, inject } from '@angular/core'; import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { BehaviorSubject, distinctUntilChanged, switchMap, of } from 'rxjs'; import { BehaviorSubject, distinctUntilChanged, switchMap, of } from 'rxjs';
import { map, catchError, shareReplay, tap } from 'rxjs/operators'; import { catchError, shareReplay, tap } from 'rxjs/operators';
import { loadTranslations } from '@angular/localize';
import { ABP } from '../models/common'; import { ABP } from '../models/common';
import { LocalizationService } from './localization.service'; import { LocalizationService } from './localization.service';
import { SessionStateService } from './session-state.service'; import { SessionStateService } from './session-state.service';
@ -13,7 +12,7 @@ export interface LocalizationResource {
} }
/** /**
* Service for managing UI localizations via @angular/localize * Service for managing UI localizations in ABP Angular applications.
* Automatically loads localization files based on selected language * Automatically loads localization files based on selected language
* Merges with backend localizations (UI > Backend priority) * Merges with backend localizations (UI > Backend priority)
*/ */
@ -54,7 +53,7 @@ export class UILocalizationService {
return this.http.get<LocalizationResource>(url).pipe( return this.http.get<LocalizationResource>(url).pipe(
catchError(() => { catchError(() => {
// Dosya yoksa sessizce devam et (backend'den gelecek) // If file not found or error occurs, return null
return of(null); return of(null);
}), }),
tap(data => { tap(data => {
@ -66,15 +65,6 @@ export class UILocalizationService {
} }
private processLocalizationData(culture: string, data: LocalizationResource) { private processLocalizationData(culture: string, data: LocalizationResource) {
// 1. @angular/localize'a ekle
const loadTranslationsMap: Record<string, string> = {};
Object.entries(data).forEach(([resourceName, texts]) => {
Object.entries(texts).forEach(([key, value]) => {
loadTranslationsMap[`${resourceName}::${key}`] = value;
});
});
loadTranslations(loadTranslationsMap);
const abpFormat: ABP.Localization[] = [ const abpFormat: ABP.Localization[] = [
{ {
culture, culture,
@ -96,14 +86,6 @@ export class UILocalizationService {
resourceName: string, resourceName: string,
translations: Record<string, string>, translations: Record<string, string>,
): void { ): void {
// @angular/localize'a ekle
const loadTranslationsMap: Record<string, string> = {};
Object.entries(translations).forEach(([key, value]) => {
loadTranslationsMap[`${resourceName}::${key}`] = value;
});
loadTranslations(loadTranslationsMap);
// ABP LocalizationService'e ekle
const abpFormat: ABP.Localization[] = [ const abpFormat: ABP.Localization[] = [
{ {
culture, culture,
@ -117,7 +99,6 @@ export class UILocalizationService {
]; ];
this.localizationService.addLocalization(abpFormat); this.localizationService.addLocalization(abpFormat);
// Cache'e ekle
const current = this.loadedLocalizations$.value; const current = this.loadedLocalizations$.value;
if (!current[culture]) { if (!current[culture]) {
current[culture] = {}; current[culture] = {};

Loading…
Cancel
Save