#!/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. # # Filip Komar, 2012 # Remco Rijnders, 2012 # # Please see SVN for a list of changes to this script. # # # Features: # -it's very configurable # -it logs all important actions # -it operates on list of "translation projects" in svn (including web pages) # -svn checkout or update as needed on every single project # -verbose checking for fuzzy and untranslated strings or just statistics (numbers of translated, fuzzy and untranslated strings) if required # -checking the syntax of po file from svn if required # -checking the syntax of pot file from svn if required # -copying the *.pot file, *.po file and web page files for editing in working directory if required # -testing for differences of *.po file from working copy if required # -testing for differences of *.pot file from working copy if required # -searching for new *.pot files in svn # TODO: # implement --password ARG to simplify svn authentication if used # simplify web copying part # more tests if target folder exist # # How to svn co single file (file.pot): # svn checkout $url_of_big_dir $target_dir --depth=empty # svn up $target_dir/$file_you_want # testing web pages checkout # better documentation # if [ -f ~/.mageia-i18n-settings ]; then source ~/.mageia-i18n-settings else cat > ~/.mageia-i18n-settings << "EOF" # Please change the below values to match your needs: language_code=xx user=svnusername_if_you_have_one # Where to put the svn files and your working directory, # please make sure those folders exist. svn_folder="/home/user/Mageia/i18n/svn_anonymous" working_translations_folder="/home/user/Mageia/i18n/translations" # choose svn method (user or anonymous) #svn_method="svn+ssh://$user@" svn_method="svn://" # The following lines can be changed if you desire, but this is # not needed to properly use this script. # choose quiet mode or normal #quiet_mode="-q" quiet_mode="" # set checking syntax of po files with 1 check_po_syntax=1 # set checking syntax of pot files with 1 check_pot_syntax=0 # set checking of fuzzy and untranslated strings with 1 check_fuzzy_and_untranslated=0 # set copying of po files with 1 copying_po=1 # set copying of web page files with 1 copying_wp=1 # set copying options (-i: interactive, -v: verbose, -u: update, -r: recursive) copy_options="-ivur" # choose log filename log_filename="updated_translations_in_svn" log_folder="$svn_folder" logfile="$svn_folder/$log_filename" # switch of logging by uncommenting following line #logfile="/dev/null" # set debug with 1 debug=0 # set searching for new *.pot files in svn with 1 searching_for_new_pot_files_in_svn=0 EOF echo "This script has not been configured yet for your language. A template" echo "configuration file has been made in .mageia-i18n-settings in your" echo "home directory. Please edit this file according to your needs before" echo "running this script again" echo exit fi # if you do have svn commit access, change the protocol from svn:// to svn+ssh://USERNAME@ in the projects array for easier committing... declare -A projects declare -A web_pages projects[control-center]="svn.mageia.org/svn/soft/control-center/trunk/po/" if [ ! $debug -eq 1 ]; then projects[desktop-common-data]="svn.mageia.org/svn/soft/desktop-common-data/trunk/po/" projects[drak3d]="svn.mageia.org/svn/soft/drak3d/trunk/po/" projects[drakguard]="svn.mageia.org/svn/soft/drakguard/trunk/po/" projects[draklive-install]="svn.mageia.org/svn/soft/draklive-install/trunk/po/" projects[drakmenustyle]="svn.mageia.org/svn/soft/drakmenustyle/trunk/po/" projects[drakpxelinux]="svn.mageia.org/svn/soft/drakpxelinux/trunk/po/" projects[drakwizard]="svn.mageia.org/svn/soft/drakwizard/trunk/po/" projects[drakx-kbd-mouse-x11]="svn.mageia.org/svn/soft/drakx-kbd-mouse-x11/trunk/po/" projects[drakx-net]="svn.mageia.org/svn/soft/drakx-net/trunk/po/" projects[drakx_help]="svn.mageia.org/svn/soft/drakx/trunk/perl-install/install/help/po/" # new projects[drakx_install]="svn.mageia.org/svn/soft/drakx/trunk/perl-install/install/share/po/" projects[drakx_share]="svn.mageia.org/svn/soft/drakx/trunk/perl-install/share/po/" projects[drakx_standalone]="svn.mageia.org/svn/soft/drakx/trunk/perl-install/standalone/po/" # projects[epoll]="forge.ipsl.jussieu.fr/epoll/svn/" projects[identity]="svn.mageia.org/svn/soft/identity/CatDap/trunk/lib/CatDap/I18N/" projects[indexhtml_about]="svn.mageia.org/svn/soft/indexhtml/trunk/about/po/" projects[indexhtml]="svn.mageia.org/svn/soft/indexhtml/trunk/po/" projects[kde4-splash-mga]="svn.mageia.org/svn/soft/kde4-splash-mga/trunk/po/" # not needed after finished translation mageia-kde4-config/trunk/kde4-profiles/Default/share/apps/plasma/layout-templates/org.mageia.plasma-desktop.classicPanel/metadata.desktop # not needed after finished translation mageia-kde4-config/trunk/kde4-profiles/Default/share/apps/plasma/layout-templates/org.mageia.plasma-desktop.defaultPanel/metadata.desktop projects[mageia-gfxboot-theme_help-boot]="svn.mageia.org/svn/soft/theme/mageia-gfxboot-theme/trunk/help-boot/" # new projects[mageia-gfxboot-theme_help-install]="svn.mageia.org/svn/soft/theme/mageia-gfxboot-theme/trunk/help-install/" # new projects[mageia-gfxboot-theme]="svn.mageia.org/svn/soft/theme/mageia-gfxboot-theme/trunk/po/" projects[mageia-kde-translation]="svn.mageia.org/svn/soft/mageia-kde-translation/trunk/po/" projects[mgaonline]="svn.mageia.org/svn/soft/mgaonline/trunk/po/" # new projects[rpmdrake]="svn.mageia.org/svn/soft/rpmdrake/trunk/po/" projects[system-config-printer]="svn.mageia.org/svn/soft/system-config-printer/trunk/po/" projects[transfugdrake]="svn.mageia.org/svn/soft/transfugdrake/trunk/po/" projects[urpmi]="svn.mageia.org/svn/soft/rpm/urpmi/trunk/po/" # is this alive: usbdumper/trunk/po/liveusb-creator.pot projects[userdrake2]="svn.mageia.org/svn/soft/userdrake2/trunk/po/" # BRANCH 2: projects[control-center_mga2]="svn.mageia.org/svn/soft/control-center/branches/2/po/" #2? projects[desktop-common-data_mga2]="svn.mageia.org/soft/desktop-common-data/tags/1:2-4/po/" # N/A projects[drak3d_mga2]="svn.mageia.org/svn/soft/drak3d/branches/2/po/" # N/A projects[drakguard_mga2]="svn.mageia.org/svn/soft/drakguard/branches/2/po/" projects[draklive-install_mga2]="svn.mageia.org/svn/soft/draklive-install/branches/2/po/" # N/A projects[drakmenustyle_mga2]="svn.mageia.org/svn/soft/drakmenustyle/branches/2/po/" # N/A projects[drakpxelinux_mga2]="svn.mageia.org/svn/soft/drakpxelinux/branches/2/po/" # N/A projects[drakwizard_mga2]="svn.mageia.org/svn/soft/drakwizard/branches/2/po/" # N/A projects[drakx-kbd-mouse-x11_mga2]="svn.mageia.org/svn/soft/drakx-kbd-mouse-x11/branches/2/po/" projects[drakx-net_mga2]="svn.mageia.org/svn/soft/drakx-net/branches/2/po/" projects[drakx_help_mga2]="svn.mageia.org/svn/soft/drakx/branches/2/perl-install/install/help/po/" projects[drakx_install_mga2]="svn.mageia.org/svn/soft/drakx/branches/2/perl-install/install/share/po/" projects[drakx_share_mga2]="svn.mageia.org/svn/soft/drakx/branches/2/perl-install/share/po/" projects[drakx_standalone_mga2]="svn.mageia.org/svn/soft/drakx/branches/2/perl-install/standalone/po/" #? projects[identity_mga2]="svn.mageia.org/svn/soft/identity/CatDap/branches/live/lib/CatDap/I18N/" # N/A projects[indexhtml_mga2]="svn.mageia.org/svn/soft/indexhtml/branches/2/po/" # N/A projects[kde4-splash-mga_mga2]="svn.mageia.org/svn/soft/kde4-splash-mga/branches/2/po/" projects[mageia-gfxboot-theme_help-boot_mga2]="svn.mageia.org/svn/soft/theme/mageia-gfxboot-theme/branches/2/help-boot/" # new projects[mageia-gfxboot-theme_help-install_mga2]="svn.mageia.org/svn/soft/theme/mageia-gfxboot-theme/branches/2/help-install/" # new projects[mageia-gfxboot-theme_mga2]="svn.mageia.org/svn/soft/theme/mageia-gfxboot-theme/branches/2/po/" # mageia-kde4-config/branches/2/kde4-profiles/Default/share/apps/plasma/layout-templates/org.mageia.plasma-desktop.classicPanel/metadata.desktop # mageia-kde4-config/branches/2/kde4-profiles/Default/share/apps/plasma/layout-templates/org.mageia.plasma-desktop.defaultPanel/metadata.desktop # N/A projects[mageia-kde-translation_mga2]="svn.mageia.org/svn/soft/mageia-kde-translation/branches/2/po/" # N/A projects[rpmdrake_mga2]="svn.mageia.org/svn/soft/rpmdrake/branches/2/po/" # N/A projects[system-config-printer_mga2]="svn.mageia.org/svn/soft/system-config-printer/branches/2/po/" # N/A projects[transfugdrake_mga2]="svn.mageia.org/svn/soft/transfugdrake/branches/2/po/" projects[urpmi_mga2]="svn.mageia.org/svn/soft/rpm/urpmi/branches/2/po/" # N/A projects[userdrake2_mga2]="svn.mageia.org/svn/soft/userdrake2/branches/2/po/" # BRANCH 1: # not "cleaned" yet # control-center/branches/1/po/drakconf.pot # desktop-common-data/tags/1:2-4/po/desktop-common-data.pot # drak3d/branches/1/po/drak3d.pot # drakguard/branches/1/po/drakguard.pot # draklive-install/branches/1/po/draklive-install.pot # drakmenustyle/branches/1/po/drakmenustyle.pot # drakpxelinux/branches/1/po/drakpxelinux.pot # drakwizard/branches/1/po/drakwizard.pot # drakx/branches/1/perl-install/install/help/po/DrakX-help.pot # drakx/branches/1/perl-install/install/share/po/DrakX.pot # drakx/branches/1/perl-install/share/po/libDrakX.pot # drakx/branches/1/perl-install/standalone/po/libDrakX-standalone.pot # drakx-kbd-mouse-x11/branches/1/po/drakx-kbd-mouse-x11.pot # drakx-net/branches/1/po/drakx-net.pot # indexhtml/branches/1/about/po/index.pot # indexhtml/branches/1/po/indexhtml.pot # kde4-splash-mga/branches/1/po/kde4-splash-mga.pot # mageia-kde-translation/branches/1/po/mageia-kde-translation.pot # mgaonline/branches/1/po/mdkonline.pot # rpm/urpmi/branches/1/po/urpmi.pot # rpmdrake/branches/1/po/rpmdrake.pot # system-config-printer/branches/1/po/system-config-printer.pot # theme/mageia-gfxboot-theme/branches/1/po/bootloader.pot # transfugdrake/branches/1/po/transfugdrake.pot # userdrake2/branches/1/po/userdrake.pot # userdrake2/tags/1.13.3/po/userdrake.pot # WEB PAGES: web_pages[web_page_navigation]="svn.mageia.org/svn/web/www/trunk/_nav/langs/" web_pages[web_page_navigation_2]="svn.mageia.org/svn/web/nav/langs/" web_pages[web_page_english]="svn.mageia.org/svn/web/www/trunk/en/" web_pages[web_page_my_language]="svn.mageia.org/svn/web/www/trunk/$language_code/" web_pages[web_pages_lang]="svn.mageia.org/svn/web/www/trunk/langs/" fi # save pwd to saved_dir saved_dir=$(pwd) mv "$logfile"_this_run.log "$logfile"_previous_run.log separator="-----------------------------------------------------" echo "" | tee -a "$logfile"_this_run.log echo "" | tee -a "$logfile"_this_run.log date | tee -a "$logfile"_this_run.log 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 # Check out / update project files 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 if [ -d $project_name ]; then cd "$svn_folder/$project_name" # svn up $quiet_mode $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 # svn up $project_name | tee -a "$logfile"_this_run.log #2 # echo -n "" # debug else cd "$svn_folder" # svn co -q ${projects[$project_name]} $project_name # svn co $quiet_mode $svn_method${projects[$project_name]} $project_name # 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_folder/$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_folder/$project_name/" ]; then mkdir -v "$working_translations_folder/$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_folder/$project_name/$language_code.po" ]; then diff -q $language_code.po "$working_translations_folder/$project_name/$language_code.po" | tee -a "$logfile"_this_run.log fi cp $copy_options $language_code.po "$working_translations_folder/$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_folder/$project_name/"*.pot ]; then diff -q *.pot "$working_translations_folder/$project_name/"*.pot | tee -a "$logfile"_this_run.log fi cp $copy_options *.pot "$working_translations_folder/$project_name/" | tee -a "$logfile"_this_run.log # set -x # turn tracing on with set -x cd "$working_translations_folder/$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_folder/$project_name/." fi cd "$svn_folder/" 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_folder/$web_page_name/" ]; then cd "$svn_folder/$web_page_name" # svn up $quiet_mode $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_folder/" # svn co -q ${web_pages[$web_page_name]} $web_page_name # svn co $quiet_mode $svn_method${web_pages[$web_page_name]} $web_page_name # 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_folder/$web_page_name" fi echo "" | tee -a "$logfile"_this_run.log done #copying the *.php file and $language_code.lang for editing in upper directory if required if [ $copying_wp -eq 1 ]; then echo $separator | tee -a "$logfile"_this_run.log # echo about copying the *.php file and $language_code.lang for editing in upper directory if required echo "Web files will be copied (updated) into working translations directory." cd "$svn_folder" cp $copy_options ./web_page_english/index.php "$working_translations_folder/web_page_english/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_english/2/download_index.php "$working_translations_folder/web_page_english/2/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_english/2/index.php "$working_translations_folder/web_page_english/2/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_english/2/nav.php "$working_translations_folder/web_page_english/2/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_english/about/index.php "$working_translations_folder/web_page_english/about/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_english/for-pc/index.php "$working_translations_folder/web_page_english/for-pc/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_english/for-server/index.php "$working_translations_folder/web_page_english/for-server/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_english/map/index.php "$working_translations_folder/web_page_english/map/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_english/support/index.php "$working_translations_folder/web_page_english/support/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_my_language/about/2010-sept-announcement.html "$working_translations_folder/web_page_my_language/about/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_pages_lang/en/* "$working_translations_folder/web_pages_lang/en/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_pages_lang/$language_code/* "$working_translations_folder/web_pages_lang/$language_code/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_navigation/fr.lang "$working_translations_folder/web_page_navigation/" | tee -a "$logfile"_this_run.log cp $copy_options ./web_page_navigation/$language_code.lang "$working_translations_folder/web_page_navigation/" | tee -a "$logfile"_this_run.log fi # turn tracing off with set +x # set +x diff -rq "$svn_folder/web_page_navigation" "$svn_folder/web_page_navigation_2" | grep -E ".lang" | 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 mv "$log_folder"/new_svn_list_of_pot_files "$log_folder"/old_svn_list_of_pot_files # -f svn list -R svn://svn.mageia.org/svn/soft/ > "$log_folder"/svn_list cat "$log_folder"/svn_list | grep [\.]pot > "$log_folder"/new_svn_list_of_pot_files # svn list -R svn://svn.mageia.org/svn/soft/ | grep [\.]pot > new_svn_list_of_pot_files 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 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 echo "Differences from last run:" | tee -a "$logfile".log # show only differences and log them diff "$logfile"_this_run.log "$logfile"_previous_run.log | tee -a "$logfile".log # restore saved_dir cd "$saved_dir" pwd