Skip to content

Instantly share code, notes, and snippets.

@SamadiPour
Last active November 30, 2023 11:32
Show Gist options
  • Save SamadiPour/ebeba0843bd62b0c8bceb17c3a51f49b to your computer and use it in GitHub Desktop.
Save SamadiPour/ebeba0843bd62b0c8bceb17c3a51f49b to your computer and use it in GitHub Desktop.
Localisation file sorting
# 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