From e620e2a2b6e46f183b8848f953bd3d59ff831966 Mon Sep 17 00:00:00 2001 From: Antenore Gatta Date: Tue, 29 Jan 2019 15:24:05 +0100 Subject: Update translations script fixes --- scripts/update-translations.sh | 125 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 114 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/update-translations.sh b/scripts/update-translations.sh index ba7b67b28..c237139f6 100755 --- a/scripts/update-translations.sh +++ b/scripts/update-translations.sh @@ -13,20 +13,123 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" REMMINATOP="$(dirname "$SCRIPTPATH")" -GIT_TAG="$(git describe --abbrev=0 "${SCRIPTPATH}")" -if [ -n "${GIT_TAG-unset}" ]; then - echo "GIT_TAG is either empty or not set. Probably you are not in a git repository" +#=============================================================================== +# FUNCTION DEFINITIONS +#=============================================================================== + +rem_varhasvalue () { + if [[ -n ${!1:-} ]]; then + return 0 + fi + return 1 + +} # ---------- end of function rem_varhasvalue ---------- + +rem_varisdefined () { + typeset -p ${1:-} >/dev/null 2>&1 # Not portable, bash specific +} # ---------- end of function rem_varisdefined ---------- + +rem_log () { + local _cmnhead="${HOSTNAME:=$(hostname)}" + local _header="" + local _message="$*" + #local _stdout="" + local _msgdate="" + case "$1" in + CRITICAL) + _header="CRITICAL" + shift + _message="$*" + ;; + ERROR) + _header="ERROR" + shift + _message="$*" + ;; + WARNING) + _header="WARNING" + shift + _message="$*" + ;; + DEBUG) + _header="DEBUG" + shift + _message="$*" + ;; + INFO) + # We can add color support adding colors in the beginning + # GREEN="\033[0;32m" + # RESET="\033[0m" + # _reset=${RESET:-'\033[0m'} + # _color=${_reset} + #_color=${GREEN} + _header="INFO" + shift + _message="$*" + ;; + *) + _header="INFO" + _message="$*" + ;; + esac + if ! rem_varisdefined DFORMAT ; then + local _dateformat='%d/%m/%y %H:%M:%S' + else + local _dateformat=${DFORMAT:-} + fi + _msgdate="$(date +"$_dateformat")" + + # printf "%s%s - [%s] - %s - %s%s\n" "$_color" "$_header" "$_msgdate" "${_cmnhead}" "$_message" "$_reset" + printf "%s - [%s] - %s - %s\n" "$_header" "$_msgdate" "${_cmnhead}" "$_message" + +} # ---------- end of function rem_log ---------- +#------------------------------------------------------------------------------- +# rem_which a poorman which function +# Return 0 un success or 1 in case of failure +rem_which () { + local _tool=() + local _ret= + for _tool in "$@" ; do + if type "$_tool" >/dev/null 2>&1 ; then + _ret=0 + else + _ret=1 + fi + case $_ret in + 0) + rem_log INFO "$_tool found" + ;; + 83) + rem_log ERROR "$_tool not found" + ;; + esac + done + unset _tool + return "$_ret" +} # ---------- end of function rem_which ---------- + +if ! rem_which "xgettext" "msgmerge" "git" "diff" ; then + rem_log ERROR "Some tools have not been found" exit 1 fi cd "$REMMINATOP" || exit 1 +GIT_TAG="$(git describe --abbrev=0 )" +rem_log INFO "GIT_TAG is set to $GIT_TAG" + +if ! rem_varhasvalue GIT_TAG ; then + rem_log ERROR "GIT_TAG is either empty or not set. Probably you are not in a git repository" + exit 1 +fi + + if ! find src plugins -name "*\.c" -o -name "*\.h" | sed 's/^.\///' >| po/POTFILES.in ; then - exit 1 + exit 1 fi if ! find data -name "*.glade" | sed 's/^.\///' >> po/POTFILES.in ; then - exit 1 + exit 1 fi xgettext --from-code=UTF-8 \ @@ -50,7 +153,7 @@ cd "$REMMINATOP"/po || exit 1 sed -i -e 's/charset=CHARSET/charset=UTF-8/g' remmina.temp.pot if diff -qI "POT-Creation-Date" remmina.temp.pot remmina.pot ; then - echo "No new strings to be translated" + rem_log INFO "No new strings to be translated" rm remmina.temp.pot exit 0 fi @@ -58,12 +161,12 @@ fi mv remmina.temp.pot remmina.pot for i in *.po; do - msgmerge -N --backup=off --update "$i" remmina.pot + msgmerge -N --backup=off --update "$i" remmina.pot done for i in "$REMMINATOP"/po/*.po ; do - TMPF=/tmp/f$$.txt - sed '/^#~/d' "$i" > "$TMPF" - awk 'BEGIN{bl=0}/^$/{bl++;if(bl==1)print;else next}/^..*$/{bl=0;print}' $TMPF >| "$i" - rm $TMPF + TMPF=/tmp/f$$.txt + sed '/^#~/d' "$i" > "$TMPF" + awk 'BEGIN{bl=0}/^$/{bl++;if(bl==1)print;else next}/^..*$/{bl=0;print}' $TMPF >| "$i" + rm $TMPF done -- cgit v1.2.3