i18next/i18next-v4-format-converter

The command line version of this doesn't replace plurals with other.

Closed this issue · 13 comments

adrai commented

Can you please provide a reproducible example or a failing test here: https://github.com/i18next/i18next-v4-format-converter/blob/main/test/converter.spec.js

image

I tested, and its only failing with your bin version published on npm.

npm install -g i18next-v4-format-converter

And run it on

{
  "user_one": "{{count}} user",
  "user_plural": "{{count}} users"
}
adrai commented

Just tested on 2 different machines... it works, but your example json is not correct, correct v3 format looks like this:

{
  "user": "{{count}} user",
  "user_plural": "{{count}} users"
}

"user" not "user_one"

adrai commented

example:

image

{
  "user": "{{count}} user",
  "user_plural": "{{count}} users",
  "number_of_posts": "sing post",
  "number_of_posts_plural": "plur post"
}
➜  tmp i18next-v4-format-converter
transformed 1 files: /Users/usr/test-project/tmp
{
  "user_one": "{{count}} user",
  "user_other": "{{count}} users",
  "number_of_posts_one": "sing post",
  "number_of_posts_other": "plur post"
}

Sorry, I accidentally showed you the results, not the input file, which was:

{
  "user": "{{count}} user",
  "user_plural": "{{count}} users"
}

Can you verify that you're using the npm published version? IE

npm uninstall -g i18next-v4-format-converter
npm i -g i18next-v4-format-converter@1.0.1

Okay, I set up a reproducible example using docker:

git clone https://github.com/dessalines/docker_i18next_converter
cd docker_i18next_converter
docker build  . --progress=plain 

You can clearly see that your published version doesn't produce the correct output:

#8 [5/7] RUN cat test.json
#8 sha256:0f9b08911ff5613f9884c439978f8529340b7eb546fdd743d390145f80053378
#8 0.679 { "user": "{{count}} user", "user_plural": "{{count}} users" }
#8 DONE 0.7s

#9 [6/7] RUN i18next-v4-format-converter
#9 sha256:3e2a7599e027fc73c644c93308c9473a1fe0bea87294a4242dad17e1cfcb64a2
#9 0.939 transformed 1 files: /test
#9 DONE 1.0s

#10 [7/7] RUN cat test.json
#10 sha256:ff3ba22abd3894fb56ec780b4a96aec5482196305d0d927efc125fe9899fad31
#10 0.723 {
#10 0.723   "user_one": "{{count}} user",
#10 0.723   "user_plural": "{{count}} users"
#10 0.723 }#10 DONE 0.8s
adrai commented

It seems you have no directory structure with language codes, but just a flat structure: https://github.com/dessalines/docker_i18next_converter/blob/main/Dockerfile#L4
This way the converter has no idea which language should be used...

adrai commented

fyi: with v1.0.2 it will fallback to the default plural rules bahaviour, so this should also be ok.

Thanks, that did it!

image

i18next-v4-format-converter -i locales/
transformed 306 files

[CLI] with 306 files, in languages ch or jp files _plural was not changed to _other. But on the second attempt, they were changed

image

i18next-v4-format-converter -i locales/ transformed 306 files

[CLI] with 306 files, in languages ch or jp files _plural was not changed to _other. But on the second attempt, they were changed

For me _plural is not changed to _other for files in languages id, ja and zh

adrai commented

These languages has no _plural suffix at all: https://jsfiddle.net/6bpxsgd4

Oh yeah understood, I guess we anyway added the _plural for these languages with same values.