Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow keys to be sorted alphabetically instead of binarily #702

Closed
dantman opened this issue Dec 8, 2021 · 4 comments · Fixed by #703
Closed

Allow keys to be sorted alphabetically instead of binarily #702

dantman opened this issue Dec 8, 2021 · 4 comments · Fixed by #703

Comments

@dantman
Copy link
Contributor

dantman commented Dec 8, 2021

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)
@stale
Copy link

stale bot commented Feb 6, 2022

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 stale bot added the stale label Feb 6, 2022
@dantman
Copy link
Contributor Author

dantman commented Feb 6, 2022

Not stale

@stale stale bot removed the stale label Feb 6, 2022
@rs3d
Copy link

rs3d commented Apr 20, 2023

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.

@v36u
Copy link

v36u commented Jul 3, 2023

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.

terales added a commit that referenced this issue Aug 27, 2023
* add option to sorting message by a locale's order

Fixes #702

* Empty commit to trigger CI

---------

Co-authored-by: Alex Terehov <terales@users.noreply.github.com>
huacnlee pushed a commit to huacnlee/i18n-ally that referenced this issue Aug 28, 2023
)

* add option to sorting message by a locale's order

Fixes lokalise#702

* Empty commit to trigger CI

---------

Co-authored-by: Alex Terehov <terales@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants