Blame Automation/Modules/Locale/locale_updateMessageXmlSvg.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# locale_updateMessageXmlSvg.sh -- This function parses XML-based
Alain Reguera Delgado 8f60cb
# files (e.g., scalable vector graphics), retrieves translatable
Alain Reguera Delgado 8f60cb
# strings and creates/update gettext portable objects.
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 locale_updateMessageXmlSvg {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Inside `Identity/Models' and Documentation/Models/Svg/, design
Alain Reguera Delgado 8f60cb
    # models can be compressed or uncompressed. Because of this we
Alain Reguera Delgado 8f60cb
    # cannot process all the design models in one unique way. Instead,
Alain Reguera Delgado 8f60cb
    # we need to treat them individually based on their file type.
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local DIR=''
Alain Reguera Delgado 8f60cb
    local DIRS=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define regular expression to match extensions of shell scripts
Alain Reguera Delgado 8f60cb
    # we use inside the repository.
Alain Reguera Delgado 8f60cb
    local EXTENSION='(svgz|svg)'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Build list of directories in which we want to look files for.
Alain Reguera Delgado 8f60cb
    local DIRS=$(cli_getFilesList ${ACTIONVAL} \
Alain Reguera Delgado 8f60cb
        --pattern="${ACTIONVAL}/${FLAG_FILTER}")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Process list of directories, one by one.
Alain Reguera Delgado 8f60cb
    for DIR in $DIRS;do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Reset information related to temporal files.
Alain Reguera Delgado 8f60cb
        local TEMPFILE=''
Alain Reguera Delgado 8f60cb
        local TEMPFILES=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Redefine localization working directory using the current
Alain Reguera Delgado 8f60cb
        # directory. The localization working directory is the place
Alain Reguera Delgado 8f60cb
        # where POT and PO files are stored inside the working copy.
Alain Reguera Delgado 8f60cb
        local L10N_WORKDIR=$(cli_getLocalizationDir "${DIR}")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Prepare working directory to receive translation files.
Alain Reguera Delgado 8f60cb
        locale_prepareWorkingDirectory ${L10N_WORKDIR}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Redefine final location of messages.po file, based on
Alain Reguera Delgado 8f60cb
        # current directory.
Alain Reguera Delgado 8f60cb
        MESSAGES=${L10N_WORKDIR}/messages
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Build list of files we want to work with.
Alain Reguera Delgado 8f60cb
        FILES=$(cli_getFilesList ${DIR} --pattern="${DIR}/.+\.${EXTENSION}")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        for FILE in $FILES;do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Redefine temporal file based on file been processed.
Alain Reguera Delgado 8f60cb
            TEMPFILE=$(cli_getTemporalFile $(basename ${FILE}))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Update the command used to read content of XML files.
Alain Reguera Delgado 8f60cb
            if [[ $(file -b -i $FILE) =~ '^application/x-gzip$' ]];then
Alain Reguera Delgado 8f60cb
        
Alain Reguera Delgado 8f60cb
                # Create uncompressed copy of file.
Alain Reguera Delgado 8f60cb
                /bin/zcat $FILE > $TEMPFILE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            else
Alain Reguera Delgado 8f60cb
                
Alain Reguera Delgado 8f60cb
                # Create uncompressed copy of file.
Alain Reguera Delgado 8f60cb
                /bin/cat $FILE > $TEMPFILE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Concatenate temporal files into a list so we can process
Alain Reguera Delgado 8f60cb
            # them later through xml2po, all at once.
Alain Reguera Delgado 8f60cb
            TEMPFILES="${TEMPFILE} ${TEMPFILES}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Create the portable object template.
Alain Reguera Delgado 8f60cb
        cat $TEMPFILES | xml2po -a -l ${CLI_LANG_LC} - \
Alain Reguera Delgado 8f60cb
            | msgcat --output=${MESSAGES}.pot --width=70 --no-location -
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Verify, initialize or merge portable objects from portable
Alain Reguera Delgado 8f60cb
        # object templates.
Alain Reguera Delgado 8f60cb
        locale_updateMessagePObjects "${MESSAGES}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}