Blame Scripts/Bash/Functions/Render/Svg/svg_doTranslation.sh

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