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

i18n.t and t not working the same? #332

Closed
abjorck opened this issue Oct 30, 2017 · 4 comments
Closed

i18n.t and t not working the same? #332

abjorck opened this issue Oct 30, 2017 · 4 comments

Comments

@abjorck
Copy link

abjorck commented Oct 30, 2017

I was expecting them to, but maybe that is wrong of me.

Anyway, the issue I have is that when using sprintf.overloadTranslationOptionHandler (from https://github.com/i18next/i18next-sprintf-postProcessor), the t() does not work as expected.
(I'm using the translate() HOC)

It seems to be that t() uses getFixedT and somewhere in there the arguments are mangled, while i18n.t() works as expected.
I also found this issue which may be related, i18next/i18next#565

So maybe the question is, can I get t() to act the same as i18n.t()?

TLDR;
(with key schedule.week being something like "Week %d")
{ i18n.t("schedule.week", moment().week() ) } works
{ t("schedule.week", moment().week() ) } does not "resolve"

also, for added info, the long form works:
{ t('schedule.week', { postProcess: 'sprintf', sprintf: [moment(startDate).week()] }) }
but that doesnt look very nice.

@jamuhl
Copy link
Member

jamuhl commented Oct 30, 2017

yes you found the right location for the problem - using getFixedT which takes a somehow naiv approach only supporting the defaultValue handler.

https://github.com/i18next/i18next/blob/master/src/i18next.js#L231

if we replace that with the same functionality used in translator:

https://github.com/i18next/i18next/blob/master/src/Translator.js#L45

that should work for every handler...if you like you could provide a PR or i will look into this asap.

@jamuhl
Copy link
Member

jamuhl commented Oct 31, 2017

should work in [email protected]

@abjorck
Copy link
Author

abjorck commented Oct 31, 2017

It does, nice! Thanks for the quick work

@abjorck abjorck closed this as completed Oct 31, 2017
@jamuhl
Copy link
Member

jamuhl commented Oct 31, 2017

awesome...thanks for confirmation.

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

No branches or pull requests

2 participants