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

using postProcess: 'interval' in i18next.init fails #223

Open
obermillerk opened this issue Jul 23, 2021 · 3 comments
Open

using postProcess: 'interval' in i18next.init fails #223

obermillerk opened this issue Jul 23, 2021 · 3 comments

Comments

@obermillerk
Copy link

🐛 Bug Report

I didn't want to have to specify {postProcess: 'interval'} every time I wanted to use the interval post-processing, so I passed it to the i18next.init options instead and this caused translations without any options to fail at this line:

const index = newOptions.postProcess.indexOf('interval'); // <-- Not supported in <IE9

To Reproduce

i18next.init({
  postProcess: 'interval',
  ...
})
// ...
i18next.t("some-key") // Fails because it has no postProcess option

Expected behavior

The examples show postProcess: 'interval' being passed to every translation that wants to use it, so it seems to be intended behavior that this would fail, but it really shouldn't. Having to pass that option for every interval is annoying and makes the code more complicated. It already has the _interval suffix in the key, so why do we need this option? Else, why bother with the suffix? Seems like if the key has the _interval suffix it should just post process with this plugin, or this plugin should try to post process everything and check if the entry has interval post processing and handle it if so.

Just something so postProcess: 'interval' doesn't have to be passed every time, or allow postProcess: 'interval' to be specified in i18next.init and not fail on keys without options or _interval suffixes.

i18next.init({
  postProcess: 'interval',
  // ...
})
// ...
i18next.t("some-key") // Works!
// ...
i18next.t("other-key_interval", {count: 3}) // Works and handles intervals!

Your Environment

Don't think it really matters, seems like it's just a flaw in the coding but...

  • runtime version: electron 13, node 14
  • i18next version: 20.3.4
  • os: Windows
@jamuhl
Copy link
Member

jamuhl commented Jul 23, 2021

How often you use interval postProcessing? 10 times in a project at max?!? Anyway feel free to provide a PR.

@obermillerk
Copy link
Author

I mean even once, you set up i18next and tell it to use this plugin, why would I then have to pass this extra argument to get the functionality? There may be a good reason why it was done, I just don't see it personally. Just seems like one more thing to forget to do down the line when I haven't been focused on internationalization for a while and want to use an interval, you know?

I'll see about taking a stab at a PR when I have some time.

@jamuhl
Copy link
Member

jamuhl commented Jul 23, 2021

Because you tell not that there is a plugin -> it's a postProcessor that gets applied to the translations -> having performance impact...

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