Blame Scripts/Modules/Render/render_setLocalizedXml.sh

Alain Reguera Delgado 2c7b25
#!/bin/bash
Alain Reguera Delgado 2c7b25
######################################################################
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 25be94
#   tcar - The CentOS Artwork Repository automation tool.
Alain Reguera Delgado 25be94
#   Copyright © 2014 The CentOS Artwork SIG
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 25be94
#   This program is free software; you can redistribute it and/or
Alain Reguera Delgado 25be94
#   modify it under the terms of the GNU General Public License as
Alain Reguera Delgado 25be94
#   published by the Free Software Foundation; either version 2 of the
Alain Reguera Delgado 25be94
#   License, or (at your option) any later version.
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 25be94
#   This program is distributed in the hope that it will be useful,
Alain Reguera Delgado 25be94
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 25be94
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 25be94
#   General Public License for more details.
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 25be94
#   You should have received a copy of the GNU General Public License
Alain Reguera Delgado 25be94
#   along with this program; if not, write to the Free Software
Alain Reguera Delgado 25be94
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 25be94
#   Alain Reguera Delgado <al@centos.org.cu>
Alain Reguera Delgado 25be94
#   39 Street No. 4426 Cienfuegos, Cuba.
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 2c7b25
######################################################################
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 25be94
# Standardize the way (.po) translation files are applied to XML files
Alain Reguera Delgado 25be94
# (e.g., .docbook, .svg) in order to produce their related translated
Alain Reguera Delgado 25be94
# instances, used to expand translation markers and produce the final
Alain Reguera Delgado 25be94
# file format in different languages.  Assuming no translation file
Alain Reguera Delgado 25be94
# exists, an untranslated instance is taken from the design model and
Alain Reguera Delgado 25be94
# created (i.e., just a copy) from it.  Using a design model instance
Alain Reguera Delgado 25be94
# (translated or not) is required in order to expand translation
Alain Reguera Delgado 25be94
# markers safely.
Alain Reguera Delgado 2c7b25
function render_setLocalizedXml {
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Define absolute path to source instance.
Alain Reguera Delgado 2c7b25
    local SOURCE="${1}"
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Define absolute path to target instance.
Alain Reguera Delgado 2c7b25
    local TARGET="${2}"
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Verify source instance and the no-locale flag. When source
Alain Reguera Delgado 2c7b25
    # instance already exists, don't create a new file for it.
Alain Reguera Delgado 2c7b25
    # Instead, link it using a symbolic link. Be careful, such
Alain Reguera Delgado 2c7b25
    # behavior only applies when the source file has no locale.
Alain Reguera Delgado 2c7b25
    # Otherwise, the source file needs to go through the translation
Alain Reguera Delgado 2c7b25
    # process inevitably.
Alain Reguera Delgado 2c7b25
    if [[ -f ${SOURCE} ]];then
Alain Reguera Delgado 2c7b25
        if [[ ${SOURCE} =~ "^${TCAR_SCRIPT_TEMPDIR}" ]];then
Alain Reguera Delgado 2c7b25
            if [[ ${RENDER_FLAG_NO_LOCALE} == 'true'  ]];then
Alain Reguera Delgado 2c7b25
                tcar_checkFiles -i 'text/xml' ${SOURCE}
Alain Reguera Delgado 2c7b25
                /bin/ln -s ${SOURCE} ${TARGET}
Alain Reguera Delgado 2c7b25
                return
Alain Reguera Delgado 2c7b25
            fi
Alain Reguera Delgado 2c7b25
        elif [[ ${RENDER_FLAG_NO_LOCALE} == 'true' ]];then
Alain Reguera Delgado 2c7b25
            tcar_printFile ${SOURCE} > ${TARGET}
Alain Reguera Delgado 2c7b25
            tcar_checkFiles -i 'text/xml' ${TARGET}
Alain Reguera Delgado 2c7b25
            return
Alain Reguera Delgado 2c7b25
        fi
Alain Reguera Delgado 2c7b25
    fi
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Verify existence of translation files.
Alain Reguera Delgado 2c7b25
    tcar_checkFiles -efi 'text/x-po' ${TRANSLATIONS[*]}
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Define absolute path to translation instance.
Alain Reguera Delgado 2c7b25
    local TRANSLATION=$(tcar_getTemporalFile "messages.po")
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Combine available translations file into one translation
Alain Reguera Delgado 2c7b25
    # instance.
Alain Reguera Delgado 2c7b25
    msgcat -u -o ${TRANSLATION} ${TRANSLATIONS[*]}
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Verify existence of final location. In case it doesn't exist,
Alain Reguera Delgado 2c7b25
    # create it.
Alain Reguera Delgado 2c7b25
    if [[ $(dirname ${RENDER_TARGET}) ]];then
Alain Reguera Delgado 2c7b25
        mkdir -p $(dirname ${RENDER_TARGET})
Alain Reguera Delgado 2c7b25
    fi
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Move to final location before processing source file in order
Alain Reguera Delgado 2c7b25
    # for relative calls (e.g., image files) inside the source files
Alain Reguera Delgado 2c7b25
    # can be found by xml2po and no warning be printed from it.
Alain Reguera Delgado 2c7b25
    pushd $(dirname ${RENDER_TARGET}) > /dev/null
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Create the localized instance from design model.
Alain Reguera Delgado 2c7b25
    tcar_printFile ${SOURCE} | xml2po -a -l ${TCAR_SCRIPT_LANG_LC} \
Alain Reguera Delgado 2c7b25
        -p ${TRANSLATION} -o ${TARGET} -
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Remove .xml2po.mo temporal file.
Alain Reguera Delgado 2c7b25
    if [[ -f ./.xml2po.mo ]];then
Alain Reguera Delgado 2c7b25
        rm ./.xml2po.mo
Alain Reguera Delgado 2c7b25
    fi
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Return to previous location.
Alain Reguera Delgado 2c7b25
    popd > /dev/null
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Remove instance created to store template translations.
Alain Reguera Delgado 2c7b25
    if [[ -f ${TRANSLATION} ]];then
Alain Reguera Delgado 2c7b25
        rm ${TRANSLATION}
Alain Reguera Delgado 2c7b25
    fi
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
}