Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2.0.1' of git.studer-raimann.ch:Apps/ILIAS-Pegas…
Browse files Browse the repository at this point in the history
…us into hotfix/2.0.1
  • Loading branch information
Jonathan Gerber authored and Jonathan Gerber committed Jun 5, 2018
2 parents b9fa534 + f54a219 commit 79f070c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -462,7 +463,8 @@ import {HTTP} from "@ionic-native/http";

IonicErrorHandler,
{provide: ErrorHandler, useClass: PegasusErrorHandler},
<ClassProvider>{provide: XhrFactory, useClass: PegasusXhrFactory, multi: false}
<ClassProvider>{provide: XhrFactory, useClass: PegasusXhrFactory, multi: false},
<ClassProvider>{provide: MissingTranslationHandler, useClass: PegasusMissingTranslationHandler, multi: false}
],
exports: [
TranslateModule
Expand Down
36 changes: 36 additions & 0 deletions src/services/language/translation-missing-handler.ts
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @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;
}
}

0 comments on commit 79f070c

Please sign in to comment.