Blame Scripts/Bash/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
0d4faa
# creates/update portable objects.
4e4b4d
#
4e4b4d
# Copyright (C) 2009-2011 Alain Reguera Delgado
4e4b4d
# 
4e4b4d
# This program is free software; you can redistribute it and/or
4e4b4d
# modify it under the terms of the GNU General Public License as
4e4b4d
# published by the Free Software Foundation; either version 2 of the
4e4b4d
# License, or (at your option) any later version.
4e4b4d
# 
4e4b4d
# This program is distributed in the hope that it will be useful, but
4e4b4d
# 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
4e4b4d
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4e4b4d
# USA.
4e4b4d
# 
4e4b4d
# ----------------------------------------------------------------------
4e4b4d
# $Id$
4e4b4d
# ----------------------------------------------------------------------
4e4b4d
4e4b4d
function locale_updateMessageXml {
4e4b4d
4e4b4d
    # Define name of file used to create both portable object
4e4b4d
    # templates (.pot) and portable objects (.po) files.
4e4b4d
    local FILE="${ACTIONVAL}/$(cli_getCurrentLocale)"
4e4b4d
0d4faa
    # Redefine filter pattern in order to reduce match to scalable
0d4faa
    # vector graphics only.
0d4faa
    local FLAG_FILTER="${FLAG_FILTER}.*\.(xml|svg)"
0d4faa
4e4b4d
    # Build list of XML-base files which we want retrive translatable
4e4b4d
    # strings from.
0d4faa
    cli_getFilesList
4e4b4d
0d4faa
    # Print action preamble.
4e4b4d
    cli_printActionPreamble "${FILES}" "doLocale" 'AsResponseLine'
4e4b4d
    
4e4b4d
    # Print action message.
4e4b4d
    cli_printMessage "${FILE}.pot" 'AsUpdatingLine'
4e4b4d
4e4b4d
    # Retrive translatable strings from XML-based files and
4e4b4d
    # create the portable object template (.pot) for them.
4e4b4d
    /usr/bin/xml2po ${FILES} \
4e4b4d
        | msgcat --output=${FILE}.pot --width=70 --sort-by-file -
4e4b4d
4e4b4d
    if [[ ! -f ${FILE}.po ]];then
4e4b4d
4e4b4d
        # Create portable object using portable object template, at
4e4b4d
        # the same time we use output to print the action message.
4e4b4d
        # There is no --quiet option for msginit command that let to
4e4b4d
        # separate both printing action message and creation command
4e4b4d
        # apart one from another).
4e4b4d
        cli_printMessage $(msginit -i ${FILE}.pot -o ${FILE}.po --width=70 \
4e4b4d
            --no-translator 2>&1 | cut -d' ' -f2 | sed -r 's!\.$!!') 'AsCreatingLine'
4e4b4d
4e4b4d
        # Sanitate portable object metadata.
4e4b4d
        locale_updateMessageMetadata "${FILE}.po"
4e4b4d
4e4b4d
    else
4e4b4d
4e4b4d
        # Print action message.
4e4b4d
        cli_printMessage "${FILE}.po" 'AsUpdatingLine'
4e4b4d
4e4b4d
        # Update portable object merging both portable object and
4e4b4d
        # portable object template.
4e4b4d
        msgmerge --output="${FILE}.po" "${FILE}.po" "${FILE}.pot" --quiet
4e4b4d
4e4b4d
    fi
4e4b4d
4e4b4d
}