eslint-plugin-i18n-json icon indicating copy to clipboard operation
eslint-plugin-i18n-json copied to clipboard

Add option to check for duplicate values to `identical-keys`

Open rafaelgomesxyz opened this issue 3 years ago • 8 comments

This is really useful when you have a main file, like /en/messages.json, from which all messages are copied to the other files, as it can detect messages that you probably forgot to translate. In cases where the value is expected to be duplicate, one can simply use the setting to ignore keys.

I got an error while running npm test, but I also got it when I tested as soon as I cloned the repo, so maybe it's because I'm on Linux?

Edit: Nope, looks like that's the same error that the Travis CI build reported.

rafaelgomesxyz avatar Jul 19 '20 00:07 rafaelgomesxyz

Seeing the same snapshot error, looks like a dependency's behavior changed within a major version. If I roll back to the versions specified in package.json, snapshots render as expected.

pnevares avatar Jul 19 '20 02:07 pnevares

Seeing the same snapshot error, looks like a dependency's behavior changed within a major version. If I roll back to the versions specified in package.json, snapshots render as expected.

Interestingly, if I roll back and then install the latest versions again, it seems to work. Weird.

rafaelgomesxyz avatar Jul 19 '20 12:07 rafaelgomesxyz

Hey @rafaelgssa , will review this PR and your other PR this week

Thanks!

mayank23 avatar Aug 11 '20 21:08 mayank23

Had to get a security release out, but will be reviewing this PR this week. Going one by one through the open PRs 😄 .

mayank23 avatar Aug 18 '20 22:08 mayank23

No problem! There's no rush.

rafaelgomesxyz avatar Aug 22 '20 00:08 rafaelgomesxyz

Hey, I updated both PRs to pass the checks. Could you please take a look?

rafaelgomesxyz avatar May 02 '21 01:05 rafaelgomesxyz

Thanks for the PR :), I have a few questions though, I'm a bit unclear on the use case based on the description.

I think in JSON, duplicate values lead to undefined behavior? I haven't really seen JSON objects with duplicate keys. Because a Javascript object has a unique set of keys, so in the end there is only one value for a property right?

Could you elaborate further on some use cases for having duplicate keys in your translations in the first place and your feature?

mayank23 avatar May 24 '21 22:05 mayank23

It's not about duplicate keys, but duplicate values for the same path across files, compared to a reference file. Let's say you have two files like this:

en-US.json

{
  "testingA": "Testing A",
  "testingB": "Testing B",
  "testingC": {
    "testingD": "Testing D",
    "testingE": "Testing E"
  }
}

pt-BR.json

{
  "testingA": "Testando A",
  "testingB": "Testing B",
  "testingC": {
    "testingD": "Testando D",
    "testingE": "Testing E"
  }
}

Where en-US.json is the reference file. I want to be able to detect that there are some values (testingB and testingC.testingE) that are not translated in the other file.

That's what this option does, it will show an error for those paths, because they have duplicate values compared to the reference file.

rafaelgomesxyz avatar May 24 '21 23:05 rafaelgomesxyz