Skip to content

Commit

Permalink
pkp/pkp-lib#8598 Several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat committed Feb 6, 2023
1 parent e6f2ac3 commit 1685045
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 59 deletions.
6 changes: 4 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"program": "${file}",
// "args": ["../Locales_Test", "es", "es_ES"],
// "args": ["../ojs-3-dev-main", "en", "en_US"],
// "args": ["./inputRepos.txt", "./inputLocales.txt"],
"args": ["../ojs-3-dev-main", "sr", "sr_RS"],
"args": ["./inputRepos.txt", "./inputLocales.txt"],
// "args": ["../ojs-3-dev-main", "sr", "sr_RS"],
// "args": ["../ojs-3-dev-main", "-s", "sr", "-l", "sr_RS", "sr_RS2", "sr_RS3"],
// "args": ["../ojs-3-dev-main", "-l", "zh_Hant", "zh_TW"],
}
]
}
14 changes: 12 additions & 2 deletions DriverScript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ readarray -t repos < "$(echo "$input_repos" | tr -d '\r\n')"
declare -a locale_params
readarray -t locale_params < "$(echo "$input_locale_params" | tr -d '\r\n')"

# for repo in "${repos[@]}"; do
# for locale_param in "${locale_params[@]}"; do
# echo "/bin/bash ./FinalLocaleMigration.sh $repo $locale_param"
# /bin/bash ./FinalLocaleMigration.sh $repo $locale_param
# done
# done
current_dir=$(pwd)

for repo in "${repos[@]}"; do
cd $repo
for locale_param in "${locale_params[@]}"; do
echo "/bin/bash ./FinalLocaleMigration.sh $repo $locale_param"
/bin/bash ./FinalLocaleMigration.sh $repo $locale_param
echo "/bin/bash $current_dir/FinalLocaleMigrationWithOptions.sh $current_dir ./ $locale_param"
/bin/bash "$current_dir/FinalLocaleMigrationWithOptions.sh" $current_dir ./ $locale_param
done
cd $current_dir
done
4 changes: 2 additions & 2 deletions FinalLocaleMigration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ for root_parent_folder in "${root_parent_folders[@]}"; do
echo "rm -r $actual_finale_action_folder_path"
rm -r $actual_finale_action_folder_path

echo "git add -u ${folder_filenames[@]}"
git add -u ${folder_filenames[@]}
echo "git add -u $actual_finale_action_folder_path"
git add -u $actual_finale_action_folder_path
fi
done

Expand Down
41 changes: 41 additions & 0 deletions FinalLocaleMigrationWithOptions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
PATH=$PATH:/usr/bin

current_dir=$1
repo_folder=$2

while [[ $# -gt 0 ]]; do
case $1 in
-l)
shift
list=("$@")
break
;;
-s|--switch)
base_locale="$2"
shift
;;
-d|--switch)
default_locale="$2"
shift
;;
*)
# other options
;;
esac
shift
done

if [ -n "$base_locale" ]; then
if [ -n "$default_locale" ]; then
echo "/bin/bash $current_dir/FinalLocaleMigration.sh $repo_folder $base_locale $default_locale"
/bin/bash $current_dir/FinalLocaleMigration.sh $repo_folder $base_locale $default_locale
else
echo "You have to declare a default locale"
fi
else
# echo "$repo_folder + $base_locale + List of parameters after -l switch: ${list[@]} withOUT switch"
echo "/bin/bash $current_dir/MergeListOfLocales.sh $repo_folder -l ${list[@]}"
/bin/bash $current_dir/MergeListOfLocales.sh $repo_folder -l ${list[@]}
fi

121 changes: 121 additions & 0 deletions MergeListOfLocales.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/bin/bash
PATH=$PATH:/usr/bin

# Get parameters
repo_folder=$1
locale_folder_names=()


