Blame Automation/centos-art.sh-render/Svg/svg_doTranslation.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# svg_doTranslation.sh -- This function standardizes the way
Alain Reguera Delgado 8f60cb
# translation files are applied to SVG design models in order to
Alain Reguera Delgado 8f60cb
# produce the translated instance that is used to expand translation
Alain Reguera Delgado 8f60cb
# markers and produce PNG output in different languages.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Assuming no translation file exists, an untranslated instace is
Alain Reguera Delgado 8f60cb
# taken from the design model and created (i.e., just a copy) from it.
Alain Reguera Delgado 8f60cb
# Using a design model instance (translated or not) is required in
Alain Reguera Delgado 8f60cb
# order to expand translation markers safetly.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function svg_doTranslation {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define which command will be used to output the template
Alain Reguera Delgado 8f60cb
    # content. This is required because template files might be found
Alain Reguera Delgado 8f60cb
    # as compressed files inside the repository.
Alain Reguera Delgado 8f60cb
    local COMMAND="/bin/cat"
Alain Reguera Delgado 8f60cb
    if [[ $(file -b -i $TEMPLATE) =~ '^application/x-gzip$' ]];then
Alain Reguera Delgado 8f60cb
        COMMAND="/bin/zcat"
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Move into template's directory in order to satisfy relative
Alain Reguera Delgado 8f60cb
    # entities.  Take care that some XML documents (e.g., DocBook
Alain Reguera Delgado 8f60cb
    # documents) can use entities relatively from their base
Alain Reguera Delgado 8f60cb
    # locations. In order to process such documents, it is necessary
Alain Reguera Delgado 8f60cb
    # to put the template directory up in the directory stack and
Alain Reguera Delgado 8f60cb
    # create the instance from there. Thus, it is possible to expand
Alain Reguera Delgado 8f60cb
    # relative entities correctly when validating the document.
Alain Reguera Delgado 8f60cb
    pushd $(dirname $TEMPLATE) > /dev/null
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify translation file existence and create template
Alain Reguera Delgado 8f60cb
    # instance accordingly.
Alain Reguera Delgado 8f60cb
    if [[ -f ${TRANSLATION} ]];then
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Print final location of translation file.
Alain Reguera Delgado 8f60cb
        cli_printMessage "${TRANSLATION}" --as-translation-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Create translation instance to combine both template
Alain Reguera Delgado 8f60cb
        # translation and licenses translations.
Alain Reguera Delgado 8f60cb
        local TRANSLATION_INSTANCE=${TMPDIR}/message.po
Alain Reguera Delgado 8f60cb
    
Alain Reguera Delgado 8f60cb
        # In the case of SVG and other files, license translations is
Alain Reguera Delgado 8f60cb
        # not required so we don't combine it into the template
Alain Reguera Delgado 8f60cb
        # translation.
Alain Reguera Delgado 8f60cb
        cp ${TRANSLATION} ${TRANSLATION_INSTANCE}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Create the translated instance of design model.
Alain Reguera Delgado 8f60cb
        ${COMMAND} ${TEMPLATE} | xml2po -a -l ${CLI_LANG_LL} \
Alain Reguera Delgado 8f60cb
            -p ${TRANSLATION_INSTANCE} -o ${INSTANCE} -
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Remove .xml2po.mo temporal file.
Alain Reguera Delgado 8f60cb
        if [[ -f ${PWD}/.xml2po.mo ]];then
Alain Reguera Delgado 8f60cb
            rm ${PWD}/.xml2po.mo
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Remove instance created to store both licenses and template
Alain Reguera Delgado 8f60cb
        # translations.
Alain Reguera Delgado 8f60cb
        if [[ -f ${TRANSLATION_INSTANCE} ]];then
Alain Reguera Delgado 8f60cb
            rm ${TRANSLATION_INSTANCE}
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    else
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Create the non-translated instance of design model. 
Alain Reguera Delgado 8f60cb
        ${COMMAND} ${TEMPLATE} > ${INSTANCE}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Return to where we were.
Alain Reguera Delgado 8f60cb
    popd > /dev/null
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify instance existence.
Alain Reguera Delgado 8f60cb
    cli_checkFiles -e $INSTANCE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}