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 2b2258
    if [[ $(/usr/bin/file -b -i ${SOURCE}) =~ '^application/x-gzip$' ]];then
Alain Reguera Delgado 2e37b0
        COMMAND="/bin/zcat"
Alain Reguera Delgado 2e37b0
    fi
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2b2258
    local TRANSLATION=$(tcar_getTemporalFile "messages.po")
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2b2258
    if [[ ${#TRANSLATIONS[*]} -gt 0 ]];then
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2b2258
        # Verify existence of translation files.
Alain Reguera Delgado 2b2258
        tcar_checkFiles -efi 'text/x-po' ${TRANSLATIONS[*]}
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2b2258
        # Combine available translations file into one translation
Alain Reguera Delgado 2b2258
        # instance.
Alain Reguera Delgado 2b2258
        msgcat -u -o ${TRANSLATION} ${TRANSLATIONS[*]}
Alain Reguera Delgado 2b2258
Alain Reguera Delgado 2b2258
        # Move to final location before processing source file in
Alain Reguera Delgado 2b2258
        # order for relative calls (e.g., image files) inside the
Alain Reguera Delgado 2b2258
        # source files can be found by xml2po and no warning be
Alain Reguera Delgado 06b3a0
        # printed from it.
Alain Reguera Delgado 2b2258
        pushd $(dirname ${RENDER_TARGET}) > /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 2b2258
            -p ${TRANSLATION} -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 2b2258
        if [[ -f ${TRANSLATION} ]];then
Alain Reguera Delgado 2b2258
            rm ${TRANSLATION}
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 2b2258
Alain Reguera Delgado 2e37b0
        ${COMMAND} ${SOURCE} > ${TARGET}
Alain Reguera Delgado 2b2258
Alain Reguera Delgado 2e37b0
    fi
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2e37b0
}