Blame Automation/Modules/Render/render_setLocalizedXml.sh

Alain Reguera Delgado 2e37b0
#!/bin/bash
Alain Reguera Delgado 2e37b0
######################################################################
Alain Reguera Delgado 2e37b0
#
Alain Reguera Delgado 54b96d
#   render_setLocalizedXml.sh -- This function standardizes the way
Alain Reguera Delgado 54b96d
#   (.po) translation files are applied to XML files (e.g., .docbook,
Alain Reguera Delgado 54b96d
#   .svg) in order to produce their related translated instances, used
Alain Reguera Delgado 54b96d
#   to expand translation markers and produce the final file format in
Alain Reguera Delgado 54b96d
#   different languages.  Assuming no translation file exists, an
Alain Reguera Delgado 54b96d
#   untranslated instance is taken from the design model and created
Alain Reguera Delgado 54b96d
#   (i.e., just a copy) from it.  Using a design model instance
Alain Reguera Delgado 54b96d
#   (translated or not) is required in order to expand translation
Alain Reguera Delgado 54b96d
#   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 2b2258
    local TRANSLATION=$(tcar_getTemporalFile "messages.po")
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 54b96d
    # By default source instances are created inside /tmp directory
Alain Reguera Delgado 54b96d
    # and are localized before reaching base rendition.  In case a
Alain Reguera Delgado 54b96d
    # source instance is being used as source here, don't duplicate
Alain Reguera Delgado 54b96d
    # it.  Try to reuse it, instead.
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 54b96d
    if [[ ! ${SOURCE} =~ '^/tmp' ]];then
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 54b96d
        if [[ ${RENDER_FLAG_NO_LOCALE} != 'true' ]];then
Alain Reguera Delgado 2b2258
Alain Reguera Delgado 54b96d
            # Verify existence of translation files.
Alain Reguera Delgado 54b96d
            tcar_checkFiles -efi 'text/x-po' ${TRANSLATIONS[*]}
Alain Reguera Delgado 06b3a0
Alain Reguera Delgado 54b96d
            # Combine available translations file into one translation
Alain Reguera Delgado 54b96d
            # instance.
Alain Reguera Delgado 54b96d
            msgcat -u -o ${TRANSLATION} ${TRANSLATIONS[*]}
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 54b96d
            # Move to final location before processing source file in
Alain Reguera Delgado 54b96d
            # order for relative calls (e.g., image files) inside the
Alain Reguera Delgado 54b96d
            # source files can be found by xml2po and no warning be
Alain Reguera Delgado 54b96d
            # printed from it.
Alain Reguera Delgado 54b96d
            pushd $(dirname ${RENDER_TARGET}) > /dev/null
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 54b96d
            # Create the translated instance of design model.
Alain Reguera Delgado 54b96d
            tcar_printFile ${SOURCE} | xml2po -a -l ${TCAR_SCRIPT_LANG_LC} \
Alain Reguera Delgado 54b96d
                -p ${TRANSLATION} -o ${TARGET} -
Alain Reguera Delgado 65f472
Alain Reguera Delgado 54b96d
            # Remove .xml2po.mo temporal file.
Alain Reguera Delgado 54b96d
            if [[ -f ./.xml2po.mo ]];then
Alain Reguera Delgado 54b96d
                rm ./.xml2po.mo
Alain Reguera Delgado 54b96d
            fi
Alain Reguera Delgado 54b96d
Alain Reguera Delgado 54b96d
            # Return to previous location.
Alain Reguera Delgado 54b96d
            popd > /dev/null
Alain Reguera Delgado 54b96d
Alain Reguera Delgado 54b96d
            # Remove instance created to store both licenses and template
Alain Reguera Delgado 54b96d
            # translations.
Alain Reguera Delgado 54b96d
            if [[ -f ${TRANSLATION} ]];then
Alain Reguera Delgado 54b96d
                rm ${TRANSLATION}
Alain Reguera Delgado 54b96d
            fi
Alain Reguera Delgado 54b96d
Alain Reguera Delgado 54b96d
            # xml2po (gnome-doc-utils-0.8.0-2.fc6) bug? For some
Alain Reguera Delgado 54b96d
            # reason, xml2po is not adding the lang attribute to
Alain Reguera Delgado 54b96d
            # refentry tag, when producing manpages document types.
Alain Reguera Delgado 54b96d
            # This make intrinsic docbook construction for manpages
Alain Reguera Delgado 54b96d
            # like Name and Synopsis to be not localized.  This
Alain Reguera Delgado 54b96d
            # doesn't happens with article and
Alain Reguera Delgado 54b96d
            # book document types.
Alain Reguera Delgado 54b96d
            if [[ ${RENDER_FLOW} == 'manpage' ]];then
Alain Reguera Delgado 54b96d
                sed -i -r "s/<refentry>/<refentry lang=\"${TCAR_SCRIPT_LANG_LC}\">/" ${TARGET}
Alain Reguera Delgado 54b96d
            fi
Alain Reguera Delgado 54b96d
Alain Reguera Delgado 54b96d
        else
Alain Reguera Delgado 54b96d
Alain Reguera Delgado 54b96d
            tcar_printFile ${SOURCE} > ${TARGET}
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 06b3a0
        fi
Alain Reguera Delgado 06b3a0
Alain Reguera Delgado 54b96d
        # Make your best to be sure the file you've created is a valid
Alain Reguera Delgado 54b96d
        # XML file.
Alain Reguera Delgado 54b96d
        tcar_checkFiles -efi 'text/xml' ${TARGET}
Alain Reguera Delgado 54b96d
Alain Reguera Delgado 2e37b0
    else
Alain Reguera Delgado 2b2258
Alain Reguera Delgado 54b96d
        /bin/ln -s ${SOURCE} ${TARGET} 
Alain Reguera Delgado 54b96d
Alain Reguera Delgado 54b96d
        # Make your best to be sure the file you've linked is a valid
Alain Reguera Delgado 54b96d
        # XML file.
Alain Reguera Delgado 54b96d
        tcar_checkFiles -efi 'text/xml' ${SOURCE}
Alain Reguera Delgado 2b2258
Alain Reguera Delgado 2e37b0
    fi
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 2e37b0
}