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
#
878a2b
# Assuming no translation file exists, the an untranslated instace
878a2b
# from the design model is created (i.e., just a copy of it). Using a
878a2b
# design model instance (translated or not) is required in order to
878a2b
# expand translation markers safetly.
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 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
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
878a2b
            xmllint --valid --noent ${TEMPLATE} \
878a2b
                | xml2po -a -l $(cli_getCurrentLocale) -p ${TRANSLATION} -o ${INSTANCE} -
878a2b
        else
878a2b
            xml2po -a -l $(cli_getCurrentLocale) -p ${TRANSLATION} -o ${INSTANCE} ${TEMPLATE}
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
878a2b
            xmllint --valid --noent ${TEMPLATE} > ${INSTANCE}    
878a2b
        else
878a2b
            cp ${TEMPLATE} ${INSTANCE}
878a2b
        fi
878a2b
878a2b
    fi
878a2b
878a2b
    # Verify instance existence.
878a2b
    cli_checkFiles $INSTANCE
878a2b
878a2b
}