diff --git a/src/services/translation-handler.ts b/src/services/translation-handler.ts index 86cf741f..316429e0 100644 --- a/src/services/translation-handler.ts +++ b/src/services/translation-handler.ts @@ -16,7 +16,7 @@ import { TRANSLATION_CONFIG, TranslationConfig } from '../models/l10n-config'; * @param lang The current language * @return The parsed value */ - public abstract parseValue(path: string, key: string, value: string | null, args: any, lang: string): string; + public abstract parseValue(path: string, key: string, value: string | null, args: any, lang: string): string | any; } @@ -24,7 +24,7 @@ import { TRANSLATION_CONFIG, TranslationConfig } from '../models/l10n-config'; constructor( @Inject(TRANSLATION_CONFIG) private configuration: TranslationConfig) { } - public parseValue(path: string, key: string, value: string | null, args: any, lang: string): string { + public parseValue(path: string, key: string, value: string | null, args: any, lang: string): string | any { if (value == null) { return this.handleMissingValue(path); } else if (args) { diff --git a/src/services/translation.service.ts b/src/services/translation.service.ts index 77bcc060..02dd15e4 100644 --- a/src/services/translation.service.ts +++ b/src/services/translation.service.ts @@ -127,7 +127,7 @@ export interface ITranslationService { }); } - private translateKey(key: string, args: any, lang: string): string | null { + private translateKey(key: string, args: any, lang: string): string | any { if (key == null || key == "") return null; // I18n plural. if (this.configuration.i18nPlural && /^\d+\b/.exec(key)) { @@ -136,21 +136,22 @@ export interface ITranslationService { return this.getValue(key, args, lang); } - private getValue(key: string, args: any, lang: string): string { + private getValue(key: string, args: any, lang: string): string | any { const path: string = key; let value: string | null = null; - if (this.translationData[lang]) { - let translation: any = this.translationData[lang]; + let translation: any = this.translationData[lang]; + + if (translation) { // Composed key. if (this.configuration.composedKeySeparator) { const sequences: string[] = key.split(this.configuration.composedKeySeparator); - do { + + key = sequences.shift()!; + while (sequences.length > 0 && translation[key]) { + translation = translation[key]; key = sequences.shift()!; - if (translation[key] && typeof translation[key] === "object") { - translation = translation[key]; - } - } while (sequences.length > 0); + } } value = translation[key] || translation[this.configuration.missingKey || ""];