www-el-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[www-el-commits] www-el GNUmakefile __make__/comp-format __make_...


From: Georgios Zarkadas
Subject: [www-el-commits] www-el GNUmakefile __make__/comp-format __make_...
Date: Tue, 05 May 2015 22:45:44 +0000

CVSROOT:        /cvsroot/www-el
Module name:    www-el
Changes by:     Georgios Zarkadas <gzarkadas>   15/05/05 22:45:44

Modified files:
        .              : GNUmakefile 
        __make__       : comp-format functions.sh 
Added files:
        __make__       : merge-templates 

Log message:
        work in progress; approaching beta status

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/www-el/GNUmakefile?cvsroot=www-el&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/www-el/__make__/comp-format?cvsroot=www-el&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/www-el/__make__/functions.sh?cvsroot=www-el&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/www-el/__make__/merge-templates?cvsroot=www-el&rev=1.1

Patches:
Index: GNUmakefile
===================================================================
RCS file: /cvsroot/www-el/www-el/GNUmakefile,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- GNUmakefile 30 Apr 2015 20:11:31 -0000      1.29
+++ GNUmakefile 5 May 2015 22:45:43 -0000       1.30
@@ -67,6 +67,12 @@
 # Note that trash does not currently accept any options.
 RM := rm --force
 
+# Adjust these variables if not using __make__ subdirectory.
+VCS-MAKEFILE := __make__/vcs.mk
+HELPFILE := __make__/help
+COMP-FORMAT := __make__/comp-format
+OBSOLETE-REMOVE := __make__/obsolete-remove
+
 ## Paths and Files
 
 # Paths to exclude from search: expands to a space separated list of 
@@ -196,7 +202,7 @@
 endif
 
 # Import vcs-related stuff here.
-include __make__/vcs.mk
+include $(VCS-MAKEFILE)
 
 # Warning message for the `publish' rule.
 pubwmsg := "Warning (%s): %s\n  does not exist; (either obsolete or \`cvs\
@@ -324,15 +330,13 @@
 # they get remerged by the official build.
 .PHONY: format
 format:
-       @echo Formatting .po files with msgcat:
-       @LC_ALL=C wc --max-line-length $(translations) \
-         | awk '$$1>80 {print $$2}' | grep -v total \
-         | xargs --max-args=1 --no-run-if-empty \
-           sh -c '$(MSGCAT) -o $$1 $$1 ; echo "  "$$1' msgcat 
+       @$(COMP-FORMAT) \
+         -C server/gnun/compendia/compendium.$(TEAM).po \
+         $(translations)
 
 # Helper target to mark changes (at word level) in fuzzy messages
 .PHONY: fuzdiff
-fuzdiff: format
+fuzdiff: #format
        @echo The fuzdiff target is not ready for production. Skipping...
 #      @for file in $(translations); do \
 #        if [ -f $(www_pot_recipy) ]; then \
@@ -359,7 +363,7 @@
 # Helper target to remove obsolete messages and store them in a catalog
 .PHONY: obremove
 obremove:
-       @__make__/obsolete-remove \
+       @$(OBSOLETE-REMOVE) \
          --store=__tools__/deleted.$(TEAM).po \
          $(translations)
 
@@ -409,4 +413,4 @@
 # Helper target to display accepted targets and parameters.
 .PHONY: help
 help:
-       @cat __make__/help
+       @cat $(HELPFILE)

Index: __make__/comp-format
===================================================================
RCS file: /cvsroot/www-el/www-el/__make__/comp-format,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- __make__/comp-format        5 May 2015 08:20:56 -0000       1.2
+++ __make__/comp-format        5 May 2015 22:45:43 -0000       1.3
@@ -60,7 +60,12 @@
 
 OPTSFOOTER='
 Compendia are applied with the same order they are provided in the command
-line; the first occurence of a message has precedence.'
+line; the first occurence of a message has precedence. Comments are changed
+also, thus you can use compendia to fix comments if your PO editor messes
+with them. 
+When using compendia, files with fuzzy translations or obsolete messages
+are skipped, because there are side effects due to the processing chain.
+Edit those files to fix them and repeat.'
 
 
 #### MAIN ####
@@ -144,7 +149,7 @@
 
         # If the processed file did not change, don't update it.
 
-        if diff --brief "${file}" "${tempfile}" >/dev/null
+        if same_files "${file}" "${tmpfile}"
         then
             rm --force "${tmpfile}"
             continue
@@ -170,8 +175,10 @@
     # (c)  msgcomm [processed] [original], to remove extraneous messages from
     # the compendia that do not exist in the original.
     # NOTE:
