From 7fb67901130b669ade64e248b2f407331531e431 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Nov 03 2012 20:24:37 +0000 Subject: Update `render' functionality. --- diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook.sh b/Scripts/Bash/Functions/Render/Docbook/docbook.sh index 4290bce..623e2e7 100755 --- a/Scripts/Bash/Functions/Render/Docbook/docbook.sh +++ b/Scripts/Bash/Functions/Render/Docbook/docbook.sh @@ -32,6 +32,13 @@ function docbook { # Define absolute path to Docbook models. local DOCBOOK_MODELS="${TCAR_WORKDIR}/trunk/Documentation/Models/Docbook" + # Apply translation to design model in order to produce the + # translated design model instance. + docbook_doTranslation + + # Expand translation markers inside design model instance. + cli_expandTMarkers ${INSTANCE} + # Exapand common contents inside instance. docbook_expandLicenses ${INSTANCE} diff --git a/Scripts/Bash/Functions/Render/Docbook/docbook_doTranslation.sh b/Scripts/Bash/Functions/Render/Docbook/docbook_doTranslation.sh new file mode 100755 index 0000000..de6180c --- /dev/null +++ b/Scripts/Bash/Functions/Render/Docbook/docbook_doTranslation.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# +# docbook_doTranslation.sh -- This function standardizes the way +# translation files are applied to DocBook design models in order to +# produce the translated instance that is used to expand translation +# markers and produce different output formats. +# +# Assuming no translation file exists, an untranslated instace is +# taken from the design model and created (i.e., just a copy) from it. +# Using a design model instance (translated or not) is required in +# order to expand translation markers safetly. +# +# Copyright (C) 2009, 2010, 2011, 2012 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 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 + + # Create translation instance to combine both template + # translation and licenses translations. + local TRANSLATION_INSTANCE=${TMPDIR}/message.po + + # Define path to docbook locales using models as reference. + local DOCBOOK_LOCALES=$(echo $DOCBOOK_MODELS \ + | sed 's!trunk/!trunk/Locales/!') + + # Define list of all locale files you want to combine. + local DOCBOOK_PO_FILES="${DOCBOOK_LOCALES}/Gpl/${CLI_LANG_LC}/messages.po \ + ${DOCBOOK_LOCALES}/Gfdl/${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} + + fi + + # Return to where we were. + popd > /dev/null + + # Verify instance existence. + cli_checkFiles -e $INSTANCE + +} diff --git a/Scripts/Bash/Functions/Render/Svg/svg.sh b/Scripts/Bash/Functions/Render/Svg/svg.sh index 4cff8a2..7caef95 100755 --- a/Scripts/Bash/Functions/Render/Svg/svg.sh +++ b/Scripts/Bash/Functions/Render/Svg/svg.sh @@ -25,6 +25,13 @@ function svg { + # Apply translation to design model in order to produce the + # translated design model instance. + svg_doTranslation + + # Expand translation markers inside design model instance. + cli_expandTMarkers ${INSTANCE} + # Initialize the export id used inside design templates. This # value defines the design area we want to export. local EXPORTID='CENTOSARTWORK' diff --git a/Scripts/Bash/Functions/Render/Svg/svg_doTranslation.sh b/Scripts/Bash/Functions/Render/Svg/svg_doTranslation.sh new file mode 100755 index 0000000..65642a7 --- /dev/null +++ b/Scripts/Bash/Functions/Render/Svg/svg_doTranslation.sh @@ -0,0 +1,96 @@ +#!/bin/bash +# +# svg_doTranslation.sh -- This function standardizes the way +# translation files are applied to SVG design models in order to +# produce the translated instance that is used to expand translation +# markers and produce PNG output in different languages. +# +# Assuming no translation file exists, an untranslated instace is +# taken from the design model and created (i.e., just a copy) from it. +# Using a design model instance (translated or not) is required in +# order to expand translation markers safetly. +# +# Copyright (C) 2009, 2010, 2011, 2012 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 svg_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 + + # Create translation instance to combine both template + # translation and licenses translations. + local TRANSLATION_INSTANCE=${TMPDIR}/message.po + + # In the case of SVG and other files, license translations is + # not required so we don't combine it into the template + # translation. + cp ${TRANSLATION} ${TRANSLATION_INSTANCE} + + # 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} + + fi + + # Return to where we were. + popd > /dev/null + + # Verify instance existence. + cli_checkFiles -e $INSTANCE + +} diff --git a/Scripts/Bash/Functions/Render/render_doBaseActions.sh b/Scripts/Bash/Functions/Render/render_doBaseActions.sh index c25911b..3f38731 100755 --- a/Scripts/Bash/Functions/Render/render_doBaseActions.sh +++ b/Scripts/Bash/Functions/Render/render_doBaseActions.sh @@ -168,25 +168,23 @@ function render_doBaseActions { # Print separator line. cli_printMessage '-' --as-separator-line - # Define final location of translation file. - TRANSLATION=$(dirname $FILE \ - | sed -r 's!trunk/(Documentation|Identity)!trunk/Locales/\1!')/${CLI_LANG_LC}/messages.po - - # Define final location of template file. - TEMPLATE=${FILE} - # Verify design models file existence. We cannot continue # with out it. - if [[ ! -f $TEMPLATE ]];then - cli_printMessage "`gettext "The template file doesn't exist."`" --as-error-line - fi + cli_checkFiles ${FILE} -f # Print action message. - cli_printMessage "$TEMPLATE" --as-template-line - + cli_printMessage "${FILE}" --as-template-line + # Define final location of output directory. render_getDirOutput + # Define final location of translation file. + TRANSLATION=$(dirname ${FILE} \ + | sed -r 's!trunk/(Documentation|Identity)!trunk/Locales/\1!')/${CLI_LANG_LC}/messages.po + + # Define final location of template file. + TEMPLATE=${FILE} + # Get relative path to file. The path string (stored in # FILE) has two parts: 1. the variable path and 2. the # common path. The variable path is before the common @@ -225,13 +223,6 @@ function render_doBaseActions { # Define instance name from design model. INSTANCE=$(cli_getTemporalFile ${TEMPLATE}) - # Apply translation to design model in order to produce - # the translated design model instance. - render_doTranslation - - # Expand translation markers inside design model instance. - cli_expandTMarkers ${INSTANCE} - # Perform format base-rendition. ${RENDER_FORMAT} diff --git a/Scripts/Bash/Functions/Render/render_doTranslation.sh b/Scripts/Bash/Functions/Render/render_doTranslation.sh deleted file mode 100755 index c32022c..0000000 --- a/Scripts/Bash/Functions/Render/render_doTranslation.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/bash -# -# render_doTranslation.sh -- This function standardizes the way -# translation files are applied to design models in order to produce -# the translated instance that is used to expand translation markers -# and produce the base-rendition output. -# -# Assuming no translation file exists, an untranslated instace is -# taken from the design model and created (i.e., just a copy) from it. -# Using a design model instance (translated or not) is required in -# order to expand translation markers safetly. -# -# Copyright (C) 2009, 2010, 2011, 2012 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 render_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 - - # Create translation instance to combine both template - # translation and licenses translations. - local TRANSLATION_INSTANCE=${TMPDIR}/${TRANSLATION} - - if [[ ${TEMPLATE} =~ "${TCAR_WORKDIR}/trunk/Documentation/.+$" ]];then - - # 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. - cli_exportFunctions "Locale/locale_combineLicenseMessages" - locale_combineLicenseMessages ${TRANSLATION_INSTANCE} ${TRANSLATION} - - else - - # In the case of SVG and other files, license translations - # is not required so we don't combine it into the template - # translation. - cp ${TRANSLATION} ${TRANSLATION_INSTANCE} - - fi - - # 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} - - fi - - # Return to where we were. - popd > /dev/null - - # Verify instance existence. - cli_checkFiles -e $INSTANCE - -}