-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7038 from Ocelot-Social-Community/normalize-local…
…e-files feat(webapp): normalize locale files
- Loading branch information
Showing
10 changed files
with
3,878 additions
and
242 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# normalize-locales.jq | ||
# | ||
# creates a copy of the structure of source and replaces the values | ||
# by the corresponding values of target. If a key does not exist in target, | ||
# the value is set to null. | ||
# | ||
# jq -n --argfile source en.json --argfile target es.json -f normalize-locales.jq | ||
# | ||
# source should be primary or fallback locale file (here en.json) | ||
# taget is the locale file to normalize (here es.json) | ||
|
||
def find_key_by_path($path): | ||
if $path | length == 0 | ||
then . | ||
elif .[$path[0]] | ||
then .[$path[0]] | find_key_by_path($path[1:]) | ||
else null | ||
end; | ||
|
||
def keys_to_paths_recursive($path): | ||
if type == "object" | ||
then with_entries( | ||
($path + [.key]) as $path | | ||
if (.value | type == "string") | ||
then .value |= ($target | find_key_by_path($path)) | ||
else .value |= keys_to_paths_recursive($path) | ||
end) | ||
else . | ||
end; | ||
|
||
$source | keys_to_paths_recursive([]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#! /usr/bin/env bash | ||
|
||
ROOT_DIR=$(dirname "$0")/../.. | ||
tmp=$(mktemp) | ||
|
||
locale_list=("es.json" "fr.json" "it.json" "nl.json" "pl.json" "pt.json" "ru.json") | ||
|
||
for locale_file in "${locale_list[@]}" | ||
do | ||
jq -n \ | ||
-f $(dirname "$0")/normalize-locales.jq \ | ||
--argfile source $ROOT_DIR/webapp/locales/en.json \ | ||
--argfile target $ROOT_DIR/webapp/locales/$locale_file \ | ||
> "$tmp" | ||
mv "$tmp" $ROOT_DIR/webapp/locales/$locale_file | ||
done | ||
|
||
exit 0 | ||
|
Oops, something went wrong.