Blame Scripts/Bash/Functions/Locale/locale_updateMessageXmlDocbook.sh

0bd190
#!/bin/bash
0bd190
#
0bd190
# locale_updateMessageXmlDocbook.sh -- This function retrives
0bd190
# translation messages from Docbook files and creates related portable
0bd190
# object template for them.
0bd190
#
e6bbbf
# Copyright (C) 2009-2013 The CentOS Project
0bd190
#
0bd190
# This program is free software; you can redistribute it and/or modify
0bd190
# it under the terms of the GNU General Public License as published by
0bd190
# the Free Software Foundation; either version 2 of the License, or (at
0bd190
# your option) any later version.
0bd190
#
0bd190
# This program is distributed in the hope that it will be useful, but
0bd190
# WITHOUT ANY WARRANTY; without even the implied warranty of
0bd190
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0bd190
# General Public License for more details.
0bd190
#
0bd190
# You should have received a copy of the GNU General Public License
0bd190
# along with this program; if not, write to the Free Software
0bd190
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0bd190
#
0bd190
# ----------------------------------------------------------------------
e94a3a
# $Id$
0bd190
# ----------------------------------------------------------------------
0bd190
0bd190
function locale_updateMessageXmlDocbook {
0bd190
78487b
    # Define location where translation files will be stored in.
78487b
    local L10N_WORKDIR=$(cli_getLocalizationDir ${ACTIONVAL})
78487b
78487b
    # Define location of the file used to create both portable object
78487b
    # templates (.pot) and portable objects (.po) files.
78487b
    local MESSAGES="${L10N_WORKDIR}/messages"
78487b
0bd190
    # Print action message.
0bd190
    cli_printMessage "${MESSAGES}.pot" --as-updating-line
0bd190
096bac
    # Define regular expression to match extensions of shell scripts
096bac
    # we use inside the repository.
096bac
    local EXTENSION='docbook'
096bac
096bac
    # Define absolute paths to Docbook main file.
096bac
    local TEMPLATE=$(cli_getFilesList ${ACTIONVAL} \
096bac
        --maxdepth=1 --mindepth=1 --type='f' \
08b3a3
        --pattern=".+/$(cli_getRepoName ${ACTIONVAL} -f)\.${EXTENSION}$")
0bd190
0bd190
    # Verify existence of docbook's main template file. We cannot go
0bd190
    # on without it.
e94a3a
    cli_checkFiles -e ${TEMPLATE}
0bd190
0bd190
    # Define file name used as template instance. Here is where we
819c26
    # expand translation markers and entities before retrieving
0bd190
    # translation messages.
0bd190
    local INSTANCE=$(cli_getTemporalFile "$(basename ${TEMPLATE})")
0bd190
08b3a3
    # Expand system entities definition.
08b3a3
    cli_exportFunctions "Render/Docbook/docbook_doTranslation"
08b3a3
    docbook_doTranslation
0bd190
0bd190
    # Expand translation markers inside instance.
0bd190
    cli_expandTMarkers ${INSTANCE}
0bd190
0bd190
    # Expand system entities definition.
0bd190
    cli_exportFunctions "Render/Docbook/docbook_expandSystemEntities"
0bd190
    docbook_expandSystemEntities ${INSTANCE}
0bd190
0bd190
    # Expand license block.
0bd190
    cli_exportFunctions "Render/Docbook/docbook_expandLicenses"
0bd190
    docbook_expandLicenses ${INSTANCE}
0bd190
0bd190
    # Create link to `Images' directory for validation to pass.
0bd190
    # Otherwise, a validation error is reported because no path was
0bd190
    # found to images.
819c26
    ln -s ${TCAR_WORKDIR}/Identity/Images/Webenv $(dirname ${INSTANCE})/Images
0bd190
0bd190
    # Move into temporal directory so paths can be found relatively.
0bd190
    pushd $(dirname ${INSTANCE}) > /dev/null
0bd190
78487b
    # Prepare working directory to receive translation files.
78487b
    locale_prepareWorkingDirectory ${L10N_WORKDIR}
78487b
0bd190
    # Create portable object template from instance.
08b3a3
    xmllint --valid --noent ${INSTANCE} | xml2po -a -l ${CLI_LANG_LC} - \
0bd190
        | msgcat --output=${MESSAGES}.pot --width=70 --no-location -
0bd190
819c26
    # Move out to initial location.
0bd190
    popd > /dev/null
0bd190
0bd190
    # Remove instance.
0bd190
    rm ${INSTANCE}
0bd190
78487b
    # Verify, initialize or merge portable objects from portable
78487b
    # object templates.
78487b
    locale_updateMessagePObjects "${MESSAGES}"
78487b
0bd190
}