-    # Fuzzy translations are removed; thus we test for them and exclude files
-    # with fuzzy translations from the processing. 
+    # Fuzzy translations are cleared (because of --use-first [untranslated]);
+    # obsolete are converted to non-obsolete by msgcomm (must be a bug).
+    # Thus, we check for fuzzy/obsolete translations and skip formatting if
+    # found. 
 
     for file in "$@"
     do
@@ -180,6 +187,11 @@
             warn "Warning: '${file}' has fuzzy translations; skipping."
             continue
         fi
+        if has_obsolete_messages "${file}"
+        then
+            warn "Warning: '${file}' has obsolete messages; skipping."
+            continue
+        fi
         emptyfile=$(tempfile_or_die)
         if ! msgfilter --input="${file}" --output-file="${emptyfile}" sh -c \
           '[ "X${MSGFILTER_MSGID}" != "X" ] && sed -z 's/^.*$//' || cat'

Index: __make__/functions.sh
===================================================================
RCS file: /cvsroot/www-el/www-el/__make__/functions.sh,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- __make__/functions.sh       5 May 2015 08:20:58 -0000       1.2
+++ __make__/functions.sh       5 May 2015 22:45:43 -0000       1.3
@@ -60,6 +60,15 @@
 EMSG_FSO_UNREAD="Error: '%s' is not readable; check permissions."
 EMSG_FSO_UNWRIT="Error: '%s' is not writable; check permissions."
 
+# Warning messages
+
+WARN_FSO_MISSED="Warning: '%s' does not exist."
+WARN_FSO_NOFILE="Warning: '%s' is not a file; please use a regular file."
+WARN_FSO_UNREAD="Warning: '%s' is not readable; please check permissions."
+WARN_FSO_UNWRIT="Warning: '%s' is not writable; please check permissions."
+
+# Common options and procedures related
+
 QUIET=0
 DELAYED_MSG=''
 
@@ -89,6 +98,11 @@
     exit 0
 }
 
+# NOTE: Both the error and print families of functions use printf to allow
+# splitting passed messages to arbitrary strings and easy control of where
+# the newlines appear. It has the caveat that the % character gets special
+# treatment; beware of it when constructing messages.
+
 # Print an error message to stderr and exit with error code.
 # Args: #1={errcode|-}, #2,[#3,[...]]=message
 #
@@ -145,7 +159,12 @@
 {
     if [ ${QUIET} -eq 0 ]
     then
-        echo "$@"
+        local arg
+        for arg in "$@"
+        do
+            printf "${arg}"
+        done
+        printf "\n"
     fi
 }
 
