From bf6bff12c09489220cd19caed207a3685759490b Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Feb 13 2011 16:24:10 +0000 Subject: Update `locale' functionality. --- diff --git a/Scripts/Bash/Functions/Locale/locale.sh b/Scripts/Bash/Functions/Locale/locale.sh index ec3ecd2..7caac41 100644 --- a/Scripts/Bash/Functions/Locale/locale.sh +++ b/Scripts/Bash/Functions/Locale/locale.sh @@ -1,7 +1,7 @@ #!/bin/bash # # locale.sh -- This function provides internationalization features to -# centos-art.sh script by means of gettext. +# centos-art.sh script through gettext standard processes. # # Copyright (C) 2009-2011 Alain Reguera Delgado # @@ -27,9 +27,9 @@ function locale { # Initialize default value to create/update machine object flag. - # The machine object flag (--create-mo) controls whether - # centos-art.sh script creates/updates the machine object related - # to portable object or not. + # The machine object flag (--dont-create-mo) controls whether + # centos-art.sh script does create/update the machine object + # related object or not. local FLAG_DONT_CREATE_MO='false' # Define the command-line interface. diff --git a/Scripts/Bash/Functions/Locale/locale_doReport.sh b/Scripts/Bash/Functions/Locale/locale_doReport.sh deleted file mode 100755 index 7deb529..0000000 --- a/Scripts/Bash/Functions/Locale/locale_doReport.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash -# -# locale_doReport.sh -- This function outputs the centos-art.sh -# translations table. Use this function to know how many languages the -# centos-art.sh script is available in, the last translators and -# revision dates. -# -# Copyright (C) 2009-2011 Alain Reguera Delgado -# -# 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 2 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. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function locale_doReport { - - # Define variables as local to avoid conflicts outside. - local LOCALESLIST='' - local LANG_NAME='' - local LANG_COUNTRY='' - local PO_LASTAUTHOR='' - local PO_REVDATE='' - local PO_STATUS='' - - # Define list of locale codes. - LOCALESLIST=$(cli_getLocales) - - for LOCALECODE in $LOCALESLIST;do - - LANG_NAME=$(cli_getLangName $LOCALECODE) - LANG_COUNTRY=$(cli_getCountryName $LOCALECODE) - - if [[ -f $TEXTDOMAINDIR/$LOCALECODE/$TEXTDOMAIN.po ]] \ - && [[ -f $TEXTDOMAINDIR/$LOCALECODE/LC_MESSAGES/$TEXTDOMAIN.mo ]];then - - # Re-define translation's status. - PO_STATUS="`gettext "Available"`" - - # Re-define translation's last update. - PO_REVDATE=$(egrep '^"PO-Revision-Date:' $TEXTDOMAINDIR/$LOCALECODE/$TEXTDOMAIN.po \ - | cut -d: -f2- | sed -r 's!\\n"!!' | sed -r 's!^[[:space:]]+!!' | cut -d ' ' -f1) - - # Re-define translation's last author. - PO_LASTAUTHOR=$(egrep '^"Last-Translator:' $TEXTDOMAINDIR/$LOCALECODE/$TEXTDOMAIN.po \ - | cut -d: -f2 | sed -r 's!\\n"!!' | sed -r 's!^[[:space:]]+!!') - - else - - LANGCOUNTRY="" - PO_LASTAUTHOR="" - PO_REVDATE="" - PO_STATUS="" - - fi - - # Output information line. - echo "$LOCALECODE | $LANG_NAME | $LANG_COUNTRY | $PO_STATUS | $PO_REVDATE | $PO_LASTAUTHOR" - - done \ - | egrep -i "$FLAG_FILTER" \ - | awk 'BEGIN {FS="|"; format ="%7s\t%-15s\t%-15s\t%-12s\t%-12s\t%-s\n" - printf "--------------------------------------------------------------------------------\n" - printf format, "'`gettext "Code"`'", " '`gettext "Language"`'", " '`gettext "Country"`'",\ - " '`gettext "Status"`'", " '`gettext "LastRev"`'", " '`gettext "Author"`'" - printf "--------------------------------------------------------------------------------\n"} - {printf format, substr($1,0,7), substr($2,0,15), substr($3,0,15), $4, $5, $6} - END {printf "--------------------------------------------------------------------------------\n"}' -} diff --git a/Scripts/Bash/Functions/Locale/locale_editMessages.sh b/Scripts/Bash/Functions/Locale/locale_editMessages.sh index dc5cad0..8205fa9 100755 --- a/Scripts/Bash/Functions/Locale/locale_editMessages.sh +++ b/Scripts/Bash/Functions/Locale/locale_editMessages.sh @@ -26,16 +26,11 @@ function locale_editMessages { - # Syncronize changes between the working copy and the central - # repository. - cli_commitRepoChanges - - # Redefine filter pattern in order to reduce match to portable - # objects only. + # Redefine filter pattern in order to get portable objects only. local FLAG_FILTER="${FLAG_FILTER}.*\.po" # Build list of portable objects which we want to edit. - cli_getFilesList + cli_getFilesList "${WORKDIR}" # Print action preamble. cli_printActionPreamble "${FILES}" "doEdit" 'AsResponseLine' @@ -46,8 +41,4 @@ function locale_editMessages { # Update machine object (.mo) from portable object (.po). locale_updateMessageBinary ${FILES} - # Syncronize changes between the working copy and the central - # repository. - cli_commitRepoChanges - } diff --git a/Scripts/Bash/Functions/Locale/locale_getActions.sh b/Scripts/Bash/Functions/Locale/locale_getActions.sh index 948a710..8916156 100644 --- a/Scripts/Bash/Functions/Locale/locale_getActions.sh +++ b/Scripts/Bash/Functions/Locale/locale_getActions.sh @@ -30,7 +30,7 @@ function locale_getActions { local ARGSS="" # Define long options we want to support. - local ARGSL="update:,edit:,report:,dont-create-mo" + local ARGSL="update:,edit:,dont-create-mo" # Parse arguments using getopt(1) command parser. cli_doParseArguments @@ -39,7 +39,7 @@ function locale_getActions { # parser. eval set -- "$ARGUMENTS" - # Define action to take for each option passed. + # Look for options passed through command-line. while true; do case "$1" in @@ -51,7 +51,7 @@ function locale_getActions { # Redefine action value. ACTIONVAL="$2" - # Break while loop. + # Rotate positional parameters shift 2 ;; @@ -63,19 +63,7 @@ function locale_getActions { # Redefine action value. ACTIONVAL="$2" - # Break while loop. - shift 2 - ;; - - --report ) - - # Redefine action name. - ACTIONNAM="${FUNCNAM}_printTranslationReport" - - # Redefine action value. - ACTIONVAL="$2" - - # Break while loop. + # Rotate positional parameters shift 2 ;; @@ -84,7 +72,7 @@ function locale_getActions { # Redefine create machine object flag. FLAG_DONT_CREATE_MO="true" - # Break while loop. + # Rotate positional parameters shift 1 ;; @@ -99,15 +87,24 @@ function locale_getActions { # copy. cli_checkRepoDirSource - # Redefine action value variable in order to transform - # `trunk/Identity/' and `trunk/Manuals/' parent directory - # structures into `trunk/Locales' parallel directory structures. - # This way we can use parent directory paths to update related - # entries inside `trunk/Locales/' directory structures. - ACTIONVAL=$(echo $ACTIONVAL | sed -r \ + # Define locales base directory where locale directory structures + # are stored in. + local BASEDIR="$(cli_getRepoTLDir)/Locales" + + # Define locales work directory. This is the place where locale + # files (e.g., .po, .pot, .mo), for a specific parent directories, + # are stored in. There is one locale work directory for each + # parent directory or said differently, each parent directory has + # a parallel directory under `trunk/Locales' to store its + # translation messages. + local WORKDIR=$(echo $ACTIONVAL | sed -r \ -e 's!trunk/(Identity|Manuals|Scripts)/!trunk/Locales/\1/!' \ - -e "s!Motifs/$(cli_getPathComponent '--theme')/?!!") - + -e "s!Models/([A-Za-z0-9]+)/?!!") + + # Syncronize changes between the working copy and the central + # repository. + cli_commitRepoChanges "${WORKDIR}" + # Execute action name. if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then eval $ACTIONNAM @@ -116,4 +113,8 @@ function locale_getActions { cli_printMessage "$(caller)" 'AsToKnowMoreLine' fi + # Syncronize changes between the working copy and the central + # repository. + cli_commitRepoChanges "${WORKDIR}" + } diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageBinary.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageBinary.sh index 77f61fc..a4907e2 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessageBinary.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageBinary.sh @@ -48,7 +48,7 @@ function locale_updateMessageBinary { MO=$(dirname ${PO})/LC_MESSAGES/$(basename ${PO} | sed -r 's!\.po$!.mo!') # Print action message. - if [[ -f ${FILE} ]];then + if [[ -f ${MO} ]];then cli_printMessage "${MO}" 'AsUpdatingLine' else cli_printMessage "${MO}" 'AsCreatingLine' @@ -57,8 +57,8 @@ function locale_updateMessageBinary { # Define directory used to store machine object. MODIR=$(dirname ${MO}) - # Verify existence of directory used to store machine object - # files. + # Create directory to store machine object, if it doesn't + # exist. if [[ ! -d ${MODIR} ]];then mkdir -p ${MODIR} fi diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageMetadata.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageMetadata.sh index 3a84873..5f9bd04 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessageMetadata.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageMetadata.sh @@ -44,14 +44,14 @@ function locale_updateMessageMetadata { # Check existence of file before work with it. cli_checkFiles "${FILE}" 'f' - # Define patterns line. The pattern lines are put inside portable + # Define pattern lines. The pattern lines are put inside portable # objects through xgettext and xml2po commands . SRC[0]='Project-Id-Version:' SRC[1]='Report-Msgid-Bugs-To:' SRC[2]='Last-Translator:' SRC[3]='Language-Team:' - # Define replacement line for pattern line. + # Define replacement lines for pattern line. DST[0]="\"Project-Id-Version: ${CLINAME} (${CURRENTLOCALE})\\\n\"" DST[1]="\"Report-Msgid-Bugs-To: =MAIL_DOCS=\\\n\"" DST[2]="\"Last-Translator: CentOS Documentation SIG\\\n\"" diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageShell.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageShell.sh index 87e2d78..820dcbc 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessageShell.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageShell.sh @@ -3,7 +3,7 @@ # locale_updateMessageShell.sh -- This function parses shell scripts # under action value, retrives translatable strings and # creates/updates both portable object templates (.pot) and portable -# objects (.po). +# objects (.po). # # Copyright (C) 2009-2011 Alain Reguera Delgado # @@ -28,28 +28,35 @@ function locale_updateMessageShell { - # Redefine filter pattern in order to reduce match to scalable - # vector graphics only. - local FLAG_FILTER="${FLAG_FILTER}.*\.(sh|py|pl)" + # Redefine locales work directory to store locale-specific files. + # The redefinition should be done locally to avoid undesired + # concatenations. + local WORKDIR=${WORKDIR}/$(cli_getCurrentLocale) - # Define location where shell script files (e.g., Bash, Python, - # Perl, etc.), we want to have translation for, are place in. - local LOCATION="$(echo ${ACTIONVAL} \ - | sed -r "s!trunk/Locales/Scripts!trunk/Scripts!")" - - # Define name of file used to create both portable object - # templates (.pot) and portable objects (.po) files. - local FILE="${ACTIONVAL}/$(cli_getCurrentLocale)/${TEXTDOMAIN}" + # Create locales work directory if it doesn't exist. + if [[ ! -d ${WORKDIR} ]];then + mkdir -p ${WORKDIR} + fi - # Verify existence of directory where .pot, .po, and .mo files - # will be stored. - if [[ ! -d $(dirname $FILE) ]];then - mkdir -p $(dirname $FILE) + # Define file-name used as reference to create portable object + # templates (.pot), portable objects (.po) and machine objects + # (.mo). + local FILE="${WORKDIR}/${TEXTDOMAIN}" + + # Redefine filter pattern in order to get shell scripts only. + # Since centos-art.sh is written in Bash, centos-art.sh does + # retrive translatable strings from shell scripts written in Bash + # only. + if [[ $ACTIONVAL =~ "$(cli_getRepoTLDir)/Scripts/Bash/.*$" ]];then + FLAG_FILTER="${FLAG_FILTER}.*\.sh" + else + cli_printMessage "`gettext "The path provided can't be processed."`" + cli_printMessage "$(caller)" 'AsToKnowMoreLine' fi # Build list of XML-base files which we want retrive translatable # strings from. - cli_getFilesList "${LOCATION}" + cli_getFilesList # Print out action preamble. Since the `--filter' option can be # supplied, it is useful to know which files we are getting diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh index 339d787..0f05d91 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh @@ -29,13 +29,17 @@ function locale_updateMessageXml { # Define name of file used to create both portable object # templates (.pot) and portable objects (.po) files. - local FILE="${ACTIONVAL}/$(cli_getCurrentLocale)" + local FILE="${WORKDIR}/$(cli_getCurrentLocale)" - # Redefine filter pattern in order to reduce match to scalable - # vector graphics only. - local FLAG_FILTER="${FLAG_FILTER}.*\.(xml|svg)" + # Redefine filtering pattern in order to get XML-based files only + # using repository directory structures as reference. + if [[ $ACTIONVAL =~ 'trunk/Identity/.+' ]];then + FLAG_FILTER="${FLAG_FILTER}.*\.svg" + else + FLAG_FILTER="${FLAG_FILTER}.*\.xml" + fi - # Build list of XML-base files which we want retrive translatable + # Build list of XML-base files we want retrive translatable # strings from. cli_getFilesList diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessages.sh b/Scripts/Bash/Functions/Locale/locale_updateMessages.sh index bbb982c..934e141 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessages.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessages.sh @@ -1,9 +1,11 @@ #!/bin/bash # -# locale_updateMessages.sh -- This function updates translatable -# strings inside portable object templates (.pot) and creates portable -# objects (.po) from it. Translatable strings are taken from both -# XML-based files (using xml2po) and shell scripts (using xgettext). +# locale_updateMessages.sh -- This function extracts translatable +# strings from both XML-based files (using xml2po) and shell scripts +# (using xgettext). Translatable strings are initially stored in +# portable objects templates (.pot) which are later merged into +# portable objects (.po) in order to be optionally converted as +# machine objects (.mo). # # Copyright (C) 2009-2011 Alain Reguera Delgado # @@ -30,25 +32,17 @@ function locale_updateMessages { local ACTIONNAM='' - # Define base directory structure where locale files (.pot, .po, - # .mo) are stored using parallel directories layout. - local ACTIONDIR="$(cli_getRepoTLDir)/Locales" - - # Syncronize changes between the working copy and the central - # repository. - cli_commitRepoChanges - # Evaluate action value to determine whether to use xml2po to # extract translatable strings from XML-based files or to use # xgettext to extract translatable strings from shell script # files. - if [[ $ACTIONVAL =~ "^${ACTIONDIR}/(Identity|Manuals)/.+$" ]];then + if [[ $WORKDIR =~ "^${BASEDIR}/(Identity|Manuals)/.+$" ]];then # Update translatable strings inside portable object templates # for XML-based files (e.g., scalable vector graphics). ACTIONNAM="${FUNCNAM}_updateMessageXml" - elif [[ $ACTIONVAL =~ "^${ACTIONDIR}/Scripts/.+$" ]];then + elif [[ $WORKDIR =~ "^${BASEDIR}/Scripts/.+$" ]];then # Update translatable strings inside portable object templates # for shell scripts (e.g., centos-art.sh script). @@ -66,8 +60,4 @@ function locale_updateMessages { eval $ACTIONNAM fi - # Syncronize changes between the working copy and the central - # repository. - cli_commitRepoChanges - }