Last active
November 30, 2023 11:32
-
-
Save SamadiPour/ebeba0843bd62b0c8bceb17c3a51f49b to your computer and use it in GitHub Desktop.
Localisation file sorting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sort first by Word Count and then Characters count - only if it's is <String, String> | |
jq 'to_entries | map({ key: .key, value: .value, word_count: (.value | split(" ") | length), char_count: (.value | length) }) | sort_by(.word_count, .char_count) | from_entries' en.json > sorted_en.json && mv sorted_en.json en.json | |
# Sort first by Word Count, then by Characters count, and then alphabetical - skips collections that are at end | |
jq '. | to_entries | reduce .[] as $entry ( {}; if $entry.value | type == "object" then .collections += [$entry] else .non_collections += [$entry] end ) | (.non_collections | map({ key: .key, value: .value, word_count: (.value | split("\n") | map(split(" ")) | map(length) | add), char_count: (.value | length) }) | sort_by(.word_count, .char_count, .key)) + .collections | from_entries' en.json > sorted_en.json && mv sorted_en.json en.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment