gilbsgilbs / babel-plugin-i18next-extract

Babel plugin that statically extracts i18next and react-i18next translation keys.
https://i18next-extract.netlify.com
MIT License
159 stars 37 forks source link

Fix plural issue with lang-region locale #257

Closed xu3u4 closed 10 months ago

xu3u4 commented 10 months ago

To fix #256

For {language}-{region} format locale, the plural count key can't be generated correctly. The locale from the result of pluralRule.resolvedOptions(); may only contain the language part, without the region. Although the value of locale should be BCP 47 language tag, but node(only tested on v18.17) and some browsers don't support it yet. So I think we can also compare the language part of the locale.

On node v18.17

const pluralRules = new Intl.PluralRules('en-US');
const options = pluralRules1.resolvedOptions();

console.log(options);
// output: Object { locale: "en", type: "cardinal",....}
xu3u4 commented 10 months ago

Hi @gilbsgilbs May I have your review when you have time 🙏

gilbsgilbs commented 10 months ago

Thanks for the PR, I'll look into it ASAP. In the meantime, could you add a test for your fix?

xu3u4 commented 10 months ago

Thank you for your suggestion 🙇‍♀️ , just added!

xu3u4 commented 10 months ago

@gilbsgilbs I saw your change that using startWith looks good! Thank you very much.

gilbsgilbs commented 10 months ago

I'll make a release later this week, probably tonight or tomorrow. I want to do some chore before releasing (mainly update dependencies, drop EOLed node versions and officially support newer node versions).

gilbsgilbs commented 10 months ago

Just published it under the 0.9.1 tag on NPM. Thank you again for your contribution, that's appreciated.