You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[x] feature request
Current behavior
If I implement the MissingTranslationHandler like this:
Such a thing, in turn, would potentially trigger an infinite loop if the 'MISSING' key is missing, too. This should be taken into account somehow.
What is the motivation / use case for changing the behavior?
Suppose you need to convert API error codes into localized messages. APIs change frequently, and if you haven't yet covered a specific error code, then you need to output something generic along the lines of "An error occurred, code: {{code}}". That is the case this feature request would cover.
Please tell us about your environment:
ng2-translate version: 2.4.3
Angular version: 2.0.0-rc.6
Browser: all
Language: TypeScript 1.8.10
The text was updated successfully, but these errors were encountered:
import{Injectable,Injector}from'@angular/core';import{MissingTranslationHandler,TranslateService}from'ng2-translate';
@Injectable()exportclassCustomMissingTranslationHandlerextendsMissingTranslationHandler{privatemissingKey: string;privatetranslation: TranslateService;constructor(privateinjector: Injector){super();}publichandle(key: string){if(this.translation==null){this.translation=this.injector.get(TranslateService);}if(this.missingKey!=null){// already handling the missing translation, and the '__TRANSLATION_MISSING' part is missing, too.// Return the key itselfletpreviouslyMissingKey=this.missingKey;this.missingKey=null;returnpreviouslyMissingKey;}this.missingKey=key;// do your thing using this.translation:letresult=this.translation.instant('__TRANSLATION_MISSING',{ key });this.missingKey=null;returnresult;}}
I'm submitting a ... (check one with "x")
Current behavior
If I implement the
MissingTranslationHandler
like this:then this results in a cyclic dependency:
TranslateService
depends onMissingTranslationHandler
, which in turn depends onTranslateService
.Expected/desired behavior
The desired behavior would be if the
handle
method provided an instance ofTranslateService
, e.g.or, given the #214 proposal, something like
Such a thing, in turn, would potentially trigger an infinite loop if the 'MISSING' key is missing, too. This should be taken into account somehow.
What is the motivation / use case for changing the behavior?
Suppose you need to convert API error codes into localized messages. APIs change frequently, and if you haven't yet covered a specific error code, then you need to output something generic along the lines of "An error occurred, code: {{code}}". That is the case this feature request would cover.
Please tell us about your environment:
The text was updated successfully, but these errors were encountered: