Blame Automation/centos-art.sh-mods/Render/Docbook/docbook_setTranslation.sh

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