Blame Scripts/Bash/Functions/Render/Docbook/docbook_doTranslation.sh

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
#
e6bbbf
# Copyright (C) 2009-2013 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
814e83
    # Print final location of translation file.
814e83
    cli_printMessage "${TRANSLATION}" --as-translation-line
7fb679
814e83
    # Create translation instance to combine both template translation
814e83
    # and licenses translations.
814e83
    local TRANSLATION_INSTANCE=${TMPDIR}/messages.po
7fb679
    
814e83
    # Define path to DocBook locales using models as reference.
814e83
    local DOCBOOK_LOCALES=$(cli_getLocalizationDir "$DOCBOOK_MODELS")
814e83
814e83
    # Define list of all locale files you want to combine. This
814e83
    # include the localization files related to all different kind of
814e83
    # licenses you want to use in the main documentation file and the
814e83
    # localization file of the main documentation file, as well.
814e83
    local DOCBOOK_PO_FILES="${TCAR_WORKDIR}/Locales/Documentation/Models/Docbook/Default/Licenses/Gfdl/${CLI_LANG_LC}/messages.po \
814e83
        ${TCAR_WORKDIR}/Locales/Documentation/Models/Docbook/Default/Licenses/Gpl/${CLI_LANG_LC}/messages.po \
814e83
        ${TRANSLATION}"
814e83
814e83
    # Be sure the files we want to combine do exist.
814e83
    cli_checkFiles -e ${DOCBOOK_PO_FILES}
814e83
814e83
    # Combine license translations with template translation in order
814e83
    # to reuse licenses translations in template files without
814e83
    # including them in template portable objects. In the case of
814e83
    # DocBook templates, translations related to licenses are required
814e83
    # because license content is expanded at execution time inside the
814e83
    # DocBook instance used by XSL processor during transformation.
814e83
    msgcat --output=${TRANSLATION_INSTANCE} \
814e83
        --width=70 --no-location --use-first ${DOCBOOK_PO_FILES}
814e83
814e83
    # At this point the translation instance with both licenses and
814e83
    # manual translations have been saved. Now it is required to
814e83
    # expand entities so it could be possible to create a translated
814e83
    # instance with all the content inside.
814e83
814e83
    # Print action message.
814e83
    cli_printMessage "${INSTANCE}" --as-translating-line
814e83
814e83
    # Create the translated instance of design model instance with all
814e83
    # entities and translation markers expanded.
814e83
    xml2po -a -l ${CLI_LANG_LL} \
814e83
        -p ${TRANSLATION_INSTANCE} \
814e83
        -o ${INSTANCE}-${CLI_LANG_LL}.tmp ${INSTANCE}
814e83
814e83
    # Rename final instance so it can be treated as just instance. 
814e83
    mv ${INSTANCE}-${CLI_LANG_LL}.tmp ${INSTANCE}
814e83
814e83
    # Remove .xml2po.mo temporal file.
814e83
    if [[ -f ${PWD}/.xml2po.mo ]];then
814e83
        rm ${PWD}/.xml2po.mo
7fb679
    fi
7fb679
7fb679
    # Verify instance existence.
7fb679
    cli_checkFiles -e $INSTANCE
7fb679
7fb679
}