From 814e83b6eb18553692f6793a8ab3dae5aa377850 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Jun 14 2013 01:44:15 +0000 Subject: git-commit.tmp --- diff --git a/Scripts/Bash/Functions/Commons/cli_getLocalizationDir.sh b/Scripts/Bash/Functions/Commons/cli_getLocalizationDir.sh index 9b75ffd..42c4456 100755 --- a/Scripts/Bash/Functions/Commons/cli_getLocalizationDir.sh +++ b/Scripts/Bash/Functions/Commons/cli_getLocalizationDir.sh @@ -31,10 +31,16 @@ function cli_getLocalizationDir { # against source directory locations in the working copy. LOCATION=$(cli_checkRepoDirSource "${1}") + # In case the location specified would be a file, remove the file + # part from the path so only its parent directory remains. + if [[ -f ${LOCATION} ]];then + LOCATION=$(dirname ${LOCATION}) + fi + # Make path transformation. case "${2}" in - '--no-lang') + '--no-lang' ) LOCATION=$(echo "${LOCATION}" \ | sed -r -e "s!(Identity|Scripts|Documentation)!Locales/\1!") ;; diff --git a/Scripts/Bash/Functions/Commons/cli_printMessage.sh b/Scripts/Bash/Functions/Commons/cli_printMessage.sh index 94e54b4..e4cdd4d 100755 --- a/Scripts/Bash/Functions/Commons/cli_printMessage.sh +++ b/Scripts/Bash/Functions/Commons/cli_printMessage.sh @@ -256,6 +256,10 @@ function cli_printMessage { cli_printMessage "`gettext "Translation"`: $MESSAGE" --as-stdout-line ;; + --as-translating-line ) + cli_printMessage "`gettext "Translating"`: $MESSAGE" --as-stdout-line + ;; + --as-validating-line ) cli_printMessage "`gettext "Validating"`: $MESSAGE" --as-stdout-line ;; diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbook.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbook.sh index b4301b5..04448e2 100755 --- a/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbook.sh +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbook.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# locale_updateMessageXmlDocbook.sh -- This function retrives +# locale_updateMessageXmlDocbook.sh -- This function retrieves # translation messages from Docbook files and creates related portable # object template for them. # @@ -29,13 +29,6 @@ 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 - # Define regular expression to match extensions of shell scripts # we use inside the repository. local EXTENSION='docbook' @@ -45,53 +38,18 @@ function locale_updateMessageXmlDocbook { --maxdepth=1 --mindepth=1 --type='f' \ --pattern=".+/$(cli_getRepoName ${ACTIONVAL} -f)\.${EXTENSION}$") - # Verify existence of docbook's main template file. We cannot go - # on without it. - cli_checkFiles -e ${TEMPLATE} - - # Define file name used as template instance. Here is where we - # expand translation markers and entities before retrieving - # translation messages. - local INSTANCE=$(cli_getTemporalFile "$(basename ${TEMPLATE})") - - # Expand system entities definition. - cli_exportFunctions "Render/Docbook/docbook_doTranslation" - docbook_doTranslation - - # Expand translation markers inside instance. - cli_expandTMarkers ${INSTANCE} - - # Expand system entities definition. - cli_exportFunctions "Render/Docbook/docbook_expandSystemEntities" - docbook_expandSystemEntities ${INSTANCE} - - # Expand license block. - cli_exportFunctions "Render/Docbook/docbook_expandLicenses" - docbook_expandLicenses ${INSTANCE} - - # Create link to `Images' directory for validation to pass. - # Otherwise, a validation error is reported because no path was - # found to images. - ln -s ${TCAR_WORKDIR}/Identity/Images/Webenv $(dirname ${INSTANCE})/Images - - # 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 -l ${CLI_LANG_LC} - \ - | msgcat --output=${MESSAGES}.pot --width=70 --no-location - - - # Move out to initial location. - popd > /dev/null - - # Remove instance. - rm ${INSTANCE} - - # Verify, initialize or merge portable objects from portable - # object templates. - locale_updateMessagePObjects "${MESSAGES}" + # Process Docbook template files based on whether it is empty or + # not. When it is empty, it is because there is not a Docbook main + # file in the location provided to centos-art.sh script + # command-line. In this case, we try to create one POT file to all + # docbook files inside the location provided but without expanding + # entities. When Docbook template file is not empty, expand + # entities and create the POT file from a Docbook main file + # instance, with all entities expanded. + if [[ -z ${TEMPLATE} ]];then + locale_updateMessageXmlDocbookNoEntities + else + locale_updateMessageXmlDocbookWithEntities + fi } diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbookNoEntities.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbookNoEntities.sh new file mode 100755 index 0000000..67d6f75 --- /dev/null +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbookNoEntities.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# +# locale_updateMessageXmlDocbookNoEntities.sh -- This function creates +# an instance of one or more Docbook files without expanding entities +# inside it, retrieves all translatable strings from main file +# instance, and creates the related portable object template POT for +# them. This is useful to localize Docbook files that aren't direct +# part of a documentation manual but included at rendition time (e.g., +# Docbook files holding license information). +# +# 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_updateMessageXmlDocbookNoEntities { + + # In case no path to Docbook main file is not found, go deeper + # into the documentation models directory structure looking for + # files that do match the name of the directory who hold it, and + # use that file as template to initiate localization process. The + # way to reach these files have to be through --filter options + # because we want to respect the restrictions imposed by + # locale_isLocalizable function inside the repository. + # CAUTION: entity expansion the files found this way will be # ignored. + local TEMPLATES=$(cli_getFilesList ${ACTIONVAL} --type='f' \ + --pattern=".+/${FLAG_FILTER}.+\.${EXTENSION}$") + + # Verify number of template files found and define what kind of + # processing they are going to have. In case more than one + # template file be found and because entity expansion will be + # ignored in such case, the whole process of creating the PO file + # for all these templates is also different (simpler) from that we + # use with entity expansion. + + for TEMPLATE in ${TEMPLATES};do + + # Redefine path related to localization work directory. + local L10N_WORKDIR=$(cli_getLocalizationDir "$TEMPLATE") + + # 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 + + # Extract translatable strings from docbook files and merge + # them down into related messages file. + xml2po -a -l ${CLI_LANG_LL} -o ${MESSAGES}.pot ${TEMPLATE} + + # Verify, initialize or merge portable objects from portable + # object templates. + locale_updateMessagePObjects "${MESSAGES}" + + done + +} diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbookWithEntities.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbookWithEntities.sh new file mode 100755 index 0000000..9556e6b --- /dev/null +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbookWithEntities.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# +# locale_updateMessageXmlDocbookWithEntities.sh -- This function +# creates an instance of Docbook main file, expands entities inside +# it, retrieves all translatable strings from main file instance, and +# creates the related portable object template POT for them. +# +# 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_updateMessageXmlDocbookWithEntities { + + # 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 + + # Define file name used as template instance. Here is where we + # expand translation markers and entities before retrieving + # translation messages. + local INSTANCE=$(cli_getTemporalFile "$(basename ${TEMPLATE})") + + # Create the non-translated instance of design model. + cp ${TEMPLATE} ${INSTANCE} + + # Expand common contents inside instance. + cli_exportFunctions "Render/Docbook/docbook_expandLicenses" + docbook_expandLicenses ${INSTANCE} + + # When translated instances are rendered, system entities (e.g., + # `%entity-name;') don't appear in the translated instance (it + # seems that xml2po removes them) and this provokes DocBook + # validation to fail. So in order to pass the validation + # successfully and automate the whole creation of system entities, + # don't let this duty ion users'. Instead, make centos-art.sh + # script responsible of it. + cli_exportFunctions "Render/Docbook/docbook_expandSystemEntities" + docbook_expandSystemEntities ${INSTANCE} + + # Create portable object template from instance. Validate + # translated instance before processing it. This step is very + # important in order to detect document's malformations and warn + # you about it, so you can correct them. + xmllint --valid --noent ${INSTANCE} | xml2po -a -l ${CLI_LANG_LC} - \ + | msgcat --output=${MESSAGES}.pot \ + --width=70 --no-location - + + # Verify, initialize or merge portable objects from portable + # object templates. + locale_updateMessagePObjects "${MESSAGES}" + +} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook.sh b/Scripts/Bash/Functions/Render/Docbook/docbook.sh index c78c431..293dda1 100755 --- a/Scripts/Bash/Functions/Render/Docbook/docbook.sh +++ b/Scripts/Bash/Functions/Render/Docbook/docbook.sh @@ -37,9 +37,8 @@ function docbook { # Verify absolute path to DocBook models. cli_checkFiles ${DOCBOOK_MODELS} -d - # Apply translation to design model in order to produce the - # translated design model instance. - docbook_doTranslation + # Create the non-translated instance of design model. + cp ${TEMPLATE} ${INSTANCE} # Expand common contents inside instance. docbook_expandLicenses ${INSTANCE} @@ -74,9 +73,16 @@ function docbook { # entities already expanded. cli_expandTMarkers ${INSTANCE} + # Verify translation file existence apply translation to docbook + # design model instance in order to produce the translated design + # model instance. + if [[ -f ${TRANSLATION} ]];then + docbook_doTranslation ${INSTANCE} + fi + # Convert DocBook source files to other formats. - docbook_convertToXhtmlChunk - docbook_convertToXhtml + docbook_convertToXhtmlChunk ${INSTANCE} + docbook_convertToXhtml ${INSTANCE} docbook_convertToText # NOTE: The current transformation from DocBook to PDF fails when diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_convertToXhtml.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_convertToXhtml.sh index 35a7dcd..d750d8e 100755 --- a/Scripts/Bash/Functions/Render/Docbook/docbook_convertToXhtml.sh +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_convertToXhtml.sh @@ -42,7 +42,7 @@ function docbook_convertToXhtml { # Define absolute path to DocBook source file. This is the # repository documentation manual file where DOCTYPE and ENTITY # definition lines are set. - local SRC=${INSTANCE} + local SRC=${1} # Define absolute path to PDF target file. This is the final # location the PDF file produced as result of DocBook to PDF diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_convertToXhtmlChunk.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_convertToXhtmlChunk.sh index fab14e5..43933c9 100755 --- a/Scripts/Bash/Functions/Render/Docbook/docbook_convertToXhtmlChunk.sh +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_convertToXhtmlChunk.sh @@ -33,6 +33,11 @@ function docbook_convertToXhtmlChunk { local -a STYLE_INSTANCE local STYLE_INSTANCE_FINAL='' + # Define absolute path to DocBook source file. This is the + # repository documentation manual file where DOCTYPE and ENTITY + # definition lines are set. + local SRC=${1} + # Define absolute path to PDF target file. This is the final # location the PDF file produced as result of DocBook to PDF # transformation will be stored in. @@ -48,11 +53,6 @@ function docbook_convertToXhtmlChunk { # Print action message. cli_printMessage "${FILE}-xhtml" --as-creating-line - # Define absolute path to DocBook source file. This is the - # repository documentation manual file where DOCTYPE and ENTITY - # definition lines are set. - local SRC=${INSTANCE} - # Prepare XSL final instances used in transformations. docbook_prepareStyles $(cli_getFilesList \ ${DOCBOOK_XSL} --pattern='^.*/docbook2xhtml-(chunks|common)\.xsl$') diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_doTranslation.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_doTranslation.sh index f0e9ce8..ee53baa 100755 --- a/Scripts/Bash/Functions/Render/Docbook/docbook_doTranslation.sh +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_doTranslation.sh @@ -32,84 +32,58 @@ function docbook_doTranslation { - # Define which command will be used to output the template - # content. This is required because template files might be found - # as compressed files inside the repository. - local COMMAND="/bin/cat" - if [[ $(file -b -i $TEMPLATE) =~ '^application/x-gzip$' ]];then - COMMAND="/bin/zcat" - fi - - # Move into template's directory in order to satisfy relative - # entities. Take care that some XML documents (e.g., DocBook - # documents) can use entities relatively from their base - # locations. In order to process such documents, it is necessary - # to put the template directory up in the directory stack and - # create the instance from there. Thus, it is possible to expand - # relative entities correctly when validating the document. - pushd $(dirname $TEMPLATE) > /dev/null - - # Verify translation file existence and create template - # instance accordingly. - if [[ -f ${TRANSLATION} ]];then - - # Print final location of translation file. - cli_printMessage "${TRANSLATION}" --as-translation-line + # Print final location of translation file. + cli_printMessage "${TRANSLATION}" --as-translation-line - # Create translation instance to combine both template - # translation and licenses translations. - local TRANSLATION_INSTANCE=${TMPDIR}/messages.po + # Create translation instance to combine both template translation + # and licenses translations. + local TRANSLATION_INSTANCE=${TMPDIR}/messages.po - # Define path to DocBook locales using models as reference. - local DOCBOOK_LOCALES=$(cli_getLocalizationDir "$DOCBOOK_MODELS") - - # Define list of all locale files you want to combine. This - # include the localization files related to all different kind - # of licenses you want to use in the main documentation file - # and the localization file of the main documentation file, as - # well. - local DOCBOOK_PO_FILES="${TCAR_WORKDIR}/Locales/Documentation/Models/Docbook/Default/Licenses/Gfdl/${CLI_LANG_LC}/messages.po \ - ${TCAR_WORKDIR}/Locales/Documentation/Models/Docbook/Default/Licenses/Gpl/${CLI_LANG_LC}/messages.po \ - ${TRANSLATION}" - - # Be sure the files we want to combine do exist. - cli_checkFiles -e ${DOCBOOK_PO_FILES} - - # Combine license translations with template translation in - # order to reuse licenses translations in template files - # without including them in template portable objects. In the - # case of DocBook templates, translations related to licenses - # are required because license content is expanded at - # execution time inside the DocBook instance used by XSL - # processor during transformation. - msgcat --output=${TRANSLATION_INSTANCE} \ - --width=70 --no-location --use-first ${DOCBOOK_PO_FILES} - - # Create the translated instance of design model. - ${COMMAND} ${TEMPLATE} | xml2po -a -l ${CLI_LANG_LL} \ - -p ${TRANSLATION_INSTANCE} -o ${INSTANCE} - - - # Remove .xml2po.mo temporal file. - if [[ -f ${PWD}/.xml2po.mo ]];then - rm ${PWD}/.xml2po.mo - fi - - # Remove instance created to store both licenses and template - # translations. - if [[ -f ${TRANSLATION_INSTANCE} ]];then - rm ${TRANSLATION_INSTANCE} - fi - - else - - # Create the non-translated instance of design model. - ${COMMAND} ${TEMPLATE} > ${INSTANCE} - + # Define path to DocBook locales using models as reference. + local DOCBOOK_LOCALES=$(cli_getLocalizationDir "$DOCBOOK_MODELS") + + # Define list of all locale files you want to combine. This + # include the localization files related to all different kind of + # licenses you want to use in the main documentation file and the + # localization file of the main documentation file, as well. + local DOCBOOK_PO_FILES="${TCAR_WORKDIR}/Locales/Documentation/Models/Docbook/Default/Licenses/Gfdl/${CLI_LANG_LC}/messages.po \ + ${TCAR_WORKDIR}/Locales/Documentation/Models/Docbook/Default/Licenses/Gpl/${CLI_LANG_LC}/messages.po \ + ${TRANSLATION}" + + # Be sure the files we want to combine do exist. + cli_checkFiles -e ${DOCBOOK_PO_FILES} + + # Combine license translations with template translation in order + # to reuse licenses translations in template files without + # including them in template portable objects. In the case of + # DocBook templates, translations related to licenses are required + # because license content is expanded at execution time inside the + # DocBook instance used by XSL processor during transformation. + msgcat --output=${TRANSLATION_INSTANCE} \ + --width=70 --no-location --use-first ${DOCBOOK_PO_FILES} + + # At this point the translation instance with both licenses and + # manual translations have been saved. Now it is required to + # expand entities so it could be possible to create a translated + # instance with all the content inside. + + # Print action message. + cli_printMessage "${INSTANCE}" --as-translating-line + + # Create the translated instance of design model instance with all + # entities and translation markers expanded. + xml2po -a -l ${CLI_LANG_LL} \ + -p ${TRANSLATION_INSTANCE} \ + -o ${INSTANCE}-${CLI_LANG_LL}.tmp ${INSTANCE} + + # Rename final instance so it can be treated as just instance. + mv ${INSTANCE}-${CLI_LANG_LL}.tmp ${INSTANCE} + + # Remove .xml2po.mo temporal file. + if [[ -f ${PWD}/.xml2po.mo ]];then + rm ${PWD}/.xml2po.mo fi - # Return to where we were. - popd > /dev/null - # Verify instance existence. cli_checkFiles -e $INSTANCE