Blame Scripts/Functions/Locale/locale.sh

4c79b5
#!/bin/bash
4c79b5
#
957ef9
# locale.sh -- This function provides internationalization features
957ef9
# for centos-art.sh script through gettext standard processes.
4c79b5
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
4c79b5
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function locale {
4c79b5
73abe0
    local ACTIONNAM=''
73abe0
    local ACTIONVAL=''
73abe0
2b3016
    # Initialize default value to create/update machine object flag.
bf6bff
    # The machine object flag (--dont-create-mo) controls whether
bf6bff
    # centos-art.sh script does create/update the machine object
bf6bff
    # related object or not.
0d4faa
    local FLAG_DONT_CREATE_MO='false'
2b3016
73abe0
    # Interpret arguments and options passed through command-line.
73abe0
    locale_getArguments
73abe0
73abe0
    # Redefine positional parameters using ARGUMENTS. At this point,
73abe0
    # option arguments have been removed from ARGUMENTS variable and
73abe0
    # only non-option arguments remain in it. 
73abe0
    eval set -- "$ARGUMENTS"
73abe0
73abe0
    # Define action name. It does matter what option be passed to
73abe0
    # centos-art, there are many different actions to perform based on
73abe0
    # the option passed (e.g., `--edit', `--read', `--search', etc.).
73abe0
    # In that sake, we defined action name inside document_getArguments,
73abe0
    # at the moment of interpreting options.
73abe0
73abe0
    # Define action value. As convenction, we use non-option arguments
73abe0
    # to define the action value (ACTIONVAL) variable.
73abe0
    for ACTIONVAL in "$@";do
73abe0
73abe0
        if [[ $ACTIONVAL == '--' ]];then
73abe0
            continue
73abe0
        fi
73abe0
73abe0
        # Check action value. Be sure the action value matches the
73abe0
        # convenctions defined for source locations inside the working
73abe0
        # copy.
73abe0
        cli_checkRepoDirSource
73abe0
ed2bf0
        # Define base directory where locale directory structures will
ed2bf0
        # be stored in.
ed2bf0
        BASEDIR="$(cli_getRepoTLDir)/Locales"
ed2bf0
ed2bf0
        # Define work directory. This is the place where locales
ed2bf0
        # directories will be stored in.
ed2bf0
        WORKDIR=$(echo ${ACTIONVAL} \
ed2bf0
            | sed -r -e "s!.+/trunk/(Identity|Manual|Scripts)!${BASEDIR}/\1!")
ed2bf0
ed2bf0
        # Add current locale to work directory. This is the place
ed2bf0
        # where parent directories specific translation messages
ed2bf0
        # (e.g., the .po, .pot and .mo files) will be stored in.  The
ed2bf0
        # `locale' functionality creates translation messages for all
ed2bf0
        # translatable files inside the parent directory and never for
ed2bf0
        # individual files inside the same parent directory.
ed2bf0
        WORKDIR=$WORKDIR/$(cli_getCurrentLocale)
ed2bf0
ed2bf0
        # Create work directory if it doesn't exist.
73abe0
        if [[ ! -d $WORKDIR ]];then
73abe0
            mkdir -p $WORKDIR
73abe0
        fi
73abe0
73abe0
        # Syncronize changes between repository and working copy. At
73abe0
        # this point, changes in the repository are merged in the
73abe0
        # working copy and changes in the working copy committed up to
73abe0
        # repository.
73abe0
        cli_syncroRepoChanges "${WORKDIR}"
73abe0
73abe0
        # Execute action name.
73abe0
        if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then
73abe0
            eval $ACTIONNAM
73abe0
        else
73abe0
            cli_printMessage "`gettext "A valid action is required."`" 'AsErrorLine'
eee226
            cli_printMessage "${FUNCDIRNAM}" 'AsToKnowMoreLine'
73abe0
        fi
73abe0
73abe0
        # Commit changes from working copy to central repository only.
73abe0
        # At this point, changes in the repository are not merged in
73abe0
        # the working copy, but chages in the working copy do are
73abe0
        # committed up to repository.
73abe0
        cli_commitRepoChanges "${WORKDIR}"
73abe0
73abe0
    done
4c79b5
4c79b5
}