#!/bin/bash # Filip Komar, 2014 - 2017 # @license GPL v2 # @author Filip (rebuilding a gettext dictionaries) # @copyright 2014 - 2017 # inspired by check_for_translation_work.sh error=0 declare -A resources declare -A errors if [ -f ./tools/web_projects.dat ]; then source ./tools/web_projects.dat else echo "Critical error!!! It was not possible to load web projects database! Please report that on atelier mailing list." exit 2 fi rpm --quiet -q gettext python3-polib if [ $? -eq 1 ]; then echo "Warning!!! Some gettext components are missing. Please install them as root: urpmi gettext python3-polib" exit 1 fi for resource in "${!resources[@]}" do difference= if [ "$resource" = "mognase" ]; then # is it about navigation? path_and_filename=./_nav/langs/en else path_and_filename=./langs/en/$resource fi if [ -f "$path_and_filename.pot" ]; then # do a temporary copy cp $path_and_filename.pot $path_and_filename.copy fi php_source=${resources[$resource]} php tools/extract2gettext.php "$php_source" $resource true php_error_level=$? # catch php error level errors[$php_source]=$php_error_level # if there are no real differences restore copy if [ -f "$path_and_filename.pot" ] && [ -f "$path_and_filename.copy" ]; then diff --ignore-matching-lines='^"POT-Creation-Date:' --ignore-matching-lines='^# Copyright (C) 2014 - ' --ignore-matching-lines='^#: "/web/' $path_and_filename.pot $path_and_filename.copy > /dev/null if [ $? -eq 0 ]; then cp $path_and_filename.copy $path_and_filename.pot fi fi if [ -f "$path_and_filename.pot" ]; then # msgmerge check of generated pot file msgmerge --quiet --no-wrap $path_and_filename.pot $path_and_filename.pot --output-file=$path_and_filename.tmp msgmerge_error_level=$? # catch msgmerge error level if [ $msgmerge_error_level -gt 0 ]; then # on failure stop the process for this resource errors[$php_source]=$msgmerge_error_level rm $path_and_filename.tmp fi if [ -f "$path_and_filename.copy" ] && [ -f "$path_and_filename.tmp" ]; then diff --ignore-matching-lines='^"POT-Creation-Date:' --ignore-matching-lines='^# Copyright (C) 2014 - ' --ignore-matching-lines='^#: "/web/' $path_and_filename.tmp $path_and_filename.copy if [ $? -eq 1 ]; then # there are differences errors[$php_source]=0 mv $path_and_filename.tmp $path_and_filename.pot rm $path_and_filename.copy echo Changes in $path_and_filename.pot are listed above else # Cleanup as there are no changes in $resource errors[$php_source]=5 rm $path_and_filename.tmp mv $path_and_filename.copy $path_and_filename.pot difference=none fi else # diff not possible if [ -f "$path_and_filename.tmp" ]; then mv $path_and_filename.tmp $path_and_filename.pot if [ -f "$path_and_filename.copy" ]; then rm $path_and_filename.copy fi else rm $path_and_filename.pot if [ -f "$path_and_filename.copy" ]; then mv $path_and_filename.copy $path_and_filename.pot difference=none fi fi fi if [ "$resource" = "mognase" ]; then # is it about navigation? # create po files if needed from lang files if available if [ -f ./_nav/langs/en.lang ]; then python tools/translated_converter.py --filename ./_nav/langs/ python_error_level=$? # catch python error level if [ $python_error_level -gt 0 ]; then errors[$resource]=50 fi if [ -f ./_nav/langs/en.po ]; then rm ./_nav/langs/en.po fi fi for tr_file in ./_nav/langs/*.po do if [ -z $difference ]; then # update po file if needed # msgfmt --statistics --verbose -c $tr_file -o /dev/null # usefull for debuging (msgctxt "/web/en/ or msgctxt "en/) echo merging $tr_file msgmerge --quiet --no-wrap $tr_file ./_nav/langs/en.pot --output-file=$tr_file.tmp msgmerge_error_level=$? # catch msgmerge error level if [ $msgmerge_error_level -gt 0 ]; then errors[$directory/$resource]=60 echo "$directory"/$resource.po could not be created succesfully if [ -f "$tr_file.tmp" ]; then rm $tr_file.tmp fi else mv $tr_file.tmp $tr_file # msgfmt --statistics --verbose -c $tr_file -o /dev/null # usefull for debuging (msgctxt "/web/en/ or msgctxt "en/) fi fi done else for directory in ./langs/* do # in each language directory except source if [ -d "$directory/" ] && [ $directory != ./langs/en ]; then # create po file if needed from lang file if available if [ ! -f "$directory/$resource.po" ] && [ -f "$directory/$resource.*.lang" ]; then # echo $directory # usefull for debuging of non UTF-8 files or other python errors python tools/translated_converter.py --filename $directory/$resource python_error_level=$? # catch python error level if [ $python_error_level -gt 0 ]; then errors[$directory/$resource]=50 fi fi if [ -f "$directory/$resource.po" ] && [ -z $difference ]; then # update po file if it exists # msgfmt --statistics --verbose -c $directory/$resource.po -o /dev/null # usefull for debuging (msgctxt "/web/en/ or msgctxt "en/) # merge the translations once if it's about mga version_soon_to_be_released but adjust the numbers and uncomment the code ;) # if [ "$resource" = "5" ]; then # msgcat --use-first --no-wrap $directory/5.po $directory/cauldron.po $directory/4.po > $directory/5_.po # sed -i 's/Mageia 4/Mageia 5/g' $directory/5_.po # mv $directory/5_.po $directory/5.po # fi echo merging $directory/$resource.po msgmerge --quiet --no-wrap $directory/$resource.po ./langs/en/$resource.pot --output-file=$directory/$resource.tmp msgmerge_error_level=$? # catch msgmerge error level if [ $msgmerge_error_level -gt 0 ]; then errors[$directory/$resource]=60 echo "$directory"/$resource.po could not be created succesfully if [ -f "$tr_file.tmp" ]; then rm $directory/$resource.tmp fi else mv $directory/$resource.tmp $directory/$resource.po # msgfmt --statistics --verbose -c $directory/$resource.po -o /dev/null # usefull for debuging (msgctxt "/web/en/ or msgctxt "en/) fi fi fi done fi fi done echo '' #printf "%s\n" "${errors[@]}" for error_in_source in "${!errors[@]}" do case ${errors[$error_in_source]} in 0) echo "Done lookup for _g() and _r() in $error_in_source. Gettext catalogs (pot files) rebuilded. Existing po files updated." ;; 1) echo "Unkown error!!" ;; 5) echo "There are no changes in $error_in_source." ;; 10) echo "No strings to save from $error_in_source!" ;; 20) echo "!!!! Parse error, please fix $error_in_source first !!!! See details above." ;; 30) echo "!!!! Failed to write $error_in_source !!!! See details above." ;; 50) echo "!!!! Script translated_converter.py encounter an error in $error_in_source !!!!" ;; 60) echo "$error_in_source.po could not be created succesfully!! Duplicates?" ;; esac done