Blame Scripts/Functions/Locale/locale_updateMessageXml.sh

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