Blame Automation/Modules/Render/render_setLocalizedXml.sh

Alain Reguera Delgado 2e37b0
#!/bin/bash
Alain Reguera Delgado 2e37b0
######################################################################
Alain Reguera Delgado 2e37b0
#
Alain Reguera Delgado 2e37b0
#   Modules/Render/Modules/Svg/Scripts/render_setLocalization.sh --
Alain Reguera Delgado 2e37b0
#   This function standardizes the way (.po) translation files are
Alain Reguera Delgado 2e37b0
#   applied to XML files (e.g., .docbook, .svg) in order to produce
Alain Reguera Delgado 2e37b0
#   their related translated instances, used to expand translation
Alain Reguera Delgado 2e37b0
#   markers and produce the final file format in different languages.
Alain Reguera Delgado 2e37b0
#   Assuming no translation file exists, an untranslated instance is
Alain Reguera Delgado 2e37b0
#   taken from the design model and created (i.e., just a copy) from
Alain Reguera Delgado 2e37b0
#   it.  Using a design model instance (translated or not) is required
Alain Reguera Delgado 2e37b0
#   in order to expand translation markers safely.
Alain Reguera Delgado 2e37b0
#
Alain Reguera Delgado 2e37b0
#   Written by:
Alain Reguera Delgado 2e37b0
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 2e37b0
#
Alain Reguera Delgado 809ecc
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 2e37b0
#
Alain Reguera Delgado 2e37b0
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 2e37b0
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 809ecc
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 809ecc
# your option) any later version.
Alain Reguera Delgado 2e37b0
#
Alain Reguera Delgado 2e37b0
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 2e37b0
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 2e37b0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 2e37b0
# General Public License for more details.
Alain Reguera Delgado 2e37b0
#
Alain Reguera Delgado 2e37b0
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 2e37b0
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 2e37b0
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 2e37b0
#
Alain Reguera Delgado 2e37b0
######################################################################
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2e37b0
function render_setLocalizedXml {
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2e37b0
    local SOURCE=${1}
Alain Reguera Delgado 2e37b0
    local TARGET=${2}
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2e37b0
    # Define which command will be used to output the template
Alain Reguera Delgado 2e37b0
    # content. This is required because template files might be found
Alain Reguera Delgado 2e37b0
    # as compressed files inside the repository.
Alain Reguera Delgado 2e37b0
    local COMMAND="/bin/cat"
Alain Reguera Delgado 2e37b0
    if [[ $(file -b -i ${SOURCES}) =~ '^application/x-gzip$' ]];then
Alain Reguera Delgado 2e37b0
        COMMAND="/bin/zcat"
Alain Reguera Delgado 2e37b0
    fi
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2e37b0
    if [[ -f ${TRANSLATIONS[0]} ]];then
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2e37b0
        # Define name of temporal file used as translation instance. 
Alain Reguera Delgado 2e37b0
        local TRANSLATION_INSTANCE=${TCAR_SCRIPT_TEMPDIR}/messages.po
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2e37b0
        # Combine translations into the translation instance.
Alain Reguera Delgado 2e37b0
        msgcat -u -o ${TRANSLATION_INSTANCE} ${TRANSLATIONS[*]}
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 06b3a0
        # Move to translation's directory before processing source
Alain Reguera Delgado 06b3a0
        # file in order for relative calls (e.g., image files) inside
Alain Reguera Delgado 06b3a0
        # the source files can be found by xml2po and no warning be
Alain Reguera Delgado 06b3a0
        # printed from it.
Alain Reguera Delgado 06b3a0
        pushd $(dirname ${TRANSLATIONS[0]}) > /dev/null
Alain Reguera Delgado 06b3a0
Alain Reguera Delgado 2e37b0
        # Create the translated instance of design model.
Alain Reguera Delgado 06b3a0
        ${COMMAND} ${SOURCE} | xml2po -a -l ${TCAR_SCRIPT_LANG_LC} \
Alain Reguera Delgado 2e37b0
            -p ${TRANSLATION_INSTANCE} -o ${TARGET} -
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2e37b0
        # Remove .xml2po.mo temporal file.
Alain Reguera Delgado 2e37b0
        if [[ -f ./.xml2po.mo ]];then
Alain Reguera Delgado 2e37b0
            rm ./.xml2po.mo
Alain Reguera Delgado 2e37b0
        fi
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 65f472
        # Return to previous location.
Alain Reguera Delgado 65f472
        popd > /dev/null
Alain Reguera Delgado 65f472
Alain Reguera Delgado 2e37b0
        # Remove instance created to store both licenses and template
Alain Reguera Delgado 2e37b0
        # translations.
Alain Reguera Delgado 2e37b0
        if [[ -f ${TRANSLATION_INSTANCE} ]];then
Alain Reguera Delgado 2e37b0
            rm ${TRANSLATION_INSTANCE}
Alain Reguera Delgado 2e37b0
        fi
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 06b3a0
        # xml2po bug? For some reason, xml2po is not adding the lang
Alain Reguera Delgado 06b3a0
        # attribute to refentry tag, when producing manpages document
Alain Reguera Delgado 06b3a0
        # types.  This make intrinsic docbook construction for
Alain Reguera Delgado 06b3a0
        # manpages like Name and Synopsis to be not localized.  This
Alain Reguera Delgado 06b3a0
        # doesn't happens with article and book document types.
Alain Reguera Delgado 06b3a0
        if [[ ${RENDER_FLOW} == 'manpage' ]];then
Alain Reguera Delgado 06b3a0
            sed -i -r "s/<refentry>/<refentry lang=\"${TCAR_SCRIPT_LANG_LC}\">/" ${TARGET}
Alain Reguera Delgado 06b3a0
        fi
Alain Reguera Delgado 06b3a0
Alain Reguera Delgado 2e37b0
    else
Alain Reguera Delgado 2e37b0
        ${COMMAND} ${SOURCE} > ${TARGET}
Alain Reguera Delgado 2e37b0
    fi
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2e37b0
}