ngx-translate / core

The internationalization (i18n) library for Angular
MIT License
4.5k stars 572 forks source link

MissingTranslationHandler is never called #452

Closed amirduran closed 6 years ago

amirduran commented 7 years ago

I'm submitting a ... (check one with "x")

[ x] 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
[ ] feature request

Current behavior MissingTranslationHandler is never called even though the translation doesn't exist

Expected/desired behavior MyCustomMissingTranslationHandler should be called when translation doesn't exist in translation JSON array.

Reproduction of the problem First I implemented my custom MissingTranslationHandler

import {MissingTranslationHandlerParams, MissingTranslationHandler} from "ng2-translate/src/translate.service";

export class MyCustomMissingTranslationHandler implements MissingTranslationHandler {
    handle(params: MissingTranslationHandlerParams) {
        console.log("Missing translation");
        console.log(params);
    }
}

In my main AppModule I have registered missingTranslation handler like this:

TranslateModule.forRoot({
            provide: TranslateLoader,
            useFactory: (store: Store<any>) => new StoreTranslateLoader(store),
            missingTranslationHandler: {provide: MissingTranslationHandler, useClass: MyCustomMissingTranslationHandler},
            deps: [Store]
        }),

In my template file I want to translate the string which doesn't exist:

{{"halllou yeah" | translate}}

Console logs in MyCustomMissingTranslationHandler are never printed in console.

What is the expected behavior? Console logs from my MyCustomMissingTranslationHandler should be printed in console

What is the motivation / use case for changing the behavior? We could easily extend MissingTranslationHandler to send and API request every time when we encounter untranslated word.

Please tell us about your environment:

chrillewoodz commented 6 years ago

Try with something that would actually be a valid json property, like hallo_yeah.

sangecz commented 6 years ago

@amirduran make sure that you are using missing trans. handler in right module

ocombe commented 6 years ago

Hello, I'm closing this issue because it's too old. If you have a similar problem with recent version of the library, please open a new issue.