i18n-ally icon indicating copy to clipboard operation
i18n-ally copied to clipboard

Allow keys to be sorted alphabetically instead of binarily

Open dantman opened this issue 2 years ago • 2 comments

Additional context i18n Ally seems to use a binary sort. Given the following this is how i18n Ally will sort messages vs. what is expected and how other tooling may sort the messages.

// i18n Ally's order
[ 'addOption', 'additional' ]
// Expected order (how other tooling may sort)
[ 'additional', 'addOption' ]

Normally you'd expect "O" to come after "i" (either because "o" comes after "i" or because "O" is capitalized). However when i18n Ally sorts the "O" comes before "i". This appears to be because i18n Ally uses the default .sort() which does a binary sort of strings. And 'O'.charCodeAt(0) === 79 while 'i'.charCodeAt(0) === 105.

Is your feature related to a specific framework or general for this extension General

Is your feature request related to a problem? Please describe. I want to use i18next-parser to cleanup my messages files. However when I tell i18n Ally to sort it sorts the already sorted messages differently because i18next-parser (and potentially other tools) uses an alphabetic sort instead of a binary sort.

Describe the solution you'd like i18n Ally should have a way to sort keys using an Intl.Collator instead of a binary sort.

I think we should add a sortLocale setting with the following possible options:

  • binary (default, current behaviour) do a binary sort
  • auto - use the message's own locale as the sort collator (i.e. sort en/common.json using an en collator and sort fr/common.json with a fr collator)
  • locale code - sort using this locale's collator (i.e. if en sort all messages files with an en collator)

dantman avatar Dec 08 '21 20:12 dantman

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 06 '22 21:02 stale[bot]

Not stale

dantman avatar Feb 06 '22 21:02 dantman

I'm also having the issue, that the alphabetical sorted JSONs exported from lokalise.com have different sorting than the ones re-ordered by the code-extension when adding a key via the built-in dialog.

rs3d avatar Apr 20 '23 14:04 rs3d

I have the same problem; this causes inconsistency between editing from the i18n-ally editor with "i18n-ally.sortKeys": true, and directly editing the JSON and running the JSON: Sort Document command. Each time the editing method is changed, the translations are reordered.

v36u avatar Jul 03 '23 18:07 v36u