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

ICU will ignore the first blank in plural #29

Closed
acdzh opened this issue Jan 4, 2021 · 2 comments
Closed

ICU will ignore the first blank in plural #29

acdzh opened this issue Jan 4, 2021 · 2 comments

Comments

@acdzh
Copy link

acdzh commented Jan 4, 2021

🐛 Bug Report

Hello! I found the icu will ignore the first blank in plural, just like this demo. Please look at the { a} in key1. Is this a bug or just a feature? Is there any way to solve this problem? Because our i18n translations are auto-generated like key1, It is diffcullt to change the translation to like key2. Thanks!

image

To Reproduce

codepen

or

<div>
  <div>key1: {count} apple{num, plural, one { a} other{s two}} day, keep doctor away.</div><br />
  <div>1 apple: <div id="div11"></div></div><br />
  <div>2 apple: <div id="div12"></div></div><br />
</div>
<br />
<div>
  <div>key2: {count} {num, plural, one {apple a} other{apples two}} day, keep doctor away.</div><br />
  <div>1 apple: <div id="div21"></div></div><br />
  <div>2 apple: <div id="div22"></div></div><br />
</div>
const translation = {
  key1: '{count} apple{num, plural, one { a} other{s two}} day, keep doctor away.',
  key2: '{count} {num, plural, one {apple a} other{apples two}} day, keep doctor away.'
};

i18next.use(ICU).init({
  lng: "en",
  resources: {
    en: { translation }
  }
});


const div11 = document.getElementById('div11');
const div12 = document.getElementById('div12');
const div21 = document.getElementById('div21');
const div22 = document.getElementById('div22');

div11.innerText = i18next.t('key1', {count: 1, num: 1});
div12.innerText = i18next.t('key1', {count: 2, num: 2});
div21.innerText = i18next.t('key2', {count: 1, num: 1});
div22.innerText = i18next.t('key2', {count: 2, num: 2});

Expected behavior

We want the key1 and key2 have the same result.

Your Environment

  • runtime version: node v14.15.0, Crome 87
  • i18next version: 19.8.4
  • i18next-icu version: 1.4.2
  • os: Mac and Linux
@jamuhl
Copy link
Member

jamuhl commented Jan 5, 2021

the ICU variant of i18next depends on the implementation used in react-intl: https://github.com/i18next/i18next-icu/blob/master/package.json#L18

so, if an issue it would need to be solved there...

but honestly I recommend you to not build up your strings like you do as messageformat encourages having full sentences

{
   count, plural,
     one {One apple a day, keep the doctor away}
   other {# apples a day, keep the doctor away }
 }

@acdzh
Copy link
Author

acdzh commented Jan 5, 2021

the ICU variant of i18next depends on the implementation used in react-intl: https://github.com/i18next/i18next-icu/blob/master/package.json#L18

so, if an issue it would need to be solved there...

but honestly I recommend you to not build up your strings like you do as messageformat encourages having full sentences

{
   count, plural,
     one {One apple a day, keep the doctor away}
   other {# apples a day, keep the doctor away }
 }

tks

@acdzh acdzh closed this as completed Jan 5, 2021
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