Browse Source

localization service updated

pull/24731/head
erdemcaygor 1 week ago
parent
commit
f585f7dc60
  1. 3
      npm/ng-packs/packages/core/src/lib/services/localization.service.ts
  2. 24
      npm/ng-packs/packages/core/src/lib/services/ui-localization.service.ts

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

@ -92,7 +92,8 @@ export class LocalizationService {
const resourceName = entry[0];
const remoteTexts = entry[1];
let resource = local?.get(resourceName) || {};
resource = { ...resource, ...remoteTexts };
// UI > Backend priority: UI localization'lar backend'i override eder
resource = { ...remoteTexts, ...resource };
local?.set(resourceName, resource);
});

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

@ -24,23 +24,17 @@ export class UILocalizationService {
private sessionState = inject(SessionStateService);
private options = inject(CORE_OPTIONS);
// Yüklenen localization'lar (culture -> resourceName -> texts)
private loadedLocalizations$ = new BehaviorSubject<Record<string, LocalizationResource>>({});
// Current language
private currentLanguage$ = this.sessionState.getLanguage$();
constructor() {
const uiLocalization = this.options.uiLocalization;
if (uiLocalization?.enabled) {
// Dil değiştiğinde otomatik yükle
this.subscribeToLanguageChanges();
}
}
/**
* Dil değişikliğini dinle ve localization dosyasını yükle
*/
private subscribeToLanguageChanges() {
this.currentLanguage$
.pipe(
@ -51,11 +45,6 @@ export class UILocalizationService {
.subscribe();
}
/**
* Seçilen dil için localization dosyasını yükle
* Format: /assets/localization/{culture}.json
* JSON format: { "ResourceName": { "Key": "Value" } }
*/
private loadLocalizationFile(culture: string) {
const config = this.options.uiLocalization;
if (!config?.enabled) return of(null);
@ -76,11 +65,6 @@ export class UILocalizationService {
);
}
/**
* Localization verisini işle:
* 1. @angular/localize'a ekle (loadTranslations)
* 2. ABP LocalizationService'e ekle (addLocalization)
*/
private processLocalizationData(culture: string, data: LocalizationResource) {
// 1. @angular/localize'a ekle
const loadTranslationsMap: Record<string, string> = {};
@ -91,7 +75,6 @@ export class UILocalizationService {
});
loadTranslations(loadTranslationsMap);
// 2. ABP LocalizationService'e ekle
const abpFormat: ABP.Localization[] = [
{
culture,
@ -103,15 +86,11 @@ export class UILocalizationService {
];
this.localizationService.addLocalization(abpFormat);
// 3. Cache'e ekle
const current = this.loadedLocalizations$.value;
current[culture] = data;
this.loadedLocalizations$.next(current);
}
/**
* Manuel olarak localization ekle (runtime'da)
*/
addAngularLocalizeLocalization(
culture: string,
resourceName: string,
@ -153,9 +132,6 @@ export class UILocalizationService {
this.loadedLocalizations$.next(current);
}
/**
* Yüklenen localization'ları al
*/
getLoadedLocalizations(culture?: string): LocalizationResource {
const lang = culture || this.sessionState.getLanguage();
return this.loadedLocalizations$.value[lang] || {};

Loading…
Cancel
Save