|
|
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 |
|
|
|
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.
|
|
|
483c3e |
local TRANSLATION_INSTANCE=$(cli_getTemporalFile ${TRANSLATION})
|
|
|
483c3e |
|
|
|
483c3e |
if [[ ${TEMPLATE} =~ "${TCAR_WORKDIR}/trunk/Documentation/.+$" ]];then
|
|
|
483c3e |
|
|
|
483c3e |
# Combine license translations with template translation
|
|
|
483c3e |
# in order to reuse licenses translations in template
|
|
|
483c3e |
# files without including them in template portable
|
|
|
483c3e |
# objects. In the case of Docbook templates, translations
|
|
|
483c3e |
# related to licenses are required because license content
|
|
|
483c3e |
# is expanded at execution time inside the docbook
|
|
|
483c3e |
# instance used by XSL processor during transformation.
|
|
|
483c3e |
cli_exportFunctions "Locale/locale_combineLicenseMessages"
|
|
|
483c3e |
locale_combineLicenseMessages ${TRANSLATION_INSTANCE} ${TRANSLATION}
|
|
|
483c3e |
|
|
|
878a2b |
else
|
|
|
483c3e |
|
|
|
483c3e |
# In the case of SVG and other files, license translations
|
|
|
483c3e |
# is not required so we don't combine it into the template
|
|
|
483c3e |
# translation.
|
|
|
483c3e |
cp ${TRANSLATION} ${TRANSLATION_INSTANCE}
|
|
|
483c3e |
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
483c3e |
# Create the translated instance of design model.
|
|
|
483c3e |
${COMMAND} ${TEMPLATE} | xml2po -a -l $(cli_getCurrentLocale) \
|
|
|
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.
|
|
|
878a2b |
cli_checkFiles $INSTANCE
|
|
|
878a2b |
|
|
|
878a2b |
}
|