Blame Automation/Modules/Locale/locale_updateMessageShell.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# locale_updateMessageShell.sh -- This function parses shell scripts
Alain Reguera Delgado 8f60cb
# source files under action value and retrives translatable strings in
Alain Reguera Delgado 8f60cb
# order to creates/updates both the portable object template (.pot)
Alain Reguera Delgado 8f60cb
# and the portable object (.po) related.
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_updateMessageShell {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Print separator line.
Alain Reguera Delgado 8f60cb
    cli_printMessage '-' --as-separator-line
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='sh'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define list of absolute paths to function directories.
Alain Reguera Delgado 8f60cb
    local FNDIRS=$(cli_getFilesList ${ACTIONVAL}/Functions \
Alain Reguera Delgado 8f60cb
        --maxdepth=1 --mindepth=1 --type='d' --pattern="${ACTIONVAL}/${FLAG_FILTER}")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    for FNDIR in $FNDIRS;do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define absolute path to directory used as reference to store
Alain Reguera Delgado 8f60cb
        # portable objects.
Alain Reguera Delgado 8f60cb
        local L10N_WORKDIR=$(cli_getLocalizationDir "${FNDIR}")
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
        # Define absolute path to file used as reference to create
Alain Reguera Delgado 8f60cb
        # portable objects.
Alain Reguera Delgado 8f60cb
        local MESSAGES="${L10N_WORKDIR}/messages"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Print action message.
Alain Reguera Delgado 8f60cb
        cli_printMessage "${MESSAGES}.pot" --as-updating-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Build list of files to process. When you build the pattern,
Alain Reguera Delgado 8f60cb
        # be sure the value passed through `--filter' will be exactly
Alain Reguera Delgado 8f60cb
        # evaluated with the extension as prefix. Otherwise it would
Alain Reguera Delgado 8f60cb
        # be difficult to match files that share the same characters
Alain Reguera Delgado 8f60cb
        # in their file names (e.g., it would be difficult to match
Alain Reguera Delgado 8f60cb
        # only `hello.sh' if `hello-world.sh' also exists in the same
Alain Reguera Delgado 8f60cb
        # location).
Alain Reguera Delgado 8f60cb
        local FILES=$(cli_getFilesList ${FNDIR} --pattern="^.+\.${EXTENSION}$")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Retrieve translatable strings from shell script files and
Alain Reguera Delgado 8f60cb
        # create the portable object template (.pot) from them.
Alain Reguera Delgado 8f60cb
        xgettext --output=${MESSAGES}.pot \
Alain Reguera Delgado 8f60cb
            --copyright-holder="$(cli_printCopyrightInfo --holder)" \
Alain Reguera Delgado 8f60cb
            --width=70 --sort-by-file ${FILES}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Sanitate metadata inside the POT file.
Alain Reguera Delgado 8f60cb
        locale_updateMessageMetadata "${MESSAGES}.pot"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Verify, initialize or update 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
    # At this point some changes might be realized inside the PO file,
Alain Reguera Delgado 8f60cb
    # so we need to update the related MO file based on recently
Alain Reguera Delgado 8f60cb
    # updated PO files here in order for `centos-art.sh' script to
Alain Reguera Delgado 8f60cb
    # print out the most up to date revision of localized messages.
Alain Reguera Delgado 8f60cb
    # Notice that this is required only if we were localizaing shell
Alain Reguera Delgado 8f60cb
    # scripts.
Alain Reguera Delgado 8f60cb
    locale_updateMessageBinary
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}