@@ -262,8 +281,7 @@
 
 has_fuzzy_tanslations ()
 {
-    [ $# -eq 1 ] \
-      || error 7 "${EMSG_INT_ARGNUM}" \
+    [ $# -eq 1 ] || error 7 "${EMSG_INT_ARGNUM}" \
       "\nLocation: has_fuzzy_translations"
 
     msgfmt --statistics -o /dev/null "${file}" 2>&1 \
@@ -272,8 +290,7 @@
 
 has_untranslated_messages ()
 {
-    [ $# -eq 1 ] \
-      || error 7 "${EMSG_INT_ARGNUM}" \
+    [ $# -eq 1 ] || error 7 "${EMSG_INT_ARGNUM}" \
       "\nLocation: has_untranslated_messages"
 
     msgfmt --statistics -o /dev/null "${file}" 2>&1 \
@@ -282,8 +299,7 @@
 
 has_obsolete_messages ()
 {
-    [ $# -eq 1 ] \
-      || error 7 "${EMSG_INT_ARGNUM}" \
+    [ $# -eq 1 ] || error 7 "${EMSG_INT_ARGNUM}" \
       "\nLocation: has_obsolete_messages"
 
     local obs=$(msgattrib --only-obsolete "${1}" 2>/dev/null \
@@ -298,8 +314,8 @@
 #
 same_files ()
 {
-    [ $# -eq 2 ] \
-      || error 7 "${EMSG_INT_ARGNUM}" "\nLocation: same_files"
+    [ $# -eq 2 ] || error 7 "${EMSG_INT_ARGNUM}" \
+      "\nLocation: same_files"
 
     diff --brief "${1}" "${2}" >/dev/null 2>/dev/null
 }
\ No newline at end of file

Index: __make__/merge-templates
===================================================================
RCS file: __make__/merge-templates
diff -N __make__/merge-templates
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ __make__/merge-templates    5 May 2015 22:45:43 -0000       1.1
@@ -0,0 +1,304 @@
+#!/bin/sh
+
+# Merge changes from the templates to po files.
+# Copyright (C) 2012, 2015 Georgios M. Zarkadas <address@hidden>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 3 of the License, or (at your option)
+# any later version.
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the "Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA"
+
+#### Import Library ####
+
+LIBMAIN=$(dirname "$0")
+LIBMAIN="${LIBMAIN}/functions.sh"
+if [ ! -f "${LIBMAIN}" ]
+then
+    echo "Error: library does not exist or is not a file;" \
+      "check installation." >&2
+    exit 1
+fi
+if [ ! -r "${LIBMAIN}" ]
+then
+    echo "Error: library is not readable; check permissions," \
+      "installation." >&2
+    exit 1
+fi
+. "${LIBMAIN}"
+if [ $? -ne 0 ] 
+then
+    echo "Error at library sourcing; check installation." >&2
+    exit 2
+fi
+
+#### Variables ####
+
+PROGRAM='merge-templates'
+VERSION='0.1.0'
+SHORTDESC='Merge changes from the templates to po files.'
+CR_YEARS='2012, 2015'
+
+ARGSDESC='[options] FILE1 [FILE2 [...]]
+Merge changes made to their templates to translations FILE1 FILE2 ...'
+
+# always keep the 1st line empty in the strings below
+
+OPTSDESC='
+  -C, --compendium=FILE   additional library of message translations to be
+                          passed to msgmerge, may be specified more than once 
+  -l, --leaf=DIR          templates are located inside a DIR leaf subdirectory
+                          at the master repository; defaults to po/
+  -n, --noleaf            there is *no* leaf subdirectory for templates; ie
+                          the structures of master and team repositories are
+                          the same
+  -q, --quiet             suppress informative output to the basics 
+  -r, --repo=DIR          templates master repository is at DIR; if must be
+                          either relative to the base path of all arguments
+                          or an absolute path; defaults to ../www/
+  -s, --srepl=EXPR        sed s/regexp/replacement/ expression for converting
+                          translation filenames to template ones, *excluding*
+                          the extension (the .po to .pot part, which always
+                          happens); defaults to none (no conversion)
+  -t, --team=TEAM         ISO language code of the translation team, if used
+                          to convert translation filenames to templates as is
+                          the common case (.TEAM.po to .pot); defaults to
+                          none (no conversion) 
+      --help              display this help screen and exit
+      --version           output version information and exit'
+
+OPTSFOOTER='
+If the -r option is ommited, then ../www/ is used as the default templates
+repository.
+If the -l, -n options are ommited, then po/ is used as a leaf subdirectory.
+The -s and -t options are usually exclusive; either the usual convention:
+  template=name.pot, translation=name.TEAM.po
+is followed or not, in which case a sed expression must be provided. However,
+the program allows both to be used, applying first the -t option, then the -s
+one to the filename.'
+
+LEAFDIR='po/'
+MASTER_REPO='../www/'
+SEDEXPR=''
+TEAM=''
+
+#### Functions ####
+
+# Return the path of the corresponding template of the translation.
+# Args: #1=translation pathname
+#
+master_pot ()
+{
+    [ $# -eq 1 ] || error 7 "${EMSG_INT_ARGNUM}" \
+      "\nLocation: master_pot"
+
+    # If any of the variables MASTER_REPO, LEAFDIR are null, expressions
+    # will still do the right thing; no need to check here.
+ 
+    local template=$(echo "${1}" | sed \
+      -e "s_^._${MASTER_REPO}&_" \
+      -e "s_\(^.*/\)\([^/]*\$\)_\1${LEAFDIR}\2_" )
+
+    if [ "X${TEAM}" != "X" ]
+    then
+        template=$(echo "${template}" | sed "s_\.${TEAM}\.po$_.pot_" )
+    else
+        template=$(echo "${template}" | sed "s_\.po$_.pot_" )
+    fi
+
+    if [ "X${SEDEXPR}" != "X" ]
+    then
+        template=$(echo "${template}" | sed -e "${SEDEXPR}")
+    fi
+    return "${template}"
+}
+
+
+#### MAIN ####
+
+CMDLINE=$(getopt \
+  -o 'C:l:nqr:s:t:' \
+  -l 'compendium:,leaf:,noleaf,quiet,repo:.srepl:,team:' \
+  -l help,version -n "${PROGRAM}" -- "$@")
+ERRCODE=$?
+if [ ${ERRCODE} -ne 0 ]
+then
+    exit ${ERRCODE}
+fi
+eval set -- "${CMDLINE}"
+
+# process options
+
+COMPENDIA=''
+# The --leaf and --noleaf options are mutually exclusive; check it out. 
+XFLAG="00"
+
+while true
+do
+    case ${1} in
+    -C|--compendium)
+        assert_is_existent "${2}"
+        assert_is_file "${2}"
+        assert_is_readable "${2}"
+        # must escape special characters, else expansion inside
+        # the processing loop will result in error
+        COMP=$(echo "${2}" | sed 's/[][(){} &!?;]/\\&/g')
+        COMPENDIA="${COMPENDIA} --compendium=${COMP}"
+        shift 2
+        ;;
+    -l|--leaf)
+        # Allow setting --leaf='' --noleaf to pass, since it is consistent. 
+
+        if [ "X${2}" != "X" ]
+        then
+            LEAFDIR=$(echo "${2}" | sed 's_[^/]$_&/_')
+            XFLAG="1"$(echo "${XFLAG}" | cut --characters=2)
+        else
+            LEAFDIR=''
+        fi
+        shift 2
+        ;;
+    -n|--noleaf)
+        XFLAG=$(echo "${XFLAG}" | cut --characters=1)"1"
+        LEAFDIR=''
+        shift
+        ;;
+    -q|--quiet)
+        QUIET=1
+        shift
+        ;;
+    -r|--repo)
+        # Allow the empty string (it means that templates are stored
+        # in the same tree as translations, which can be the case).
+
+        if [ "X${2}" = "X" ]
+        then
+            MASTER_REPO="./"
+        else
+            MASTER_REPO=$(echo "${2}" | sed 's_[^/]$_&/_')
+        fi
+        assert_is_existent "${MASTER_REPO}"
+        assert_is_directory "${MASTER_REPO}"
+        assert_is_readable "${MASTER_REPO}"
+        shift 2
+        ;;
+    -s|--srepl)
+        SEDEXPR="${2}"
+        # TODO: make basic sanity checks
+        shift 2
+        ;;
+    -t|--team)
+        TEAM="${2}"
+        shift 2
+        ;;
+    --help)
+        show_help
+        shift
+        ;;
+    --version)
+        show_version
+        shift
+        ;;
+    --)
+        shift
+        break
+        ;;
+    *)
+        errmsg=$(printf "${EMSG_INT_OPTION}" "${1}")
+        error 5 "${errmsg}"
+        ;;
+    esac
+done
+
+# The --leaf and --noleaf options are mutually exclusive;
+# if both have been set flag the error and exit. 
+
+if [ "${XFLAG}" = "11" ]
+then
+    error 5 "Error: The --leaf and --noleaf options are mutually exclusive;" \
+      "please specify only one of them, not both."
+fi
+
+# process arguments
+
+print_msg "Merging template changes to translations..."
+
+for file in "$@"
+do
+    if [ "X${file}" = "X" ]
+    then
+        warn "Warning: empty string passed as argument."
+        continue
+    fi
+    if [ ! -e "${file}" ]
+    then
+        warn $(printf "${WARN_FSO_MISSED}" "${file}")
+        continue
+    fi
+    if [ ! -f "${file}" ]
+    then
+        warn $(printf "${WARN_FSO_NOFILE}" "${file}")
+        continue
+    fi
+    if [ ! -r "${file}" ]
+    then
+        warn $(printf "${WARN_FSO_UNREAD}" "${file}")
+        continue
+    fi
+    if [ ! -w "${file}" ]
+    then
+        warn $(printf "${WARN_FSO_UNWRIT}" "${file}")
+        continue
+    fi
+
+    template=$(master_pot "${file}")
+
+    if [ ! -e "${template}" ]
+    then
+        warn "Warning: '${file}' has no equivalent template" \
+          "in '${MASTER_REPO}'."
+        continue
+    fi
+    if [ ! -f "${template}" ]
+    then
+        warn "Warning: '${file}' equivalent template" in '${MASTER_REPO}'" \
+          "is not a file; please check master repository tree structure."
+        continue
+    fi
+    if [ ! -r "${template}" ]
+    then
+        warn "Warning: '${file}' equivalent template" in '${MASTER_REPO}'" \
+          "is not readable; please check filesystem permissions."
+        continue
+    fi
+
+    tmpfile=$(tempfile_or_die)
+
+    if ! msgmerge --quiet --previous ${COMPENDIA} \
+      --output-file="${tmpfile}" "${file}" "${template}"
+    then
+        rm --force "${tmpfile}"
+        error 15 \
+          "Error at msgmerge-ing '${file}'; check format of translation," \
+          "template and compendia."
+    fi
+    if same_files "${file}" "${tmpfile}"
+    then
+        rm --force "${tmpfile}"
+        continue
+    fi
+    if ! mv --backup "${tmpfile}" "${file}"
+    then
+        rm --force "${tmpfile}"
+        error 11 \
+          "Error at replacing '${file}' with its formatted version;" \
+          "${EMSG_CHK_ALOS}"
+    fi
+    print_msg "  ${file}"
+done



reply via email to

[Prev in Thread] Current Thread [Next in Thread]