Skip to content

Conversation

@rafaelss95
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Currently we can't override the getTranslateFn as it's private.

Issue Number:
Closes #489.

What is the new behavior?

This changes getTranslateFn to be protected and so we can override it in order to make it work with the cases mentioned on #489.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@rafaelss95
Copy link
Contributor Author

rafaelss95 commented Sep 7, 2021

@shaharkazaz is there any release plan that includes this version? I'm willing to start using this ❤️

Oh, I just noticed that you already released a new version some minutes ago. Thank you for that :)

@angelaki
Copy link

angelaki commented Sep 7, 2021

Woooho! Timing! ;)

@angelaki
Copy link

angelaki commented Sep 7, 2021

Love the new possibilities! ❤ Here is my use-case:

protected getTranslateFn(lang: string, read: string | undefined): (key: string | ITranslateable, params?: HashMap) => any {
  const translateFn = super.getTranslateFn(lang, read);
  return (k, b) => {
    if (typeof (k) === 'string') { return translateFn(k); }
    else { return k.displayTextTranslation ? translateFn(k.displayTextTranslation) : k.displayText; }
  }
}

Pre: {{m.displayTextTranslation?t(m.displayTextTranslation):m.displayText}}
Post: {{t(m)}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change private to protected methods in TranslocoDirectiveBase

3 participants