Blame Scripts/Bash/Functions/Render/render_doTranslation.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# render_doTranslation.sh -- This function standardizes the way
878a2b
# translation files are applied to design models in order to produce
878a2b
# the translated instance that is used to expand translation markers
878a2b
# and produce the base-rendition output.
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
878a2b
function render_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
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
878a2b
        # Create the translated instance of design model based on
878a2b
        # whether the template file has DOCTYPE definition or not.
878a2b
        if [[ ${TEMPLATE_HAS_DOCTYPE} -eq 0 ]];then
56cf52
            ${COMMAND} ${TEMPLATE} | xmllint --valid --noent - \
878a2b
                | xml2po -a -l $(cli_getCurrentLocale) -p ${TRANSLATION} -o ${INSTANCE} -
878a2b
        else
56cf52
            ${COMMAND} ${TEMPLATE} | xml2po -a -l $(cli_getCurrentLocale) \
56cf52
                -p ${TRANSLATION} -o ${INSTANCE} -
878a2b
        fi
878a2b
878a2b
        # Remove .xml2po.mo temporal file.
878a2b
        if [[ -f ${PWD}/.xml2po.mo ]];then
878a2b
            rm ${PWD}/.xml2po.mo
878a2b
        fi
878a2b
878a2b
    else
878a2b
878a2b
        # Create the non-translated instance of design model.
878a2b
        if [[ ${TEMPLATE_HAS_DOCTYPE} -eq 0 ]];then
606cf3
            ${COMMAND} ${TEMPLATE} | xmllint --valid --noent - > ${INSTANCE}    
878a2b
        else
56cf52
            ${COMMAND} ${TEMPLATE} > ${INSTANCE}
878a2b
        fi
878a2b
878a2b
    fi
878a2b
878a2b
    # Verify instance existence.
878a2b
    cli_checkFiles $INSTANCE
878a2b
878a2b
}