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

878a2b
#!/bin/bash
878a2b
#
878a2b
# locale_updateMessageXml.sh -- This function parses XML-based files
878a2b
# (e.g., scalable vector graphics), retrives translatable strings and
878a2b
# creates/update gettext portable objects.
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function locale_updateMessageXml {
878a2b
878a2b
    # Print separator line.
878a2b
    cli_printMessage '-' --as-separator-line
878a2b
878a2b
    # Define filename used to create both portable object templates
878a2b
    # (.pot) and portable objects (.po) files.
878a2b
    local MESSAGES="${L10N_WORKDIR}/messages"
878a2b
878a2b
    # Define regular expression to match the file extension of all
878a2b
    # XML-based source files that can be localized inside the working
878a2b
    # copy.  Be aware that sometimes, source files and output files
878a2b
    # are stored in the same location (e.g., when rendering
878a2b
    # `tcar-ug.docbook' file the `tcar-ug.xhtml' is saved in the same
878a2b
    # location). Avoid using output files as if they were source
878a2b
    # files, when retriving translatable strings.
878a2b
    local EXTENSION='(svg|docbook)'
878a2b
878a2b
    # Build list of files to process. When building the patter, be
878a2b
    # sure the value passed through `--filter' be exactly evaluated
878a2b
    # with the extension as prefix. Otherwise it would be difficult to
878a2b
    # match files that share the same characters in their file names
878a2b
    # (e.g., it would be difficult to match only `hello.docbook' if
878a2b
    # `hello-world.docbook' also exists in the same location).
878a2b
    local FILES=$(cli_getFilesList ${ACTIONVAL} \
878a2b
        --pattern="${FLAG_FILTER}\.${EXTENSION}" \
878a2b
        --maxdepth='1' --type="f" \
878a2b
        | egrep -v '/[[:alpha:]]{2}_[[:alpha:]]{2}/')
878a2b
878a2b
    # Print action message.
878a2b
    cli_printMessage "${MESSAGES}.pot" --as-updating-line
878a2b
878a2b
    # Normalize XML files, expand entities before retriving
878a2b
    # translatable strings and create the portable object template
878a2b
    # (.pot) from such output.  The translatable strings are retrived
878a2b
    # from the normalized output of files, not files themselves
878a2b
    # (because of this, we don't include `#: filename:line' output on
878a2b
    # .pot files).  Entity expansion is also necessary for DocBook
878a2b
    # documents to be processed correctly. Notice that some long
878a2b
    # DocBook document structures might use entities to split the
878a2b
    # document structure into smaller pieces so they could be easier
878a2b
    # to maintain. Also, don't validate svg files the same way you
878a2b
    # validate docbook files; Docbook files have a DOCTYPE definition
878a2b
    # while svg files don't. Without a DOCTYPE definition, it isn't
878a2b
    # possible for `xmllint' to validate the document. 
878a2b
    if [[ $ACTIONVAL =~ '^.+/(branches|trunk)/Manuals/.+$' ]];then
878a2b
878a2b
        # Another issue to consider is the amount of source files that
878a2b
        # are being processed through xml2po. When there are more than
878a2b
        # one file, xml2po interprets only the first one and discards
878a2b
        # the rest in the list. This way, when more than one file
878a2b
        # exists in the list, it isn't convenient to provide xmllint's
878a2b
        # output to xml2po's input. Once here, we can say that
878a2b
        # in order to expand DocBook entities it is required that only
878a2b
        # one file must be provided at localization time (e.g., using
878a2b
        # the `--filter' option). Otherwise translation messages are
878a2b
        # retrived from all files, but no entity expansion is realized
878a2b
        # because xmllint wouldn't be used in such case.
878a2b
        if [[ $(echo "$FILES" | wc -l) -eq 1 ]];then
878a2b
878a2b
            xmllint --valid --noent ${FILES} | xml2po -a - \
878a2b
                | msgcat --output=${MESSAGES}.pot --width=70 --no-location -
878a2b
878a2b
        else
878a2b
878a2b
            xml2po -a ${FILES} \
878a2b
                | msgcat --output=${MESSAGES}.pot --width=70 --no-location -
878a2b
878a2b
        fi
878a2b
878a2b
    elif [[ $ACTIONVAL =~ '^.+/(branches|trunk)/Identity/Models/.+$' ]];then
878a2b
878a2b
        xml2po -a ${FILES} \
878a2b
            | msgcat --output=${MESSAGES}.pot --width=70 --no-location -
878a2b
878a2b
    else
878a2b
878a2b
        cli_printMessage "`gettext "The path provided doesn't support localization."`" --as-error-line
878a2b
878a2b
    fi
878a2b
878a2b
   # Verify, initialize or merge portable objects from portable object
878a2b
   # templates.
878a2b
   locale_updateMessagePObjects "${MESSAGES}"
878a2b
878a2b
}