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

Alain Reguera Delgado 64aead
#!/bin/bash
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# docbook_setTranslation.sh -- This function standardizes the way
Alain Reguera Delgado 64aead
# translation files are applied to DocBook design models in order to
Alain Reguera Delgado 64aead
# produce the translated instance that is used to expand translation
Alain Reguera Delgado 64aead
# markers and produce different output formats.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# Assuming no translation file exists, an untranslated instance is
Alain Reguera Delgado 64aead
# taken from the design model and created (i.e., just a copy) from it.
Alain Reguera Delgado 64aead
# Using a design model instance (translated or not) is required in
Alain Reguera Delgado 64aead
# order to expand translation markers safely.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 64aead
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 64aead
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 64aead
# your option) any later version.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 64aead
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 64aead
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 64aead
# General Public License for more details.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 64aead
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 64aead
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# ----------------------------------------------------------------------
Alain Reguera Delgado 64aead
# $Id$
Alain Reguera Delgado 64aead
# ----------------------------------------------------------------------
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
function docbook_setTranslation {
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Print final location of translation file.
Alain Reguera Delgado 64aead
    cli_printMessage "${TRANSLATION}" --as-translation-line
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Create translation instance to combine both template translation
Alain Reguera Delgado 64aead
    # and licenses translations.
Alain Reguera Delgado 64aead
    local TRANSLATION_INSTANCE=${TMPDIR}/messages.po
Alain Reguera Delgado 64aead
    
Alain Reguera Delgado 64aead
    # Define path to DocBook locales using models as reference.
Alain Reguera Delgado 64aead
    local DOCBOOK_LOCALES=$(cli_getLocalizationDir "$DOCBOOK_MODELS")
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define list of all locale files you want to combine. This
Alain Reguera Delgado 64aead
    # include the localization files related to all different kind of
Alain Reguera Delgado 64aead
    # licenses you want to use in the main documentation file and the
Alain Reguera Delgado 64aead
    # localization file of the main documentation file, as well.
Alain Reguera Delgado 64aead
    local DOCBOOK_PO_FILES="${TCAR_WORKDIR}/Locales/Documentation/Models/Docbook/Default/Licenses/Gfdl/${CLI_LANG_LC}/messages.po \
Alain Reguera Delgado 64aead
        ${TCAR_WORKDIR}/Locales/Documentation/Models/Docbook/Default/Licenses/Gpl/${CLI_LANG_LC}/messages.po \
Alain Reguera Delgado 64aead
        ${TRANSLATION}"
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Be sure the files we want to combine do exist.
Alain Reguera Delgado 64aead
    cli_checkFiles -e ${DOCBOOK_PO_FILES}
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Combine license translations with template translation in order
Alain Reguera Delgado 64aead
    # to reuse licenses translations in template files without
Alain Reguera Delgado 64aead
    # including them in template portable objects. In the case of
Alain Reguera Delgado 64aead
    # DocBook templates, translations related to licenses are required
Alain Reguera Delgado 64aead
    # because license content is expanded at execution time inside the
Alain Reguera Delgado 64aead
    # DocBook instance used by XSL processor during transformation.
Alain Reguera Delgado 64aead
    msgcat --output=${TRANSLATION_INSTANCE} \
Alain Reguera Delgado 64aead
        --width=70 --no-location --use-first ${DOCBOOK_PO_FILES}
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # At this point the translation instance with both licenses and
Alain Reguera Delgado 64aead
    # manual translations have been saved. Now it is required to
Alain Reguera Delgado 64aead
    # expand entities so it could be possible to create a translated
Alain Reguera Delgado 64aead
    # instance with all the content inside.
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Print action message.
Alain Reguera Delgado 64aead
    cli_printMessage "${INSTANCE}" --as-translating-line
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Create the translated instance of design model instance with all
Alain Reguera Delgado 64aead
    # entities and translation markers expanded.
Alain Reguera Delgado 64aead
    xml2po -a -l ${CLI_LANG_LL} \
Alain Reguera Delgado 64aead
        -p ${TRANSLATION_INSTANCE} \
Alain Reguera Delgado 64aead
        -o ${INSTANCE}-${CLI_LANG_LL}.tmp ${INSTANCE}
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Rename final instance so it can be treated as just instance. 
Alain Reguera Delgado 64aead
    mv ${INSTANCE}-${CLI_LANG_LL}.tmp ${INSTANCE}
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Remove .xml2po.mo temporal file.
Alain Reguera Delgado 64aead
    if [[ -f ${PWD}/.xml2po.mo ]];then
Alain Reguera Delgado 64aead
        rm ${PWD}/.xml2po.mo
Alain Reguera Delgado 64aead
    fi
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Verify instance existence.
Alain Reguera Delgado 64aead
    cli_checkFiles -e $INSTANCE
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
}