Blame Scripts/Functions/Render/render_doTranslation.sh

57da3b
#!/bin/bash
57da3b
#
57da3b
# render_doTranslation.sh -- This function standardizes the way
57da3b
# translation files are applied to design models in order to produce
57da3b
# the translated instance that is used to expand translation markers
57da3b
# and produce the base-rendition output.
57da3b
#
57da3b
# Assuming no translation file exists, the an untranslated instace
57da3b
# from the design model is created (i.e., just a copy of it). Using a
57da3b
# design model instance (translated or not) is required in order to
57da3b
# expand translation markers safetly.
57da3b
#
3b0984
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
57da3b
#
57da3b
# This program is free software; you can redistribute it and/or modify
57da3b
# it under the terms of the GNU General Public License as published by
57da3b
# the Free Software Foundation; either version 2 of the License, or (at
57da3b
# your option) any later version.
57da3b
#
57da3b
# This program is distributed in the hope that it will be useful, but
57da3b
# WITHOUT ANY WARRANTY; without even the implied warranty of
57da3b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
57da3b
# General Public License for more details.
57da3b
#
57da3b
# You should have received a copy of the GNU General Public License
57da3b
# along with this program; if not, write to the Free Software
57da3b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
57da3b
#
57da3b
# ----------------------------------------------------------------------
57da3b
# $Id$
57da3b
# ----------------------------------------------------------------------
57da3b
57da3b
function render_doTranslation {
57da3b
57da3b
    # Verify translation file existence and create template
57da3b
    # instance accordingly.
57da3b
    if [[ -f ${TRANSLATION} ]];then
57da3b
6c620e
        # Print final location of translation file.
6c620e
        cli_printMessage "${TRANSLATION}" --as-translation-line
6c620e
9f1f50
        # Create the translated instance of design model based on
9f1f50
        # whether the template file has DOCTYPE definition or not.
6c620e
        if [[ ${TEMPLATE_HAS_DOCTYPE} -eq 0 ]];then
9f1f50
            xmllint --valid --noent ${TEMPLATE} \
9f1f50
                | xml2po -a -l $(cli_getCurrentLocale) -p ${TRANSLATION} -o ${INSTANCE} -
9f1f50
        else
9f1f50
            xml2po -a -l $(cli_getCurrentLocale) -p ${TRANSLATION} -o ${INSTANCE} ${TEMPLATE}
9f1f50
        fi
57da3b
57da3b
        # Remove .xml2po.mo temporal file.
57da3b
        if [[ -f ${PWD}/.xml2po.mo ]];then
57da3b
            rm ${PWD}/.xml2po.mo
57da3b
        fi
57da3b
57da3b
    else
57da3b
9f1f50
        # Create the non-translated instance of design model.
6c620e
        if [[ ${TEMPLATE_HAS_DOCTYPE} -eq 0 ]];then
9f1f50
            xmllint --valid --noent ${TEMPLATE} > ${INSTANCE}    
9f1f50
        else
9f1f50
            cp ${TEMPLATE} ${INSTANCE}
9f1f50
        fi
57da3b
57da3b
    fi
57da3b
9f1f50
    # Verify instance existence.
9f1f50
    cli_checkFiles $INSTANCE
9f1f50
57da3b
}