Blame Scripts/centos-art/Functions/Locale/locale.sh

4c79b5
#!/bin/bash
4c79b5
#
957ef9
# locale.sh -- This function provides internationalization features
80bc6f
# for centos-art.sh script through GNU gettext standard processes.
4c79b5
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
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
219a1a
    # Verify current locale information to avoid English messages from
219a1a
    # being localized to themselves.  The English language is used as
219a1a
    # reference to write translatable strings inside the source files.
f1a655
    if [[ $(cli_getCurrentLocale) =~ '^en' ]];then
219a1a
        cli_printMessage "`gettext "The English language cannot be localized to itself."`" --as-error-line
f1a655
    fi
f1a655
80bc6f
    local ACTIONNAMS=''
73abe0
    local ACTIONNAM=''
73abe0
    local ACTIONVAL=''
73abe0
219a1a
    # Initialize machine object flag (`--dont-create-mo').  This flag
219a1a
    # controls whether the centos-art.sh script does create/update
219a1a
    # machine object (MO) files from related portable object (PO)
219a1a
    # files or not. By default, MO files are created.
0d4faa
    local FLAG_DONT_CREATE_MO='false'
2b3016
80bc6f
    # Define localization (l10n) base directory. This is the place
34cd8d
    # where all translation messages are organized in. Translation
219a1a
    # messages are organized herein using the same layout of the
219a1a
    # components they represent under the `trunk/Identity',
219a1a
    # `trunk/Manuals' or `trunk/Scripts' directory structures.  The
219a1a
    # localization base directory must be used as source location for
219a1a
    # subversion operations (e.g., status, update, commit, etc.).
80bc6f
    # Otherwise, it would be difficult to add directory structures
80bc6f
    # that have several levels down from the localization base
80bc6f
    # directory up to the repository (e.g., it is not possible in
219a1a
    # subversion to add a directory which parent directory hasn't been
219a1a
    # added to the repository previously.).
a5d502
    L10N_BASEDIR="$(cli_getRepoTLDir)/L10n"
34cd8d
73abe0
    # Interpret arguments and options passed through command-line.
556c95
    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. 
219a1a
    eval set -- "${ARGUMENTS}"
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
219a1a
    # Loop through non-option arguments passed to centos-art.sh script
219a1a
    # through its command-line.
73abe0
    for ACTIONVAL in "$@";do
73abe0
219a1a
        # Sanitate non-option argument to be sure it matches the
219a1a
        # directory convenctions stablished by centos-art.sh script
219a1a
        # against source locations in the working copy.
219a1a
        ACTIONVAL=$(cli_checkRepoDirSource "${ACTIONVAL}")
73abe0
219a1a
        # Verify directory passed as non-option argument to be sure it
219a1a
        # supports localization.
219a1a
        if [[ ! $(cli_isLocalized "${ACTIONVAL}") == 'true' ]];then
219a1a
            cli_printMessage "`gettext "The path provided does not support localization."`" --as-error-line
c3e209
        fi
c3e209
219a1a
        # Define localization working directory using directory passed
219a1a
        # as non-option argument. The localization working directory
219a1a
        # is the place where POT and PO files are stored inside the
219a1a
        # working copy.
219a1a
        L10N_WORKDIR=$(echo "${ACTIONVAL}" \
219a1a
            | sed -r -e "s!trunk/(Identity|Scripts|Manuals)!trunk/L10n/\1!")/$(cli_getCurrentLocale)
219a1a
219a1a
        # Execute localization actions provided to centos-art.sh
219a1a
        # script through its command-line. Notice that localization
219a1a
        # actions will be executed in the same order they were
219a1a
        # provided in the command-line.
219a1a
        for ACTIONNAM in ${ACTIONNAMS};do
80bc6f
            ${ACTIONNAM}
80bc6f
        done
73abe0
73abe0
    done
4c79b5
3906a2
    # Syncronize changes between repository and working copy. At this
3906a2
    # point, changes in the repository are merged in the working copy
3906a2
    # and changes in the working copy committed up to repository.
3906a2
    cli_syncroRepoChanges "${L10N_BASEDIR}"
34cd8d
4c79b5
}