i18n-ally
i18n-ally copied to clipboard
Allow keys to be sorted alphabetically instead of binarily
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. sorten/common.json
using anen
collator and sortfr/common.json
with afr
collator) -
locale code
- sort using this locale's collator (i.e. ifen
sort all messages files with anen
collator)
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.
Not stale
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.
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.