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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deault values in t function do not work #2124

Closed
Toto5931 opened this issue Jan 24, 2024 · 10 comments
Closed

Deault values in t function do not work #2124

Toto5931 opened this issue Jan 24, 2024 · 10 comments

Comments

@Toto5931
Copy link

馃悰 Bug Report

Default values in t function do not work

To Reproduce

              t("key1", {count: 0,
			defaultValue_zero: "no item",
			defaultValue_one: "one item",
			defaultValue_other: "{{count}} items",
		})
renders: one item

Expected behavior

It renders "one item" whereas I would have expected zero.
If I put this in a traduction file it works but I want my code to be the source of thruth.

Your Environment

  • runtime version: browser
  • i18next version: 23.7.18
  • os: Windows
  • any other relevant information
@adrai adrai transferred this issue from i18next/i18next-http-backend Jan 24, 2024
@adrai
Copy link
Member

adrai commented Jan 24, 2024

should be fixed with i18next v23.7.19

@Toto5931
Copy link
Author

Thanks. It works if saveMissing: false

But in this sandbox example as soon as I activate saveMissing:true, the displays goes to "one item def" instead of "no item def".

And the POST requests are {key12_one: "one item def"}, {key12_other: "{{count}} items def"} and {key12_many: "no item def"} whereas I would have expected key12_zero instead of key12_many

@adrai
Copy link
Member

adrai commented Jan 26, 2024

That's because of the fallbackLng it defaults to dev....
We've just released v23.7.20 that should address this.

@Toto5931
Copy link
Author

Thank you for your quick response

There is still one problem, in this sandox example {key_many: "no item def"} is sent in POST whereas it is not defined in the default value. Moreover it takes the value of key_zero, which makes no sense.

For your information, if we change the order of the ressource from

    translation: {
      key_one: "{{count}} item",
      key_other: "{{count}} items",
      key_zero: "no item",
    },

to

    translation: {
      key_zero: "no item",
      key_one: "{{count}} item",
      key_other: "{{count}} items",
    },

the problem does not happen.

Thanks !

@adrai
Copy link
Member

adrai commented Jan 26, 2024

currently afk... but I guess that's because of the used language...
_zero is sent if there is also a defaultValue_zero provided

@adrai
Copy link
Member

adrai commented Jan 26, 2024

i'm not able to reproduce your issue...

@Toto5931
Copy link
Author

The issue is reproduced in the sandbox link I gave. Try refreshing several times since the network exchanges are not always displayed (I don't know why)
See the capture below. "_many" is sent in POST whereas it is not defined as default. And its value is the one of "_zero" so it is dangerous.
Capture
Thanks !

@adrai
Copy link
Member

adrai commented Jan 27, 2024

It's not because of the refresh... it's because of the detected language... that's why I'm not able to reproduce it... for me it detects english... for you probably french...
if I add ?lng=fr in the url, I can also see the key_many... but this is correct for french... this occurs, because you set the fallbackLng to false...
try to set it to en => fallbackLng: 'en',

@Toto5931
Copy link
Author

What is the link between the fallbackLng and the fact that it sends _many whereas it does not exist?
I need to keep fallbackLng to false since I do not want that he loads 2 language files when 1 language is enough

@adrai
Copy link
Member

adrai commented Jan 27, 2024

The reason is the saveMissingTo option: https://www.i18next.com/overview/configuration-options

@adrai adrai closed this as completed Feb 17, 2024
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