diff --git a/Scripts/Functions/Locale/locale.sh b/Scripts/Functions/Locale/locale.sh index 3f402e3..825ac62 100755 --- a/Scripts/Functions/Locale/locale.sh +++ b/Scripts/Functions/Locale/locale.sh @@ -1,7 +1,7 @@ #!/bin/bash # # locale.sh -- This function provides internationalization features -# for centos-art.sh script through gettext standard processes. +# for centos-art.sh script through GNU gettext standard processes. # # Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG # @@ -32,6 +32,7 @@ function locale { cli_printMessage "`gettext "Cannot locale English language to itself."`" --as-error-line fi + local ACTIONNAMS='' local ACTIONNAM='' local ACTIONVAL='' @@ -41,34 +42,28 @@ function locale { # related object or not. local FLAG_DONT_CREATE_MO='false' - # Define localization (l10n) base directory. This is the location + # Define localization (l10n) base directory. This is the place # where all translation messages are organized in. Translation - # messages, here, are organized using the same order of the + # messages, here, are organized using the same organization of the # components they represent inside the `trunk/Identity', # `trunk/Manuals' or `trunk/Scripts' directory structures. - # Moreover, the localization base directory must be used as source - # location for subverion operations (e.g., status, update, commit, - # etc.). Otherwise, it would be difficult to add directory - # structures that have several levels down from the localization - # base directory up to the repository (e.g., it is not possible in + # The localization base directory must be used as source location + # for subverion operations (e.g., status, update, commit, etc.). + # Otherwise, it would be difficult to add directory structures + # that have several levels down from the localization base + # directory up to the repository (e.g., it is not possible in # subversion to add a directory structure which parent directory # structure hasn't been added to the repository, previously.). L10N_BASEDIR="$(cli_getRepoTLDir)/L10n" # Interpret arguments and options passed through command-line. - locale_getOptions + ${FUNCNAM}_getOptions # Redefine positional parameters using ARGUMENTS. At this point, # option arguments have been removed from ARGUMENTS variable and # only non-option arguments remain in it. eval set -- "$ARGUMENTS" - # Define action name. It does matter what option be passed to - # centos-art, there are many different actions to perform based on - # the option passed (e.g., `--edit', `--read', `--search', etc.). - # In that sake, we defined action name inside document_getArguments, - # at the moment of interpreting options. - # Syncronize changes between repository and working copy. At this # point, changes in the repository are merged in the working copy # and changes in the working copy committed up to repository. @@ -89,45 +84,20 @@ function locale { cli_printMessage "`gettext "The path provided doesn't support localization."`" --as-error-line fi - # Define work directory. This is the place where locales - # directories will be stored in. + # Define localization working directory. This is the place + # where language-specific directories are stored in. WORKDIR=$(echo ${ACTIONVAL} \ | sed -r -e "s!trunk/(Identity|Scripts|Manuals)!trunk/L10n/\1!") - # Add current locale to work directory. This is the place - # where parent directories specific translation messages - # (e.g., the .po, .pot and .mo files) will be stored in. The - # `locale' functionality creates translation messages for all - # translatable files inside the parent directory and never for - # individual files inside the same parent directory. + # Redefine localization working directory to include + # language-specific directories. This is the place where POT, + # PO, and MO files are stored in. WORKDIR=$WORKDIR/$(cli_getCurrentLocale) - # Prepare working direcotry to receive .po files. - if [[ ! -d ${WORKDIR} ]];then - - # Print separator line. - cli_printMessage "-" --as-separator-line - - # Output action message. - cli_printMessage "${WORKDIR}" --as-creating-line - - # Create directory making parent directories as needed. - mkdir -p ${WORKDIR} - - # Commit changes from working copy to central repository - # only. At this point, changes in the repository are not - # merged in the working copy, but chages in the working - # copy do are committed up to repository. - cli_commitRepoChanges "${L10N_BASEDIR}" - - fi - - # Execute action name. - if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then - eval $ACTIONNAM - else - cli_printMessage "`gettext "A valid action is required."`" --as-error-line - fi + # Execute action names. + for ACTIONNAM in $ACTIONNAMS;do + ${ACTIONNAM} + done done diff --git a/Scripts/Functions/Locale/locale_editMessages.sh b/Scripts/Functions/Locale/locale_editMessages.sh index fb9b9c3..d8bd3e1 100755 --- a/Scripts/Functions/Locale/locale_editMessages.sh +++ b/Scripts/Functions/Locale/locale_editMessages.sh @@ -28,7 +28,30 @@ function locale_editMessages { # Print separator line. cli_printMessage '-' --as-separator-line - # Initialize local variables. + # Prepare localization working directory to receive translation + # files. + if [[ ! -d ${WORKDIR} ]];then + + # Print separator line. + cli_printMessage "-" --as-separator-line + + # Output action message. + cli_printMessage "${WORKDIR}" --as-creating-line + + # Create localization working directory making parent + # directories as needed. Subversion doesn't create directories + # recursively, so we use the system's `mkdir' command and then + # subversion to register the changes. + mkdir -p ${WORKDIR} + + # Commit changes from working copy to central repository only. + # At this point, changes in the repository are not merged in + # the working copy, but chages in the working copy do are + # committed up to repository. + cli_commitRepoChanges "${L10N_BASEDIR}" + + fi + local FILES='' if [[ $ACTIONVAL =~ "^$(cli_getRepoTLDir)/(Manuals|Identity/Models)/.*$" ]];then @@ -59,7 +82,7 @@ function locale_editMessages { eval ${EDITOR} ${FILE} # Update machine object (.mo) from portable object (.po). - locale_updateMessageBinary ${FILE} + ${FUNCNAM}_updateMessageBinary ${FILE} done diff --git a/Scripts/Functions/Locale/locale_getOptions.sh b/Scripts/Functions/Locale/locale_getOptions.sh index 111180f..3990960 100755 --- a/Scripts/Functions/Locale/locale_getOptions.sh +++ b/Scripts/Functions/Locale/locale_getOptions.sh @@ -1,14 +1,15 @@ #!/bin/bash # # locale_getOptions.sh -- This function interprets option parameters -# passed to `locale' functionality and calls actions accordingly. +# passed to `locale' functionality and defines action names +# accordingly. # # Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG # # 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. +# 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 @@ -29,7 +30,7 @@ function locale_getOptions { local ARGSS="" # Define long options we want to support. - local ARGSL="filter:,quiet,answer-yes,dont-commit-changes,update,edit,dont-create-mo" + local ARGSL="filter:,quiet,answer-yes,dont-commit-changes,update,edit,delete,dont-create-mo" # Parse arguments using getopt(1) command parser. cli_parseArguments @@ -64,12 +65,17 @@ function locale_getOptions { ;; --update ) - ACTIONNAM="${FUNCNAM}_updateMessages" + ACTIONNAMS="$ACTIONNAMS ${FUNCNAM}_updateMessages" shift 1 ;; --edit ) - ACTIONNAM="${FUNCNAM}_editMessages" + ACTIONNAMS="$ACTIONNAMS ${FUNCNAM}_editMessages" + shift 1 + ;; + + --delete ) + ACTIONNAMS="$ACTIONNAMS ${FUNCNAM}_deleteMessages" shift 1 ;; @@ -94,7 +100,20 @@ function locale_getOptions { esac done + # Verify action names. When no action name is specified, use + # edition as default action name. + if [[ $ACTIONNAMS == '' ]];then + ACTIONNAMS="${FUNCNAM}_editMessages" + fi + # Redefine ARGUMENTS variable using current positional parameters. cli_parseArgumentsReDef "$@" + # Verify non-option arguments passed to command-line. If there + # isn't any, redefine the ARGUMENTS variable to use the current + # location the functionality was called from. + if [[ $ARGUMENTS == '' ]];then + ARGUMENTS=${PWD} + fi + } diff --git a/Scripts/Functions/Locale/locale_updateMessageMetadata.sh b/Scripts/Functions/Locale/locale_updateMessageMetadata.sh index 99a0965..ab5d549 100755 --- a/Scripts/Functions/Locale/locale_updateMessageMetadata.sh +++ b/Scripts/Functions/Locale/locale_updateMessageMetadata.sh @@ -22,7 +22,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # ---------------------------------------------------------------------- -# $Id4 +# $Id$ # ---------------------------------------------------------------------- function locale_updateMessageMetadata { @@ -52,8 +52,8 @@ function locale_updateMessageMetadata { # Define replacement lines for pattern line. DST[0]="\"Project-Id-Version: ${CLI_PROGRAM} (${CURRENTLOCALE})\\\n\"" - DST[1]="\"Report-Msgid-Bugs-To: CentOS Documentation SIG <=MAIL_DOCS=>\\\n\"" - DST[2]="\"Last-Translator: CentOS Documentation SIG <=MAIL_DOCS=>\\\n\"" + DST[1]="\"Report-Msgid-Bugs-To: The CentOS L10n SIG <=MAIL_L10N=>\\\n\"" + DST[2]="\"Last-Translator: The CentOS L10n SIG <=MAIL_L10N=>\\\n\"" DST[3]="\"Language-Team: ${LANGNAME}\\\n\"" # Change pattern lines with their replacement lines. diff --git a/Scripts/Functions/Locale/locale_updateMessagePObjects.sh b/Scripts/Functions/Locale/locale_updateMessagePObjects.sh index 376f6c1..37393d8 100755 --- a/Scripts/Functions/Locale/locale_updateMessagePObjects.sh +++ b/Scripts/Functions/Locale/locale_updateMessagePObjects.sh @@ -1,8 +1,10 @@ #!/bin/bash # -# locale_updateMessagePObjects.sh --- This function verifies, -# initializes or updates portable objects from portable object -# templates. +# locale_updateMessagePObjects.sh -- This function initializes the +# portable object when it doesn't exist. When the portable object does +# exist, it is updated instead. In both cases, the portable object +# template is used as source to merge changes inside the portable +# object. # # Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG # @@ -29,25 +31,23 @@ function locale_updateMessagePObjects { local FILE="$1" # Verify the portable object template. The portable object - # template is used to create the portable object. + # template is used to create the portable object. We cannot + # continue without it. cli_checkFiles "${FILE}.pot" + # Print action message. + cli_printMessage "${FILE}.po" --as-creating-line + # Verify existence of portable object. The portable object is the # file translators edit in order to make translation works. if [[ -f ${FILE}.po ]];then - # Print action message. - cli_printMessage "${FILE}.po" --as-updating-line - # Update portable object merging both portable object and # portable object template. msgmerge --output="${FILE}.po" "${FILE}.po" "${FILE}.pot" --quiet else - # Print action message. - cli_printMessage "${FILE}.po" --as-creating-line - # Initiate portable object using portable object template. # Do not print msginit sterr output, use centos-art action # message instead. @@ -57,7 +57,7 @@ function locale_updateMessagePObjects { # Sanitate portable object metadata. This is the first time # the portable object is created so some modifications are # needed to customized metadata. - locale_updateMessageMetadata "${FILE}.po" + ${FUNCNAM}_updateMessageMetadata "${FILE}.po" fi diff --git a/Scripts/Functions/Locale/locale_updateMessageShell.sh b/Scripts/Functions/Locale/locale_updateMessageShell.sh index 463dd33..014b7ae 100755 --- a/Scripts/Functions/Locale/locale_updateMessageShell.sh +++ b/Scripts/Functions/Locale/locale_updateMessageShell.sh @@ -1,9 +1,9 @@ #!/bin/bash # # 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). +# source files under action value and retrives translatable strings in +# order to creates/updates both the portable object template (.pot) +# and the portable object (.po) related. # # Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG # @@ -39,25 +39,25 @@ function locale_updateMessageShell { # use inside the repository. local EXTENSION='sh' - # Build list of files to process. - local FILES=$(cli_getFilesList $ACTIONVAL --pattern="${FLAG_FILTER}.*\.${EXTENSION}") + # Build list of files to process. When building the patter, be + # sure the value passed through `--filter' be exactly evaluated + # with the extension as prefix. Otherwise it would be difficult to + # match files that share the same characters in their file names + # (e.g., it would be difficult to match only `hello.sh' if + # `hello-world.sh' also exists in the same location). + local FILES=$(cli_getFilesList $ACTIONVAL --pattern="${FLAG_FILTER}\.${EXTENSION}") # Print action message. cli_printMessage "${FILE}.pot" --as-updating-line - # Prepare directory structure to receive .po files. - if [[ ! -d $(dirname ${FILE}) ]];then - mkdir -p $(dirname ${FILE}) - fi - # Retrive translatable strings from shell script files and create # the portable object template (.pot) from them. /usr/bin/xgettext --output=${FILE}.pot \ - --copyright-holder="CentOS Documentation SIG" \ + --copyright-holder="The CentOS L10n SIG" \ --width=70 --sort-by-file ${FILES} # Verify, initialize or update portable objects from portable # object templates. - locale_updateMessagePObjects "${FILE}" + ${FUNCNAM}_updateMessagePObjects "${FILE}" } diff --git a/Scripts/Functions/Locale/locale_updateMessageXml.sh b/Scripts/Functions/Locale/locale_updateMessageXml.sh index ebbfbe1..93c03b5 100755 --- a/Scripts/Functions/Locale/locale_updateMessageXml.sh +++ b/Scripts/Functions/Locale/locale_updateMessageXml.sh @@ -33,20 +33,23 @@ function locale_updateMessageXml { # (.pot) and portable objects (.po) files. local FILE="${WORKDIR}/messages" - # Define regular expression to match extensions of XML files we - # use inside the repository. - local EXTENSION='(svg|xml|xhtml|docbook)' + # Define regular expression to match the file extension of all + # XML-based source files that can be localized inside the working + # copy. Be aware that sometimes, source files and output files + # are stored in the same location (e.g., when rendering + # `tcar-ug.docbook' file the `tcar-ug.xhtml' is saved in the same + # location). Avoid using output files as if they were source + # files, when retriving translatable strings. + local EXTENSION='(svg|docbook)' - # Build list of files to process. Remember that in some cases - # templates and output are in the same location (e.g., when - # rendering `trunk/Manuals/repository.xhtml/' directory). In these - # cases localized content are stored in the same location where - # template files are retrived from and we need to avoid using - # localized content from being interpreted as design models. In - # that sake, supress language-specific files from the list of - # files to process. + # Build list of files to process. When building the patter, be + # sure the value passed through `--filter' be exactly evaluated + # with the extension as prefix. Otherwise it would be difficult to + # match files that share the same characters in their file names + # (e.g., it would be difficult to match only `hello.docbook' if + # `hello-world.docbook' also exists in the same location). local FILES=$(cli_getFilesList ${ACTIONVAL} \ - --pattern="${FLAG_FILTER}.*\.${EXTENSION}" \ + --pattern="${FLAG_FILTER}\.${EXTENSION}" \ --maxdepth='1' --type="f" \ | egrep -v '/[[:alpha:]]{2}_[[:alpha:]]{2}/') @@ -67,12 +70,6 @@ function locale_updateMessageXml { # Verify, initialize or merge portable objects from portable # object templates. - locale_updateMessagePObjects "${FILE}" - - # Commit changes from working copy to central repository only. At - # this point, changes in the repository are not merged in the - # working copy, but chages in the working copy do are committed up - # to repository. - cli_commitRepoChanges "${L10N_BASEDIR}" + ${FUNCNAM}_updateMessagePObjects "${FILE}" } diff --git a/Scripts/Functions/Locale/locale_updateMessages.sh b/Scripts/Functions/Locale/locale_updateMessages.sh index b3eee71..30c1964 100755 --- a/Scripts/Functions/Locale/locale_updateMessages.sh +++ b/Scripts/Functions/Locale/locale_updateMessages.sh @@ -29,6 +29,10 @@ function locale_updateMessages { + # Verify existence of localization working directory. We cannot + # update translation files that don't exist. + cli_checkFiles $WORKDIR + local ACTIONNAM='' # Evaluate action value to determine whether to use xml2po to @@ -37,25 +41,22 @@ function locale_updateMessages { # files. if [[ $ACTIONVAL =~ "^$(cli_getRepoTLDir)/(Manuals|Identity/Models)/.*$" ]];then - # Update translatable strings inside portable object templates - # for XML-based files (e.g., scalable vector graphics). - ACTIONNAM="${FUNCNAM}_updateMessageXml" + # Update translatable strings inside the portable object + # template related to XML-based files (e.g., scalable vector + # graphics). + ${FUNCNAM}_updateMessageXml elif [[ $ACTIONVAL =~ "^$(cli_getRepoTLDir)/Scripts$" ]];then - # Update translatable strings inside portable object templates - # for shell scripts (e.g., centos-art.sh script). - ACTIONNAM="${FUNCNAM}_updateMessageShell" + # Update translatable strings inside the portable object + # template related to shell scripts (e.g., the centos-art.sh + # script). + ${FUNCNAM}_updateMessageShell else + cli_printMessage "`gettext "The path provided does not support localization."`" --as-error-line - fi - # Execute action name. - if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then - eval $ACTIONNAM - else - cli_printMessage "`gettext "A valid action is required."`" --as-error-line fi }