Blame Automation/centos-art.sh-locale/locale_isLocalizable.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# locale_isLocalizable.sh -- This function determines whether a file
Alain Reguera Delgado 8f60cb
# or directory can have translation messages or not. This is the way
Alain Reguera Delgado 8f60cb
# we standardize what locations can and cannot be localized inside the
Alain Reguera Delgado 8f60cb
# repository.
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_isLocalizable {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local DIR=''
Alain Reguera Delgado 8f60cb
    local -a DIRS
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize location will use as reference to determine whether
Alain Reguera Delgado 8f60cb
    # it can have translation messages or not.
Alain Reguera Delgado 8f60cb
    local LOCATION="$1"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize answer value. By default all paths do not accept
Alain Reguera Delgado 8f60cb
    # localization.
Alain Reguera Delgado 8f60cb
    local L10N_ACCEPTED='no'
Alain Reguera Delgado 8f60cb
    
Alain Reguera Delgado 8f60cb
    # When no variable is passed to this function, use the action
Alain Reguera Delgado 8f60cb
    # value instead.
Alain Reguera Delgado 8f60cb
    if [[ $LOCATION == '' ]];then
Alain Reguera Delgado 8f60cb
        LOCATION=${ACTIONVAL}
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Redefine location to be sure we'll always evaluate a directory,
Alain Reguera Delgado 8f60cb
    # as reference location.
Alain Reguera Delgado 8f60cb
    if [[ -f $LOCATION ]];then
Alain Reguera Delgado 8f60cb
        LOCATION=$(dirname $LOCATION)
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify location existence. If it doesn't exist we cannot go on.
Alain Reguera Delgado 8f60cb
    cli_checkFiles -e $LOCATION
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize possible messages this function would print out.
Alain Reguera Delgado 8f60cb
    local -a MESSAGES
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define regular expression list of all directories inside the
Alain Reguera Delgado 8f60cb
    # repository that can have translation. Try to keep regular
Alain Reguera Delgado 8f60cb
    # expressions as simple as possible, so they can be understood by
Alain Reguera Delgado 8f60cb
    # sed program.
Alain Reguera Delgado 8f60cb
    DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Identity/Models/Themes/[[:alnum:]-]+/Distro/$(\
Alain Reguera Delgado 8f60cb
        cli_getPathComponent --release-pattern)/(Anaconda|Concept|Posters|Media)"
Alain Reguera Delgado 8f60cb
    DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Documentation/Models/Docbook/[[:alnum:]-]+"
Alain Reguera Delgado 8f60cb
    DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Documentation/Models/Svg/[[:alnum:]-]+"
Alain Reguera Delgado 8f60cb
    DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Scripts/Bash"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify location passed as first argument against the list of
Alain Reguera Delgado 8f60cb
    # directories that can have translation messages. By default, the
Alain Reguera Delgado 8f60cb
    # location passed as first argument is considered as a location
Alain Reguera Delgado 8f60cb
    # that cannot have translation messages until a positive answer
Alain Reguera Delgado 8f60cb
    # says otherwise.
Alain Reguera Delgado 8f60cb
    for DIR in ${DIRS[@]};do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define the path part which is not present in the
Alain Reguera Delgado 8f60cb
        # localizable directories.
Alain Reguera Delgado 8f60cb
        local PATHDIFF=$(echo ${LOCATION} | sed -r "s,${DIR}/,,")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define the path part that is present in the localizable
Alain Reguera Delgado 8f60cb
        # directories.
Alain Reguera Delgado 8f60cb
        local PATHSAME=$(echo ${LOCATION} | sed -r "s,/${PATHDIFF},,")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Initiate verification between location provided and
Alain Reguera Delgado 8f60cb
        # localizable directories.
Alain Reguera Delgado 8f60cb
        if [[ $LOCATION =~ "^$DIR$" ]];then
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # At this point the location provided is exactly the same
Alain Reguera Delgado 8f60cb
            # that matches the localizable directories. There is
Alain Reguera Delgado 8f60cb
            # nothing else to do here but return the script flow to
Alain Reguera Delgado 8f60cb
            # this function caller.
Alain Reguera Delgado 8f60cb
            L10N_ACCEPTED='yes' 
Alain Reguera Delgado 8f60cb
            break
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        elif [[ ${PATHSAME} =~ "^${DIR}" ]] && [[ -d ${LOCATION} ]];then
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # At this point the location provided is a directory in
Alain Reguera Delgado 8f60cb
            # the repository which doesn't match any localizable
Alain Reguera Delgado 8f60cb
            # directory in the list, but it could be rendered if the
Alain Reguera Delgado 8f60cb
            # --filter option is provided with the appropriate path
Alain Reguera Delgado 8f60cb
            # argument. Print a suggestion about it.
Alain Reguera Delgado 8f60cb
            cli_printMessage "${PATHSAME} --filter=\"$PATHDIFF\"" --as-suggestion-line
Alain Reguera Delgado 8f60cb
            break
Alain Reguera Delgado 8f60cb
            
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # At this point, we are safe to say that the path provided isn't
Alain Reguera Delgado 8f60cb
    # allow to have any localization for it. So, finish the script
Alain Reguera Delgado 8f60cb
    # execution with an error message.
Alain Reguera Delgado 8f60cb
    if [[ $L10N_ACCEPTED == 'no' ]];then
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "The path provided doesn't support localization."`" --as-error-line
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}