#!/bin/sh# $Id: sync_lang.sh,v 2.22 2005/12/07 23:03:46 nijel Exp $### Shell script that synchronises all translations in phpMyAdmin### Any parameters (except --iconv/--recode) will be passed to grep to filter# processed translation, for example: './sync_lang.sh czech' will process only# czech translation, './sync_lang.sh -e czech -e english' will process czech# and english translations.### Written by Michal Cihar <nijel at users.sourceforge.net>### Changes:# 2005-12-08# * less verbose output to allow quick overview# 2005-11-29# * hack for multibyte chars, so that \'; at the end will not fool PHP# 2004-09-22# * default to iconv, as it doesn't break things as recode does# 2004-09-03# * hack for hebrew# 2003-11-18# * switch php3 -> php# 2003-04-14# * convert only files that are needed to convert (checks mtime), --force to# avoid this checking# * get charset from filename when reading from file failed# * report failed translations at the end# 2002-09-18# * now accepts parameters --iconv/--recode for specifying which convertor# to use# 2002-08-13# * support for synchronisation only for selected language(s)# 2002-07-18# * can exclude some languages from conversion# 2002-07-17# * support for multiple convertors (recode added)##### convertor setup### CONVERTOR_PARAMS is used for printf and it also receives two params: source# and target charset#case "$1" in--iconv)echo Using iconv on user requestCONVERTOR=iconv# the space on following is REQUIREDCONVERTOR_PARAMS=" -f %s -t %s"shift;;--recode)echo Using recode on user requestecho '(please use iconv for arabic)'CONVERTOR=recodeCONVERTOR_PARAMS=" -f %s..%s"shift;;*)echo Using iconv as default, force with --iconv/--recodeCONVERTOR=iconv# the space on following is REQUIREDCONVERTOR_PARAMS=" -f %s -t %s";;esacif [ "$1" = "--force" ] ; thenFORCE=1shiftelseFORCE=0fi### names of translations to process### Here should be listed all translations for which conversion should be done.# The name is filename without inc.php.#BASE_TRANSLATIONS="afrikaans-iso-8859-1albanian-iso-8859-1arabic-windows-1256azerbaijani-iso-8859-9basque-iso-8859-1belarusian_cyrillic-windows-1251belarusian_latin-utf-8bosnian-windows-1250brazilian_portuguese-iso-8859-1bulgarian-utf-8catalan-iso-8859-1chinese_traditional-utf-8chinese_simplified-gb2312croatian-iso-8859-2czech-utf-8danish-iso-8859-1dutch-iso-8859-1english-iso-8859-1estonian-iso-8859-1finnish-iso-8859-1french-iso-8859-1galician-iso-8859-1german-utf-8greek-iso-8859-7hebrew-iso-8859-8-ihungarian-iso-8859-2indonesian-iso-8859-1italian-iso-8859-1japanese-utf-8korean-euc-krlatvian-windows-1257lithuanian-windows-1257malay-iso-8859-1norwegian-iso-8859-1persian-windows-1256polish-iso-8859-2portuguese-iso-8859-1romanian-iso-8859-1russian-windows-1251serbian_cyrillic-windows-1251serbian_latin-windows-1250slovenian-iso-8859-2slovak-iso-8859-2spanish-iso-8859-1swedish-iso-8859-1tatarish-iso-8859-9thai-tis-620turkish-utf-8ukrainian-windows-1251"### which translations should not be translated to utf-8### List here any translation that should not be converted to utf-8. The name is# same as above.#IGNORE_UTF=""### which translations should not be automatically generated### List here any translation should not be automatically generated from base# translation for that language (usually for those which are not correctly# supported by convertor).#IGNORE_TRANSLATIONS="russian-cp-866"### end of configuration, you hopefully won't need to edit anything bellow##TEMPFILE=`mktemp /tmp/pma-sync-lang.XXXXXX`cleanup() {rm -f $TEMPFILE}trap cleanup INT ABRT TERMFAILED=""echo "-------------------------------------------------------------------"# go through all file we should processfor base in $BASE_TRANSLATIONS ; doif [ "$#" -gt 0 ] ; thenif ( echo $base | grep -q "$@" ) ; thentrueelsecontinuefifi# grep language from basenamelang=$(echo $base|sed 's%-.*%%')# which files will we create from current?create_files=$(ls --color=none -1 $lang*.inc.php|grep -v $base.inc.php)for ignore in $IGNORE_TRANSLATIONS ; docreate_files=$(echo "$create_files" | grep -v $ignore)done# charset of source filesrc_charset=$(grep '\$charset' $base.inc.php | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")replace_charset=$src_charset# special case for hebrewif [ $src_charset = 'iso-8859-8-i' ] ; thensrc_charset=iso-8859-8fiecho -n "$base [charset $src_charset]"# do we already have utf-8 translation?if [ $src_charset = 'utf-8' ] ; thenis_utf=yeselseis_utf=nofi# at first update existing translationsfor file in $create_files ; do# charset of destination file# grepping from file causes problems when it is empty...charset=$(grep '\$charset' $file | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")if [ -z "$charset" ] ; thencharset=$(echo $file | sed -e 's/^[^-]*-//' -e 's/\.inc\.php\?$//')fiif [ $charset = 'utf-8' ] ; thenis_utf=yesfi# check whether we need to update translationif [ ! "$base.inc.php" -nt "$file" -a "$FORCE" -eq 0 -a -s "$file" ] ; thenecho -n " ($file:ok)"continuefiecho -n " ($file:to $charset:"if [ $charset = 'utf-8' ] ; then# if we convert to utf-8, we should add allow_recodingis_utf=yes$CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed -e "s/$replace_charset/$charset/" -e '/\$charset/a\$allow_recoding = TRUE;' > $TEMPFILEelif [ $src_charset = 'utf-8' ] ; thenis_utf=yes# if we convert from utf-8, we should remove allow_recoding$CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| grep -v allow_recoding | sed "s/$replace_charset/$charset/" > $TEMPFILEelse# just convert$CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed "s/$replace_charset/$charset/" > $TEMPFILEfiif [ -s $TEMPFILE ] ; thensed "s/\\\\';[[:space:]]*$/\\\\\\\\';/" $TEMPFILE > $fileecho -n 'done)'elseFAILED="$FAILED $file"echo -n 'FAILED)'fidone# now check whether we found utf-8 translationif [ $is_utf = no ] ; thenif ( echo $IGNORE_UTF | grep -q $base ) ; then# utf-8 should not be createdtrueelse# we should create utf-8 translationcharset=utf-8file=$lang-$charset.inc.phpecho -n " [$file:$charset:"$CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed -e "s/$replace_charset/$charset/" -e '/\$charset/a\$allow_recoding = TRUE;' > $TEMPFILEif [ -s $TEMPFILE ] ; thencat $TEMPFILE > $fileecho -n 'done)'elseFAILED="$FAILED $file"echo -n 'FAILED)'fififiechodoneecho "-------------------------------------------------------------------"if [ -z "$FAILED" ] ; thenecho "Everything seems to went okay"elseecho "!!!SOME CONVERSION FAILED!!!"echo "Following file were NOT updated:"echoecho "$FAILED"echoecho "!!!SOME CONVERSION FAILED!!!"ficleanup