while [[ $# -gt 0 ]]; do
case $1 in
-l)
shift
locale_folder_names=("$@")
break
;;
esac
shift
done

k=$(echo "${locale_folder_names[@]}" | tr ' ' '|')
echo $k

default_locale_folder=${locale_folder_names[0]}

# Get all the folder names that actually contain any .po files, and list their parent's parent folder.
echo "git -C $repo_folder ls-files --full-name | grep -E '($k)/[^/]+\.po$' | xargs dirname | xargs -n 1 dirname | sort | uniq"
root_parent_folders=($(git -C $repo_folder ls-files --full-name | grep -E "($k)/[^/]+\.po$" | xargs dirname | xargs -n 1 dirname | sort | uniq))

for root_parent_folder in "${root_parent_folders[@]}"; do
actual_root_locale_folder_path="$repo_folder/$root_parent_folder"

# Check if that folder actually exists
if [ ! -d "$actual_root_locale_folder_path" ]; then
echo "Not there $actual_root_locale_folder_path"
continue
fi

# List all the base filenames (like admin.po, locale.po, submission.po, etc) from this root locale folder, that are contained into
# the searched locale code
file_filenames=($(git -C $actual_root_locale_folder_path ls-files | grep -E "($k)/[^/]+\.po$" | xargs -n 1 basename | sort | uniq))

for file_filename in "${file_filenames[@]}"; do
folder_to_attach="$repo_folder/$root_parent_folder/"

# Get all the .po files filenames that are contained to a locale folder with the specified locale code, and add the relative folder path to that.
folder_filenames=($(git -C $actual_root_locale_folder_path ls-files | grep -E "($k)/$file_filename" | grep -v @ | xargs -I {} echo "${folder_to_attach}{}" | sort | uniq))

# Declare the path that it would be the .po file name path in the default locale folder, which is declared as an input param ...
default_file_name="$folder_to_attach/$default_locale_folder/$file_filename"

if [ "${#folder_filenames[@]}" -gt 0 ]; then

# if there are more than one .po files that are contained to a locale folder with the specified locale code
if [ "${#folder_filenames[@]}" -gt 1 ]; then
# Make sure that there are no dublicate translation keys in each .po file - remove them if there are
for folder_filename in "${folder_filenames[@]}"; do
echo "msguniq --use-first $folder_filename -o $folder_filename"
msguniq --use-first $folder_filename -o $folder_filename
done

echo "msgcat --use-first ${folder_filenames[@]} -o "$default_file_name""
msgcat --use-first ${folder_filenames[@]} -o "$default_file_name"

echo "git add "$default_file_name""
git add "$default_file_name"

if [[ " ${folder_filenames[@]} " =~ " ${default_file_name} " ]]; then
# If it is in then remove the default locale folder filename from the array, in order to handle it differently ...
folder_filenames=(${folder_filenames[@]/$default_file_name})
fi
# Finally remove all the .po files that we have just merged.
echo "rm ${folder_filenames[@]}"
rm ${folder_filenames[@]}

echo "git add -u ${folder_filenames[@]}"
git add -u ${folder_filenames[@]}
else
# if there is only one .po files that are contained to a locale folder with the specified locale code ...
only_file=${folder_filenames[0]}

# ... just move it in the base locale folder
echo "mv $only_file "$default_file_name""
mv $only_file "$default_file_name"

echo "git add "$default_file_name""
git add "$default_file_name"

echo "git add -u $only_file"
git add -u $only_file
fi
fi
done

locale_folder_names_no_first=("${locale_folder_names[@]:1}")
k_no_first=$(echo "${locale_folder_names_no_first[@]}" | tr ' ' '|')
echo $k_no_first

# Find and remove all locale folders that have no contents after the .po files merge
# Search for non empty locale folders and move them to the base locale folder adding a _depr to their name
finale_action_folders=($(git -C $actual_root_locale_folder_path ls-tree -r -d --name-only HEAD | xargs -n 1 basename | grep -E "($k_no_first)".* | grep -v @ | sort | uniq))

for finale_action_folder in "${finale_action_folders[@]}"; do
actual_finale_action_folder_path="$actual_root_locale_folder_path/$finale_action_folder"
if [ -n "$(ls -A "$actual_finale_action_folder_path")" ]; then
# Actions if the folder is not empty
finale_action_folder_name=($(basename ${actual_finale_action_folder_path}))
echo "mv $actual_finale_action_folder_path "$repo_folder/$root_parent_folder/$default_locale_folder/depr_$finale_action_folder_name"_depr"
mv $actual_finale_action_folder_path "$repo_folder/$root_parent_folder/$default_locale_folder/depr_$finale_action_folder_name"_depr

echo "git add "$repo_folder/$root_parent_folder/$default_locale_folder/depr_$finale_action_folder_name"_depr"
git add "$repo_folder/$root_parent_folder/$default_locale_folder/depr_$finale_action_folder_name"_depr
else
# Actions id the folder is empty
echo "rm -r $actual_finale_action_folder_path"
rm -r $actual_finale_action_folder_path

echo "git add -u $actual_finale_action_folder_path"
git add -u $actual_finale_action_folder_path
fi
done
done
105 changes: 52 additions & 53 deletions inputLocales.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
es es_ES
en en_US
sr sr_RS
el el_GR
de de_DE
da da_DK
cs cs_CZ
ca ca_ES
bs bs_BA
bg bg_BG
be be_BY
az az_AZ
ar ar_IQ
fa fa_IR
fi fi_FI
gd gd_GB
gl gl_ES
he he_IL
hi hi_IN
hr hr_HR
hu hu_HU
hy hy_AM
id id_ID
is is_IS
it it_IT
ja ja_JP
ka ka_GE
kk kk_KZ
ko ko_KR
ku ku_IQ
lt lt_LT
lv lv_LV
mk mk_MK
mn mn_MN
ms ms_MY
nb nb_NO
nl nl_NL
pl pl_PL
pt pt_PT
ro ro_RO
ru ru_RU
si si_LK
sk sk_SK
sl sl_SI
sv sv_SE
tr tr_TR
uk uk_UA
ur ur_PK
uz uz_UZ
vi vi_VN
zh zh_CN
eu eu_ES
sw sw_KE
-s es -d es_ES
-s en -d en_US
-s sr -d sr_RS
-s el -d el_GR
-s de -d de_DE
-s da -d da_DK
-s cs -d cs_CZ
-s ca -d ca_ES
-s bs -d bs_BA
-s bg -d bg_BG
-s be -d be_BY
-s az -d az_AZ
-s ar -d ar_IQ
-s fa -d fa_IR
-s fi -d fi_FI
-s gd -d gd_GB
-s gl -d gl_ES
-s he -d he_IL
-s hi -d hi_IN
-s hr -d hr_HR
-s hu -d hu_HU
-s hy -d hy_AM
-s id -d id_ID
-s is -d is_IS
-s it -d it_IT
-s ja -d ja_JP
-s ka -d ka_GE
-s kk -d kk_KZ
-s ko -d ko_KR
-s ku -d ku_IQ
-s lt -d lt_LT
-s lv -d lv_LV
-s mk -d mk_MK
-s mn -d mn_MN
-s ms -d ms_MY
-s nb -d nb_NO
-s nl -d nl_NL
-s pl -d pl_PL
-s ro -d ro_RO
-s ru -d ru_RU
-s si -d si_LK
-s sk -d sk_SK
-s sl -d sl_SI
-s sv -d sv_SE
-s tr -d tr_TR
-s uk -d uk_UA
-s ur -d ur_PK
-s uz -d uz_UZ
-s vi -d vi_VN
-s eu -d eu_ES
-s sw -d sw_KE
-l zh_Hant zh_TW

0 comments on commit 1685045

Please sign in to comment.