Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TranslateService): pass 'interpolateParams' to MissingTranslationHandler in addition to 'key' #214

Closed
wants to merge 2 commits into from

Conversation

ross-nordstrom
Copy link

@ross-nordstrom ross-nordstrom commented Aug 27, 2016

This lets consumers do more with missing translations.

Notably, you could implement defaultValue behavior similar to how you would use i18next in Angular 1, which could Close #160

import {MissingTranslationHandler} from 'ng2-translate/ng2-translate';

export class CygnusMissingTranslationHandler implements MissingTranslationHandler {
   // Support defaults via: `{{ 'my.missing.key' | {defaultValue:'MyDefault'} }}`
    handle(key: string, interpolateParams?: {defaultValue?: string}) {
        const hasDefault = (interpolateParams && interpolateParams.defaultValue);
        return hasDefault ? interpolateParams.defaultValue : key;
    }
}

@ocombe I was having issues running the test suite locally, so I'm not certain if the test case I added works.
Also, an obvious extension of this PR (if you like it) would be to modify the default handle() method to behave as I've shown above so defaultValue works for everyone

…nHandler in addition to 'key'

This lets consumers do more with missing translations. Notably, this let's you implement

'defaultValue' behavior similar to how you would use i18next in Angular 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants