diff --git a/Scripts/Bash/Functions/Locale/locale.sh b/Scripts/Bash/Functions/Locale/locale.sh index 2c2cb48..c812432 100755 --- a/Scripts/Bash/Functions/Locale/locale.sh +++ b/Scripts/Bash/Functions/Locale/locale.sh @@ -50,6 +50,13 @@ function locale { # exist.). local L10N_BASEDIR="${TCAR_WORKDIR}/Locales" + # Verify current locale information to avoid English messages from + # being localized to themselves. The English language is used as + # reference to write translatable strings inside the source files. + if [[ ${CLI_LANG_LC} =~ '^en' ]];then + cli_printMessage "`gettext "The English language cannot be localized to itself."`" --as-error-line + fi + # Interpret arguments and options passed through command-line. locale_getOptions @@ -62,11 +69,21 @@ function locale { # through its command-line. for ACTIONVAL in "$@";do + # Print action message. + cli_printMessage "${ACTIONVAL}" --as-processing-line + # Sanitate non-option arguments to be sure they match the # directory conventions established by centos-art.sh script # against source directory locations in the working copy. ACTIONVAL=$(cli_checkRepoDirSource ${ACTIONVAL}) + # Verify directory passed as non-option argument to be sure it + # supports localization. + locale_isLocalizable "${ACTIONVAL}" + if [[ $? -ne 0 ]];then + cli_printMessage "`gettext "The path provided does not support localization."`" --as-error-line + fi + # Verify non-option arguments passed to centos-art.sh # command-line. It should point to an existent directory under # version control inside the working copy. Otherwise, if it @@ -74,13 +91,6 @@ function locale { # the script execution with an error message. cli_checkFiles ${ACTIONVAL} -d --is-versioned - # Define localization working directory using directory passed - # as non-option argument. The localization working directory - # is the place where POT and PO files are stored inside the - # working copy. - L10N_WORKDIR=$(echo "${ACTIONVAL}" \ - | sed -r -e "s!(Identity|Scripts|Documentation)!Locales/\1!")/${CLI_LANG_LC} - # Execute localization actions provided to centos-art.sh # script through its command-line. Notice that localization # actions will be executed in the same order they were diff --git a/Scripts/Bash/Functions/Locale/locale_editMessages.sh b/Scripts/Bash/Functions/Locale/locale_editMessages.sh index 07fc2d7..195d3f4 100755 --- a/Scripts/Bash/Functions/Locale/locale_editMessages.sh +++ b/Scripts/Bash/Functions/Locale/locale_editMessages.sh @@ -25,49 +25,33 @@ function locale_editMessages { - # Verify current locale information to avoid English messages from - # being localized to themselves. The English language is used as - # reference to write translatable strings inside the source files. - if [[ ${CLI_LANG_LC} =~ '^en' ]];then - cli_printMessage "`gettext "The English language cannot be localized to itself."`" --as-error-line - fi - - # Verify directory passed as non-option argument to be sure it - # supports localization. - locale_isLocalizable "${ACTIONVAL}" - if [[ $? -ne 0 ]];then - cli_printMessage "`gettext "The path provided does not support localization."`" --as-error-line - fi - local PO_FILE='' local PO_FILES='' - # Prepare working directory to receive translation files. - locale_prepareWorkingDirectory ${L10N_WORKDIR} + # Define location where translation files will be stored in + # without language information in it. The language information is + # put later, when we build the list of files. + local L10N_WORKDIR=$(cli_getLocalizationDir "${ACTIONVAL}" "--no-lang") - # Synchronize 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. - cli_synchronizeRepoChanges "${L10N_WORKDIR}" + # Prepare working directory to receive translation files. Don't do + # this here. It is already done as part the update actions, but we + # need it here for those cases when no update action is run and + # one execute the edit option. + locale_prepareWorkingDirectory ${L10N_WORKDIR} # Define list of PO files to process based on paths provided as # non-option arguments through centos-art.sh script command-line. - if [[ $ACTIONVAL =~ "^${TCAR_WORKDIR}/(Documentation/Models/Docbook|Identity/Models)/.*$" ]];then - - # Define list of PO files for XML-based files. - PO_FILES=$(cli_getFilesList ${L10N_WORKDIR} --type="f" --pattern="^.+/messages\.po$") + if [[ $ACTIONVAL =~ "^${TCAR_WORKDIR}/(Documentation/Models/(Docbook|Svg)|Identity/Models)/.*$" ]];then # Do not create MO files for XML-based files. FLAG_DONT_CREATE_MO='true' - elif [[ $ACTIONVAL =~ "^${TCAR_WORKDIR}/Scripts/Bash$" ]];then - - # Define list of PO files for script files. - PO_FILES=$(cli_getFilesList ${L10N_WORKDIR} --pattern="^.*${FLAG_FILTER}/messages\.po$") - - else - cli_printMessage "`gettext "The path provided does not support localization."`" --as-error-line fi + + # Define list of PO files we want to work with. Don't forget to + # include the language information here. + PO_FILES=$(cli_getFilesList ${L10N_WORKDIR} --type="f" \ + --pattern=".+/${FLAG_FILTER}/${CLI_LANG_LC}/messages\.po$") # Verify list of PO files. if [[ $PO_FILES = "" ]];then @@ -76,6 +60,11 @@ function locale_editMessages { cli_printMessage '-' --as-separator-line fi + # Synchronize 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. + cli_synchronizeRepoChanges "${PO_FILES}" + # Loop through list of PO files to process in order to edit them # one by one using user's default text editor. for PO_FILE in ${PO_FILES};do @@ -96,9 +85,9 @@ function locale_editMessages { # scripts. locale_updateMessageBinary - # Syncronize changes between repository and working copy. At this + # Synchronize 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. - cli_synchronizeRepoChanges "${L10N_WORKDIR}" + cli_synchronizeRepoChanges "${PO_FILES}" } diff --git a/Scripts/Bash/Functions/Locale/locale_isLocalizable.sh b/Scripts/Bash/Functions/Locale/locale_isLocalizable.sh index 885e1e3..588875e 100755 --- a/Scripts/Bash/Functions/Locale/locale_isLocalizable.sh +++ b/Scripts/Bash/Functions/Locale/locale_isLocalizable.sh @@ -55,6 +55,7 @@ function locale_isLocalizable { DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Identity/Models/Themes/[[:alnum:]-]+/(Distro/$(\ cli_getPathComponent --release-pattern)/Anaconda|Concept|Posters|Media)" DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Documentation/Models/Docbook/[[:alnum:]-]+$" + DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Documentation/Models/Svg/[[:alnum:]-]+$" DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Scripts/Bash$" # Verify location passed as first argument against the list of diff --git a/Scripts/Bash/Functions/Locale/locale_prepareWorkingDirectory.sh b/Scripts/Bash/Functions/Locale/locale_prepareWorkingDirectory.sh index 8cf6065..0eaae6a 100755 --- a/Scripts/Bash/Functions/Locale/locale_prepareWorkingDirectory.sh +++ b/Scripts/Bash/Functions/Locale/locale_prepareWorkingDirectory.sh @@ -43,7 +43,7 @@ function locale_prepareWorkingDirectory { elif [[ $L10N_WORKDIR == '' ]];then - cli_printMessage "`gettext "The variable L10N_WORKDIR cannot be empty."`" --as-error-line + cli_printMessage "`gettext "The localization directory isn't defined."`" --as-error-line fi diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageBinary.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageBinary.sh index e206361..426eb5d 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessageBinary.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageBinary.sh @@ -42,7 +42,7 @@ function locale_updateMessageBinary { # FLAG_FILTER mustn't be applied here). Thus, when we are # selective about the functionalities we want to use, it is # possible to have translation messages only for those - # functionalities we did donwload into the working copy and no + # functionalities we did download into the working copy and no # others. There is no need to have translation messages for # functionalities we didn't download. local PO_FILES=$(cli_getFilesList ${L10N_WORKDIR} --type='f' --pattern="^.+/messages.po$") diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageShell.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageShell.sh index e379a96..ad7614f 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessageShell.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageShell.sh @@ -40,19 +40,16 @@ function locale_updateMessageShell { for FNDIR in $FNDIRS;do - # Define function name. - local FNNAME=$(basename $FNDIR) - # Define absolute path to directory used as reference to store # portable objects. - local L10N_DIR=${L10N_WORKDIR}/Functions/${FNNAME} + local L10N_WORKDIR=$(cli_getLocalizationDir "${FNDIR}") # Prepare working directory to receive translation files. - locale_prepareWorkingDirectory ${L10N_DIR} + locale_prepareWorkingDirectory ${L10N_WORKDIR} # Define absolute path to file used as reference to create # portable objects. - local MESSAGES="${L10N_DIR}/messages" + local MESSAGES="${L10N_WORKDIR}/messages" # Print action message. cli_printMessage "${MESSAGES}.pot" --as-updating-line diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh index 81dfe19..cf7bfde 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh @@ -1,8 +1,8 @@ #!/bin/bash # # locale_updateMessageXml.sh -- This function parses XML-based files -# (e.g., scalable vector graphics), retrieves translatable strings and -# creates/update gettext portable objects. +# (e.g., Scalable Vector Graphics and Docbook files), retrieves +# translatable strings and creates/update gettext portable objects. # # Copyright (C) 2009-2013 The CentOS Project # @@ -26,13 +26,6 @@ function locale_updateMessageXml { - # Print separator line. - cli_printMessage '-' --as-separator-line - - # Define filename used to create both portable object templates - # (.pot) and portable objects (.po) files. - local MESSAGES="${L10N_WORKDIR}/messages" - # Define what kind of XML file we are generating translation # messages for. This is relevant because scalable vector graphics # (SVG) files are not using entity expansion while DocBook files @@ -47,14 +40,15 @@ function locale_updateMessageXml { # independent documents (e.g., through XInclude), then lets # keep translation messages as synchronized as possible. - elif [[ $ACTIONVAL =~ "^${TCAR_WORKDIR}/Identity/Models/.+$" ]];then + elif [[ $ACTIONVAL =~ "^${TCAR_WORKDIR}/Identity/Models/.+$" ]] \ + || [[ $ACTIONVAL =~ "^${TCAR_WORKDIR}/Documentation/Models/Svg/.+$" ]];then locale_updateMessageXmlSvg - fi + else - # Verify, initialize or merge portable objects from portable - # object templates. - locale_updateMessagePObjects "${MESSAGES}" + cli_printMessage "`gettext "The path provided doesn't support localization."`" --as-error-line + + fi } diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbook.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbook.sh index 4d73176..f54ddcc 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbook.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbook.sh @@ -26,6 +26,13 @@ function locale_updateMessageXmlDocbook { + # Define location where translation files will be stored in. + local L10N_WORKDIR=$(cli_getLocalizationDir ${ACTIONVAL}) + + # Define location of the file used to create both portable object + # templates (.pot) and portable objects (.po) files. + local MESSAGES="${L10N_WORKDIR}/messages" + # Print action message. cli_printMessage "${MESSAGES}.pot" --as-updating-line @@ -73,6 +80,9 @@ function locale_updateMessageXmlDocbook { # Move into temporal directory so paths can be found relatively. pushd $(dirname ${INSTANCE}) > /dev/null + # Prepare working directory to receive translation files. + locale_prepareWorkingDirectory ${L10N_WORKDIR} + # Create portable object template from instance. xmllint --valid --noent ${INSTANCE} | xml2po -a - \ | msgcat --output=${MESSAGES}.pot --width=70 --no-location - @@ -83,4 +93,9 @@ function locale_updateMessageXmlDocbook { # Remove instance. rm ${INSTANCE} + # Verify, initialize or merge portable objects from portable + # object templates. + locale_updateMessagePObjects "${MESSAGES}" + + } diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageXmlSvg.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageXmlSvg.sh index f4d0f77..d41bec1 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessageXmlSvg.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageXmlSvg.sh @@ -1,47 +1,101 @@ #!/bin/bash # +# locale_updateMessageXmlSvg.sh -- This function parses XML-based +# files (e.g., scalable vector graphics), retrieves translatable +# strings and creates/update gettext portable objects. # +# Copyright (C) 2009-2013 The CentOS Project +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- function locale_updateMessageXmlSvg { - # Inside `Identity/Models', design models can be compressed or - # uncompressed. Because of this we cannot process all the design - # models in one unique way. Instead, we need to treat them - # individually based on their file type. + # Inside `Identity/Models' and Documentation/Models/Svg/, design + # models can be compressed or uncompressed. Because of this we + # cannot process all the design models in one unique way. Instead, + # we need to treat them individually based on their file type. + + local DIR='' + local DIRS='' + + # Define regular expression to match extensions of shell scripts + # we use inside the repository. + local EXTENSION='(svgz|svg)' + + # Build list of directories in which we want to look files for. + local DIRS=$(cli_getFilesList ${ACTIONVAL} \ + --pattern="${ACTIONVAL}/${FLAG_FILTER}") + + # Process list of directories, one by one. + for DIR in $DIRS;do - # Initialize name of temporal files. - local TEMPFILE='' - local TEMPFILES='' + # Reset information related to temporal files. + local TEMPFILE='' + local TEMPFILES='' - for FILE in $FILES;do + # Redefine localization working directory using the current + # directory. The localization working directory is the place + # where POT and PO files are stored inside the working copy. + local L10N_WORKDIR=$(cli_getLocalizationDir "${DIR}") - # Redefine temporal file based on file been processed. - TEMPFILE=$(cli_getTemporalFile $(basename ${FILE} )) + # Prepare working directory to receive translation files. + locale_prepareWorkingDirectory ${L10N_WORKDIR} - # Update the command used to read content of XML files. - if [[ $(file -b -i $FILE) =~ '^application/x-gzip$' ]];then + # Redefine final location of messages.po file, based on + # current directory. + MESSAGES=${L10N_WORKDIR}/messages + + # Build list of files we want to work with. + FILES=$(cli_getFilesList ${DIR} --pattern="${DIR}/.+\.${EXTENSION}") + + for FILE in $FILES;do + + # Redefine temporal file based on file been processed. + TEMPFILE=$(cli_getTemporalFile $(basename ${FILE})) + + # Update the command used to read content of XML files. + if [[ $(file -b -i $FILE) =~ '^application/x-gzip$' ]];then - # Create uncompressed copy of file. - /bin/zcat $FILE > $TEMPFILE + # Create uncompressed copy of file. + /bin/zcat $FILE > $TEMPFILE - else + else - # Create uncompressed copy of file. - /bin/cat $FILE > $TEMFILE + # Create uncompressed copy of file. + /bin/cat $FILE > $TEMPFILE - fi + fi - # Concatenate temporal files into a list so we can process - # them later through xml2po. - TEMPFILES="${TEMPFILE} ${TEMPFILES}" + # Concatenate temporal files into a list so we can process + # them later through xml2po, all at once. + TEMPFILES="${TEMPFILE} ${TEMPFILES}" - done + done + + # Create the portable object template. + cat $TEMPFILES | xml2po -a -l ${CLI_LANG_LC} - \ + | msgcat --output=${MESSAGES}.pot --width=70 --no-location - - # Create the portable object template. - xml2po -a $TEMPFILES \ - | msgcat --output=${MESSAGES}.pot --width=70 --no-location - + # Verify, initialize or merge portable objects from portable + # object templates. + locale_updateMessagePObjects "${MESSAGES}" - # Remove list of temporal files. They are no longer needed. - rm $TEMPFILES + done } diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessages.sh b/Scripts/Bash/Functions/Locale/locale_updateMessages.sh index 1f7abf2..bbd8af1 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessages.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessages.sh @@ -29,33 +29,32 @@ function locale_updateMessages { - # Verify current locale information to avoid English messages from - # being localized to themselves. The English language is used as - # reference to write translatable strings inside the source files. - if [[ ${CLI_LANG_LC} =~ '^en' ]];then - cli_printMessage "`gettext "The English language cannot be localized to itself."`" --as-error-line - fi - - # Verify directory passed as non-option argument to be sure it - # supports localization. - locale_isLocalizable "${ACTIONVAL}" - if [[ $? -ne 0 ]];then - cli_printMessage "`gettext "The path provided does not support localization."`" --as-error-line - fi - - # Prepare working directory to receive translation files. - locale_prepareWorkingDirectory ${L10N_WORKDIR} - - # Synchronize 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. - cli_synchronizeRepoChanges "${L10N_WORKDIR}" + # Prepare working directory to receive translation files. Don't + # do this here. This location can be redefine later based on + # deeper directory structures not provided as arguments to + # centos-art.sh script. For example, if you execute the following + # command: + # + # centos-art locale Documentation/Models/Svg/Brands --update + # + # it should produce the following directory structure: + # + # Locales/Documentation/Models/Svg/Brands/Logos/${LANG}/ + # Locales/Documentation/Models/Svg/Brands/Symbols/${LANG}/ + # Locales/Documentation/Models/Svg/Brands/Types/${LANG}/ + # + # and not the next one: + # + # Locales/Documentation/Models/Svg/Brands/${LANG}/ + # + # So, don't prepare working directory to receive translation files + # here. Instead, do it just before POT files creation. # 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 =~ "^${TCAR_WORKDIR}/(Documentation/Models/Docbook|Identity/Models)/.*$" ]];then + if [[ $ACTIONVAL =~ "^${TCAR_WORKDIR}/(Documentation/Models/(Docbook|Svg)|Identity/Models)/.*$" ]];then # Update translatable strings inside the portable object # template related to XML-based files (e.g., scalable vector @@ -73,9 +72,4 @@ function locale_updateMessages { cli_printMessage "`gettext "The path provided doesn't support localization."`" --as-error-line fi - # Synchronize 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. - cli_synchronizeRepoChanges "${L10N_WORKDIR}" - }