Last active
September 18, 2017 09:44
-
-
Save amatmv/72de50ae5677e1a5d259565f415f53ba to your computer and use it in GitHub Desktop.
MergeTool For translations
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
#!/bin/bash | |
# This script should be placed in the /tools folder of the ERP base directory. | |
# And be executed from the /erp directory this way: ./tools/merge_trans.sh -m <module_name> | |
module=$2 | |
if [[ -z $1 ]] || [[ "$1" != "-m" ]] || [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]] || [[ -z $2 ]]; then | |
echo "Indicate the module that has conflicts this way: -m <module-name>." | |
else | |
line=1 | |
module_dir=`cd .. | locate -r /$module$ | grep "erp/addons" | sed -n "$line"p` | |
if [[ -z $module_dir ]]; then | |
printf "\e[31mTHIS MODULE DOESNT'T EXIST.\nEXITING...\e[0m\n" && exit -1 | |
fi | |
printf "Is this your module directory: \e[32m\e[1m`cd .. | locate -r /$module$ | grep "erp/addons" | head -n $line`\e[0m? [Y/n] " | |
read input | |
if [[ $input = "n" ]]; then | |
n_lines=`cd .. | locate -r /$module$ | grep "erp/addons" | wc -l` | |
n=1 | |
for line in `cd .. | locate -r /$module$ | grep "erp/addons"`; | |
do | |
echo $n $line | |
let n=$n+1 | |
done | |
printf "Indicate the module directory by entering the number of the line [1-$n_lines]:" | |
read line | |
echo "OK: `cd .. | locate -r /$module$ | grep "erp/addons" | sed -n "$line"p`" | |
fi | |
module_po=$module_dir/i18n/es_ES.po | |
module_pot=$module_dir/i18n/$module.pot | |
printf "\e[34mINFO:\e[0m Merging $module_dir .po ...\n" | |
printf "\e[34mINFO:\e[0m Copying local po file before merge\n" | |
cp $module_po es_ES.local.po 2> /dev/null || (printf "\e[31mTHERE ISN'T ANY .po FILE IN THE i18n DIRECTORY.\nEXITING...\e[0m\n"; exit -1) | |
printf "\e[34mINFO:\e[0m Copying local pot file before merge\n" | |
cp $module_pot $module.local.pot 2> /dev/null || (printf "\e[31mTHERE ISN'T ANY .pot FILE IN THE i18n DIRECTORY.\nEXITING...\e[0m\n"; exit -1) | |
printf "\e[34mINFO:\e[0m Getting remote po file from master before merge to avoid conflicts\n" | |
git checkout origin/developer -- $module_po | |
git checkout origin/developer -- $module_pot | |
cp $module_po es_ES.remote.po | |
printf "\e[34mINFO:\e[0m Resetting po file from local branch\n" | |
git reset HEAD $module_po | |
git checkout -- $module_po | |
printf "\e[34mINFO:\e[0m Merging pofile using msgcat\n" | |
msgcat --use-first es_ES.local.po es_ES.remote.po -o es_ES.merge.po | |
mv es_ES.merge.po $module_po | |
printf "\e[34mINFO:\e[0m Cleaning repository\n" | |
rm es_ES.local.po | |
rm es_ES.remote.po | |
printf "\e[34mINFO:\e[0m Merging pot file with the new translations...\n" | |
msgmerge -U $module_po $module_pot | |
git add $module_po | |
git add $module_pot | |
rm $module.local.pot | |
if [[ -f $module_po~ ]]; then | |
rm $module_po~ | |
fi | |
printf "\e[34mINFO:\e[0m Done!\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment