#!/bin/bash # turn tracing on with /bin/bash -x # # Check for translation work by checking out / updating from SVN and # displaying the project name when your language.po has fuzzy strings or # empty string messages. Also useful for translation of web pages. # # Filip Komar, 2012, 2013 # Remco Rijnders, 2012 # $Id$ # # Please see SVN for a list of changes to this script. # # More information about this script is in README file. if [ -f ~/.mageia-i18n-config ]; then source ~/.mageia-i18n-config else cat > ~/.mageia-i18n-config << "EOF" # Please change the below values to match your needs: language_code=xx # Where to put the svn files and your working directory, # please make sure those directories exist before running the script!!! svn_directory="/home/user/Mageia/i18n/svn" working_translations_directory="/home/user/Mageia/i18n/translations" # choose svn method: # 1. anonymous (no commit access) svn_method="svn://" # 2. public ssh key svn access. Remember to upload it to identity! # Otherwise it will prompty you for password everytime for every resource. #svn_method="svn+ssh://" # The following lines can be changed if you desire, but this is # not needed to properly use this script. # set checking syntax of po files with 1 check_po_syntax=1 # set copying of po files with 1 copying_po=1 # set copying of web page files with 1 copying_wp=1 # uncomment next line to exclude checkout of software resources for mageia 2 #checkout_soft_mga2=no # ADVANCED SETTINGS # set checking syntax of pot files with 1 check_pot_syntax=0 # set copying options (-i: interactive, -v: verbose, -u: update, -r: recursive) copy_options="-ivur" # choose log filename log_filename="updated_translations_in_svn" log_directory="$svn_directory" logfile="$svn_directory/$log_filename" # switch of logging by uncommenting the following line #logfile="/dev/null" # set checking of fuzzy and untranslated strings with 1 # WARNING: listings can be really long check_fuzzy_and_untranslated=0 # checkout whole website www.mageia.org and mognase navigation checkout_whole_website=0 # set searching for new *.pot files in svn with 1 searching_for_new_pot_files_in_svn=0 # whether to look for new versions of the script and project files check_updates=1 EOF echo "This script has not been configured yet for you. A template" echo "configuration file named .mageia-i18n-config has been made in your" echo "home directory. Please edit it according to your needs and remember" echo "to create apropriate directories before running this script again." echo echo "For more information about this script please read README file." exit fi # save pwd to saved_dir saved_dir=$(pwd) if [ -f "$logfile"_this_run.log ]; then mv "$logfile"_this_run.log "$logfile"_previous_run.log fi separator="-----------------------------------------------------" # Check if both directories exist if [ ! -d "$svn_directory" ]; then mkdir -vp "$svn_directory/" | tee -a "$logfile"_this_run.log fi if [ ! -d "$working_translations_directory" ]; then mkdir -vp "$working_translations_directory/" | tee -a "$logfile"_this_run.log fi echo "" | tee -a "$logfile"_this_run.log echo "" | tee -a "$logfile"_this_run.log date | tee -a "$logfile"_this_run.log # Check if a newer version of this script is available. If yes, show the changes. my_version=`echo "$Revision$" | cut -d" " -f2` svn_version=`svn info svn://svn.mageia.org/svn/soft/i18n-tools/check_for_translation_work.sh | grep "Last Changed Rev:" | cut -c19-` echo Revision: $my_version | tee -a "$logfile"_this_run.log if [ $check_updates -eq 1 ]; then if [ $my_version -lt $svn_version ]; then echo "You are running revision $my_version of this script, while $svn_version is available on SVN." echo "You may consider updating. Changes are:" let "tmp=$my_version + 1" svn log -r $tmp:$svn_version svn://svn.mageia.org/svn/soft/i18n-tools/check_for_translation_work.sh fi svn export --force svn://svn.mageia.org/svn/soft/i18n-tools/translation_projects.dat "$svn_directory" echo "" fi declare -A projects declare -A web_pages source "$svn_directory/translation_projects.dat" echo "SW files:" | tee -a "$logfile"_this_run.log # echo about checking the syntax of po file if required if [ $check_po_syntax -eq 1 ]; then echo "Syntax of $language_code.po in svn will be tested." fi # echo about copying the *.pot file and $language_code.po for editing in apropriate directory if required if [ $copying_po -eq 1 ]; then echo "Files *.pot and $language_code.po will be copied into apropriate directory." fi for project_name in "${!projects[@]}" do echo $separator | tee -a "$logfile"_this_run.log echo Working on: \'$project_name\' from \'${projects[$project_name]}\'. | tee -a "$logfile"_this_run.log # Check out / update project files if [ -d "$svn_directory/$project_name" ]; then cd "$svn_directory/$project_name" # just echo $language_code.po or *.pot file line if they are updated svn up | grep -E "$language_code.po|[\.]pot" | tee -a "$logfile"_this_run.log # echo -n "" # debug else cd "$svn_directory" # just echo $language_code.po or *.pot file line if they are updated svn co $svn_method${projects[$project_name]} $project_name | grep -E "$language_code.po|[\.]pot" | tee -a "$logfile"_this_run.log # echo -n "" # debug cd "$svn_directory/$project_name" fi # verbose checking for fuzzy and untranslated strings if [ $check_fuzzy_and_untranslated -eq 1 ]; then msgattrib $language_code.po --only-fuzzy --no-obsolete msgattrib $language_code.po --untranslated --no-obsolete fi # checking the syntax of po file if required if [ $check_po_syntax -eq 1 ]; then if [ -f $language_code.po ]; then msgfmt --statistics --verbose -c $language_code.po -o $language_code.po.mo 2>&1 | tee -a "$logfile"_this_run.log rm $language_code.po.mo else echo "File $language_code.po is not present in $project_name. Automatic test is not possible." | tee -a "$logfile"_this_run.log fi # checking the syntax of po file if required if [ $check_pot_syntax -eq 1 ]; then if [ -f *.pot ]; then msgfmt -c *.pot -o pot.mo 2>&1 | tee -a "$logfile"_this_run.log rm pot.mo else echo "File *.pot is not present in $project_name. Automatic test is not possible." | tee -a "$logfile"_this_run.log fi fi fi # copying the *.pot file and $language_code.po for editing in working directory if required if [ $copying_po -eq 1 ]; then if [ ! -d "$working_translations_directory/$project_name/" ]; then mkdir -vp "$working_translations_directory/$project_name/" | tee -a "$logfile"_this_run.log fi if [ -f $language_code.po ]; then # testing for differences of *.po file from working copy if [ -f "$working_translations_directory/$project_name/$language_code.po" ]; then diff -q $language_code.po "$working_translations_directory/$project_name/$language_code.po" | tee -a "$logfile"_this_run.log fi cp $copy_options $language_code.po "$working_translations_directory/$project_name/" | tee -a "$logfile"_this_run.log else echo "File $language_code.po is not present in $project_name. Copying is not possible." | tee -a "$logfile"_this_run.log fi if [ -f *.pot ]; then # testing for differences of *.pot file from working copy if [ -f "$working_translations_directory/$project_name/"*.pot ]; then diff -q *.pot "$working_translations_directory/$project_name/"*.pot | tee -a "$logfile"_this_run.log fi cp $copy_options *.pot "$working_translations_directory/$project_name/" | tee -a "$logfile"_this_run.log # set -x # turn tracing on with set -x cd "$working_translations_directory/$project_name/" if [ -f *.pot_$language_code.po ]; then # creating new_pot_lang.po from latest *.pot file msgmerge -q *.pot_$language_code.po *.pot > new_pot_$language_code.po # msgmerge *.pot_lang.po *.pot > new_pot_lang.po # comparing new_pot_lang.po from working copy diff -q *.pot_$language_code.po new_pot_$language_code.po | tee -a "$logfile"_this_run.log # diff -q $language_code.po new_pot_$language_code.po | tee -a "$logfile"_this_run.log diff_exit_status_1=${PIPESTATUS[0]} # this reads and remembers exit status of first command in pipe (diff in this case) # if [ $? -eq 0 ]; then if [ $diff_exit_status_1 -eq 0 ]; then # no differences rm new_pot_$language_code.po # remove resulting file # echo Between *.pot_$language_code.po and new_pot_$language_code.po there are no differences. else if [ $diff_exit_status_1 -eq 1 ]; then # there are differences echo Replace existing file *.pot_$language_code.po with new_pot_$language_code.po in $project_name since there are differences. | tee -a "$logfile"_this_run.log else echo There was an error in diff between *.pot_$language_code.po and new_pot_$language_code.po in $project_name. fi fi # comparing svn lang.po from working copy lang.po if [ -f $language_code.po ]; then diff -q *.pot_$language_code.po $language_code.po | tee -a "$logfile"_this_run.log diff_exit_status_2=${PIPESTATUS[0]} # this reads and remembers exit status of first command in pipe (diff in this case) # if [ $? -eq 0 ]; then if [ $diff_exit_status_2 -eq 1 ]; then # there are differences echo New commit will be needed when the file *.pot_$language_code.po is ready in $project_name. | tee -a "$logfile"_this_run.log else if [ $diff_exit_status_2 -eq 2 ]; then # there was an error echo There was an error in diff between file *.pot_$language_code.po and $language_code.po in $project_name. fi fi fi else echo "File *.pot_$language_code.po is not present in $project_name. Comparing is not possible." | tee -a "$logfile"_this_run.log fi # set +x # turn tracing off with set +x else echo "File *.pot is not present in $project_name. Copying is not possible." | tee -a "$logfile"_this_run.log fi # echo "Files *.pot and $language_code.po copied into $working_translations_directory/$project_name/." fi cd "$svn_directory/" echo "" | tee -a "$logfile"_this_run.log done # Check out / update web_page files echo "web page files:" | tee -a "$logfile"_this_run.log for web_page_name in "${!web_pages[@]}" do echo $separator | tee -a "$logfile"_this_run.log echo Working on: "$web_page_name" from "${web_pages[$web_page_name]}". | tee -a "$logfile"_this_run.log # \' # turn tracing on with set -x # set -x if [ -d "$svn_directory/$web_page_name/" ]; then cd "$svn_directory/$web_page_name" # just echo $language_code.lang or *.php file line if they are updated svn up | grep -E "$language_code.lang|en.lang|[\.]php" | tee -a "$logfile"_this_run.log # echo -n "" # debug else cd "$svn_directory/" # just echo $language_code.lang or *.php file line if they are updated svn co $svn_method${web_pages[$web_page_name]} $web_page_name | grep -E "$language_code.lang|en.lang|[\.]php" | tee -a "$logfile"_this_run.log echo -n "" | tee -a "$logfile"_this_run.log cd "$svn_directory/$web_page_name" fi echo "" | tee -a "$logfile"_this_run.log done #copying the english files and $language_code.lang files for editing in working directory if required if [ $copying_wp -eq 1 ]; then echo $separator | tee -a "$logfile"_this_run.log echo "Web files will be copied (updated) into working translations directory." cd "$svn_directory" if [ ! -d "$working_translations_directory/web_pages_lang/en/" ]; then mkdir -vp "$working_translations_directory/web_pages_lang/en/" | tee -a "$logfile"_this_run.log fi cp $copy_options ./web_pages_lang/en/* "$working_translations_directory/web_pages_lang/en/" | tee -a "$logfile"_this_run.log if [ ! -d "$working_translations_directory/web_pages_lang/$language_code/" ]; then mkdir -vp "$working_translations_directory/web_pages_lang/$language_code/" | tee -a "$logfile"_this_run.log fi cp $copy_options ./web_pages_lang/$language_code/* "$working_translations_directory/web_pages_lang/$language_code/" | tee -a "$logfile"_this_run.log if [ ! -d "$working_translations_directory/web_page_navigation/" ]; then mkdir -vp "$working_translations_directory/web_page_navigation/" | tee -a "$logfile"_this_run.log fi cp $copy_options ./web_page_navigation/en.lang "$working_translations_directory/web_page_navigation/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_navigation/$language_code.lang "$working_translations_directory/web_page_navigation/" | tee -a "$logfile"_this_run.log fi # turn tracing off with set +x # set +x if [ -d "$svn_directory/web_page_navigation/" ]; then if [ -d "$svn_directory/web_page_navigation_2/" ]; then diff -rq "$svn_directory/web_page_navigation" "$svn_directory/web_page_navigation_2" | grep -E ".lang" | tee -a "$logfile"_this_run.log else echo "Both navigation directories ($svn_directory/web_page_navigation and $svn_directory/web_page_navigation_2) are not present. Comparing is not possible." | tee -a "$logfile"_this_run.log fi else echo "Both navigation directories ($svn_directory/web_page_navigation and $svn_directory/web_page_navigation_2) are not present. Comparing is not possible." | tee -a "$logfile"_this_run.log fi echo "" | tee -a "$logfile"_this_run.log if [ $searching_for_new_pot_files_in_svn -eq 1 ]; then echo $separator | tee -a "$logfile"_this_run.log echo "Searching for new *.pot files in svn." | tee -a "$logfile"_this_run.log if [ -f "$log_directory"/new_svn_list_of_pot_files ]; then mv "$log_directory"/new_svn_list_of_pot_files "$log_directory"/old_svn_list_of_pot_files # -f fi svn list -R svn://svn.mageia.org/svn/soft/ > "$log_directory"/svn_list cat "$log_directory"/svn_list | grep [\.]pot > "$log_directory"/new_svn_list_of_pot_files # svn list -R svn://svn.mageia.org/svn/soft/ | grep [\.]pot > new_svn_list_of_pot_files if [ -f "$log_directory"/old_svn_list_of_pot_files ]; then diff new_svn_list_of_pot_files old_svn_list_of_pot_files | tee -a "$logfile"_this_run.log if [ ${PIPESTATUS[0]} -eq 0 ]; then # this reads exit status of first command in pipe echo "No new *.pot files found." | tee -a "$logfile"_this_run.log fi fi echo "" | tee -a "$logfile"_this_run.log fi # append this_run_log to full_log cat "$logfile"_this_run.log >> "$logfile"_full.log echo "" | tee -a "$logfile".log echo $separator | tee -a "$logfile".log if [ -f "$logfile"_previous_run.log ]; then # show only differences and log them echo "Differences from last run:" | tee -a "$logfile".log diff "$logfile"_this_run.log "$logfile"_previous_run.log | tee -a "$logfile".log fi # if you use this script by click it in GUI uncomment the next line #read -p "Press any key to continue... " -n1 -s # restore saved_dir cd "$saved_dir" pwd