diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 09d9d311..69157072 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -15,7 +15,7 @@ import {StatusBar} from "@ionic-native/status-bar"; import {StreamingMedia} from "@ionic-native/streaming-media"; import {Toast} from "@ionic-native/toast"; import {IonicApp, IonicErrorHandler, IonicModule, ModalController, NavController, Platform} from "ionic-angular"; -import {TranslateModule, TranslateService} from "ng2-translate/ng2-translate"; +import {TranslateModule, TranslateService, MissingTranslationHandler} from "ng2-translate/ng2-translate"; import {TranslateLoader, TranslateStaticLoader} from "ng2-translate/src/translate.service"; import {OPEN_LEARNPLACE_ACTION_FACTORY, OpenLearnplaceAction, OpenLearnplaceActionFunction} from "../actions/open-learnplace-action"; import {OPEN_OBJECT_IN_ILIAS_ACTION_FACTORY, OpenObjectInILIASAction} from "../actions/open-object-in-ilias-action"; @@ -88,6 +88,7 @@ import {DiagnosticUtil} from "../services/device/hardware-features/diagnostics.u import {Hardware} from "../services/device/hardware-features/hardware-feature.service"; import {FileService} from "../services/file.service"; import {FooterToolbarService} from "../services/footer-toolbar.service"; +import {PegasusMissingTranslationHandler} from "../services/language/translation-missing-handler"; import {DEFAULT_LINK_BUILDER, DefaultLinkBuilder, DefaultLinkBuilderImpl} from "../services/link/default.builder"; import {LINK_BUILDER, LinkBuilderImpl} from "../services/link/link-builder.service"; import { @@ -462,7 +463,8 @@ import {HTTP} from "@ionic-native/http"; IonicErrorHandler, {provide: ErrorHandler, useClass: PegasusErrorHandler}, - {provide: XhrFactory, useClass: PegasusXhrFactory, multi: false} + {provide: XhrFactory, useClass: PegasusXhrFactory, multi: false}, + {provide: MissingTranslationHandler, useClass: PegasusMissingTranslationHandler, multi: false} ], exports: [ TranslateModule diff --git a/src/services/language/translation-missing-handler.ts b/src/services/language/translation-missing-handler.ts new file mode 100644 index 00000000..247bdf0f --- /dev/null +++ b/src/services/language/translation-missing-handler.ts @@ -0,0 +1,36 @@ +import {Injectable} from "@angular/core"; +import {MissingTranslationHandler, MissingTranslationHandlerParams} from "ng2-translate"; +import {Logger} from "../logging/logging.api"; +import {Logging} from "../logging/logging.service"; + +/** + * Fallback handler for translation. + * The handler will check if the missing translation is due to a unknown type which may happens with ILIAS plugins. + * If the key do not start with the "object_type" namespace the missing key is return as translation in order to + * indicate which variable is missing. + * + * It is not possible to translate a string within this handler due to the fact that the + * TranslationService is depending on the MissingTranslation handler. + * + * @author Nicolas Schaefli + * @version 1.0.0 + * @since v2.0.1 + */ +@Injectable() +export class PegasusMissingTranslationHandler extends MissingTranslationHandler { + + private static readonly OBJECT_TYPE_KEY: string = "object_type."; + private readonly log: Logger = Logging.getLogger(PegasusMissingTranslationHandler.name); + + handle(params: MissingTranslationHandlerParams): string { + + // check if we got a object_type which indicates that we got a unknown object from ILIAS most likely a plugin + if(params.key.startsWith(PegasusMissingTranslationHandler.OBJECT_TYPE_KEY) === true) { + this.log.warn(() => `No ILIAS object translation found for "${params.key}" fallback to "Object" translation.`); + return "Object"; + } + + this.log.warn(() => `Missing translation falling back to key "${params.key}"`); + return params.key; + } +}