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
#
3b0984
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
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
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
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function locale {
4c79b5
f1a655
    # Do not locale messages for English language. The English
f1a655
    # language is already used as translation pattern and there is no
f1a655
    # translation messages for it.
f1a655
    if [[ $(cli_getCurrentLocale) =~ '^en' ]];then
510fad
        cli_printMessage "`gettext "Cannot locale English language to itself."`" --as-error-line
f1a655
    fi
f1a655
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
34cd8d
    # Define localization (l10n) base directory. This is the location
34cd8d
    # where all translation messages are organized in. Translation
34cd8d
    # messages, here, are organized using the same order of the
34cd8d
    # components they represent inside the `trunk/Identity',
34cd8d
    # `trunk/Manuals' or `trunk/Scripts' directory structures.
34cd8d
    # Moreover, the localization base directory must be used as source
34cd8d
    # location for subverion operations (e.g., status, update, commit,
34cd8d
    # etc.).  Otherwise, it would be difficult to add directory
34cd8d
    # structures that have several levels down from the localization
34cd8d
    # base directory up to the repository (e.g., it is not possible in
34cd8d
    # subversion to add a directory structure which parent directory
34cd8d
    # structure hasn't been added to the repository, previously.).
a5d502
    L10N_BASEDIR="$(cli_getRepoTLDir)/L10n"
34cd8d
73abe0
    # Interpret arguments and options passed through command-line.
9fe4a2
    locale_getOptions
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
34cd8d
    # Syncronize changes between repository and working copy. At this
34cd8d
    # point, changes in the repository are merged in the working copy
34cd8d
    # and changes in the working copy committed up to repository.
34cd8d
    cli_syncroRepoChanges "${L10N_BASEDIR}"
34cd8d
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
        # Check action value. Be sure the action value matches the
73abe0
        # convenctions defined for source locations inside the working
73abe0
        # copy.
dc2f3c
        ACTIONVAL=$(cli_checkRepoDirSource $ACTIONVAL)
73abe0
c3e209
        # Verify whether the directory provided can have localization
c3e209
        # messages or not.
c3e209
        if [[ ! $(cli_hasLocalization $ACTIONVAL) == 'true' ]];then
c3e209
            cli_printMessage "`gettext "The path provided doesn't support localization."`" --as-error-line
c3e209
        fi
c3e209
ed2bf0
        # Define work directory. This is the place where locales
ed2bf0
        # directories will be stored in.
ed2bf0
        WORKDIR=$(echo ${ACTIONVAL} \
a5d502
            | sed -r -e "s!trunk/(Identity|Scripts|Manuals)!trunk/L10n/\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
34cd8d
        # Prepare working direcotry to receive .po files.
34cd8d
        if [[ ! -d ${WORKDIR} ]];then
34cd8d
34cd8d
            # Print separator line.
34cd8d
            cli_printMessage "-" --as-separator-line
34cd8d
34cd8d
            # Output action message.
34cd8d
            cli_printMessage "${WORKDIR}" --as-creating-line
34cd8d
34cd8d
            # Create directory making parent directories as needed.
34cd8d
            mkdir -p ${WORKDIR}
34cd8d
34cd8d
            # Commit changes from working copy to central repository
34cd8d
            # only.  At this point, changes in the repository are not
34cd8d
            # merged in the working copy, but chages in the working
34cd8d
            # copy do are committed up to repository.
34cd8d
            cli_commitRepoChanges "${L10N_BASEDIR}"
34cd8d
34cd8d
        fi
73abe0
73abe0
        # Execute action name.
73abe0
        if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then
73abe0
            eval $ACTIONNAM
73abe0
        else
510fad
            cli_printMessage "`gettext "A valid action is required."`" --as-error-line
73abe0
        fi
73abe0
73abe0
    done
4c79b5
34cd8d
    # Commit changes from working copy to central repository only.  At
34cd8d
    # this point, changes in the repository are not merged in the
34cd8d
    # working copy, but chages in the working copy do are committed up
34cd8d
    # to repository.
34cd8d
    cli_commitRepoChanges "${L10N_BASEDIR}"
34cd8d
4c79b5
}