|
|
7fb679 |
#!/bin/bash
|
|
|
7fb679 |
#
|
|
|
7fb679 |
# docbook_doTranslation.sh -- This function standardizes the way
|
|
|
7fb679 |
# translation files are applied to DocBook design models in order to
|
|
|
7fb679 |
# produce the translated instance that is used to expand translation
|
|
|
7fb679 |
# markers and produce different output formats.
|
|
|
7fb679 |
#
|
|
|
819c26 |
# Assuming no translation file exists, an untranslated instance is
|
|
|
7fb679 |
# taken from the design model and created (i.e., just a copy) from it.
|
|
|
7fb679 |
# Using a design model instance (translated or not) is required in
|
|
|
819c26 |
# order to expand translation markers safely.
|
|
|
7fb679 |
#
|
|
|
7fb679 |
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
|
|
|
7fb679 |
#
|
|
|
7fb679 |
# This program is free software; you can redistribute it and/or modify
|
|
|
7fb679 |
# it under the terms of the GNU General Public License as published by
|
|
|
7fb679 |
# the Free Software Foundation; either version 2 of the License, or (at
|
|
|
7fb679 |
# your option) any later version.
|
|
|
7fb679 |
#
|
|
|
7fb679 |
# This program is distributed in the hope that it will be useful, but
|
|
|
7fb679 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7fb679 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
7fb679 |
# General Public License for more details.
|
|
|
7fb679 |
#
|
|
|
7fb679 |
# You should have received a copy of the GNU General Public License
|
|
|
7fb679 |
# along with this program; if not, write to the Free Software
|
|
|
7fb679 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
7fb679 |
#
|
|
|
7fb679 |
# ----------------------------------------------------------------------
|
|
|
7fb679 |
# $Id$
|
|
|
7fb679 |
# ----------------------------------------------------------------------
|
|
|
7fb679 |
|
|
|
7fb679 |
function docbook_doTranslation {
|
|
|
7fb679 |
|
|
|
7fb679 |
# Define which command will be used to output the template
|
|
|
7fb679 |
# content. This is required because template files might be found
|
|
|
7fb679 |
# as compressed files inside the repository.
|
|
|
7fb679 |
local COMMAND="/bin/cat"
|
|
|
7fb679 |
if [[ $(file -b -i $TEMPLATE) =~ '^application/x-gzip$' ]];then
|
|
|
7fb679 |
COMMAND="/bin/zcat"
|
|
|
7fb679 |
fi
|
|
|
7fb679 |
|
|
|
7fb679 |
# Move into template's directory in order to satisfy relative
|
|
|
7fb679 |
# entities. Take care that some XML documents (e.g., DocBook
|
|
|
7fb679 |
# documents) can use entities relatively from their base
|
|
|
7fb679 |
# locations. In order to process such documents, it is necessary
|
|
|
7fb679 |
# to put the template directory up in the directory stack and
|
|
|
7fb679 |
# create the instance from there. Thus, it is possible to expand
|
|
|
7fb679 |
# relative entities correctly when validating the document.
|
|
|
7fb679 |
pushd $(dirname $TEMPLATE) > /dev/null
|
|
|
7fb679 |
|
|
|
7fb679 |
# Verify translation file existence and create template
|
|
|
7fb679 |
# instance accordingly.
|
|
|
7fb679 |
if [[ -f ${TRANSLATION} ]];then
|
|
|
7fb679 |
|
|
|
7fb679 |
# Print final location of translation file.
|
|
|
7fb679 |
cli_printMessage "${TRANSLATION}" --as-translation-line
|
|
|
7fb679 |
|
|
|
7fb679 |
# Create translation instance to combine both template
|
|
|
7fb679 |
# translation and licenses translations.
|
|
|
7fb679 |
local TRANSLATION_INSTANCE=${TMPDIR}/message.po
|
|
|
7fb679 |
|
|
|
819c26 |
# Define path to DocBook locales using models as reference.
|
|
|
7fb679 |
local DOCBOOK_LOCALES=$(echo $DOCBOOK_MODELS \
|
|
|
819c26 |
| sed 's!^!Locales/!')
|
|
|
7fb679 |
|
|
|
7fb679 |
# Define list of all locale files you want to combine.
|
|
|
7fb679 |
local DOCBOOK_PO_FILES="${DOCBOOK_LOCALES}/Gpl/${CLI_LANG_LC}/messages.po \
|
|
|
7fb679 |
${DOCBOOK_LOCALES}/Gfdl/${CLI_LANG_LC}/messages.po \
|
|
|
7fb679 |
${TRANSLATION}"
|
|
|
7fb679 |
|
|
|
7fb679 |
# Be sure the files we want to combine do exist.
|
|
|
7fb679 |
cli_checkFiles -e ${DOCBOOK_PO_FILES}
|
|
|
7fb679 |
|
|
|
7fb679 |
# Combine license translations with template translation in
|
|
|
7fb679 |
# order to reuse licenses translations in template files
|
|
|
7fb679 |
# without including them in template portable objects. In the
|
|
|
819c26 |
# case of DocBook templates, translations related to licenses
|
|
|
7fb679 |
# are required because license content is expanded at
|
|
|
819c26 |
# execution time inside the DocBook instance used by XSL
|
|
|
7fb679 |
# processor during transformation.
|
|
|
7fb679 |
msgcat --output=${TRANSLATION_INSTANCE} \
|
|
|
7fb679 |
--width=70 --no-location --use-first ${DOCBOOK_PO_FILES}
|
|
|
7fb679 |
|
|
|
7fb679 |
# Create the translated instance of design model.
|
|
|
7fb679 |
${COMMAND} ${TEMPLATE} | xml2po -a -l ${CLI_LANG_LL} \
|
|
|
7fb679 |
-p ${TRANSLATION_INSTANCE} -o ${INSTANCE} -
|
|
|
7fb679 |
|
|
|
7fb679 |
# Remove .xml2po.mo temporal file.
|
|
|
7fb679 |
if [[ -f ${PWD}/.xml2po.mo ]];then
|
|
|
7fb679 |
rm ${PWD}/.xml2po.mo
|
|
|
7fb679 |
fi
|
|
|
7fb679 |
|
|
|
7fb679 |
# Remove instance created to store both licenses and template
|
|
|
7fb679 |
# translations.
|
|
|
7fb679 |
if [[ -f ${TRANSLATION_INSTANCE} ]];then
|
|
|
7fb679 |
rm ${TRANSLATION_INSTANCE}
|
|
|
7fb679 |
fi
|
|
|
7fb679 |
|
|
|
7fb679 |
else
|
|
|
7fb679 |
|
|
|
7fb679 |
# Create the non-translated instance of design model.
|
|
|
7fb679 |
${COMMAND} ${TEMPLATE} > ${INSTANCE}
|
|
|
7fb679 |
|
|
|
7fb679 |
fi
|
|
|
7fb679 |
|
|
|
7fb679 |
# Return to where we were.
|
|
|
7fb679 |
popd > /dev/null
|
|
|
7fb679 |
|
|
|
7fb679 |
# Verify instance existence.
|
|
|
7fb679 |
cli_checkFiles -e $INSTANCE
|
|
|
7fb679 |
|
|
|
7fb679 |
}
|