Blame Scripts/Bash/Functions/Locale/locale_isLocalizable.sh

878a2b
#!/bin/bash
878a2b
#
08b3a3
# locale_isLocalizable.sh -- This function determines whether a file
08b3a3
# or directory can have translation messages or not. This is the way
08b3a3
# we standardize what locations can and cannot be localized inside the
08b3a3
# repository.
878a2b
#
e6bbbf
# Copyright (C) 2009-2013 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
73bb34
function locale_isLocalizable {
878a2b
878a2b
    local DIR=''
878a2b
    local -a DIRS
878a2b
878a2b
    # Initialize location will use as reference to determine whether
878a2b
    # it can have translation messages or not.
878a2b
    local LOCATION="$1"
08b3a3
08b3a3
    # Initialize answer value. By default all paths do not accept
08b3a3
    # localization.
08b3a3
    local L10N_ACCEPTED='no'
1dcaa7
    
1dcaa7
    # When no variable is passed to this function, use the action
1dcaa7
    # value instead.
1dcaa7
    if [[ $LOCATION == '' ]];then
1dcaa7
        LOCATION=${ACTIONVAL}
1dcaa7
    fi
878a2b
878a2b
    # Redefine location to be sure we'll always evaluate a directory,
878a2b
    # as reference location.
878a2b
    if [[ -f $LOCATION ]];then
878a2b
        LOCATION=$(dirname $LOCATION)
878a2b
    fi
878a2b
878a2b
    # Verify location existence. If it doesn't exist we cannot go on.
aed54d
    cli_checkFiles -e $LOCATION
878a2b
08b3a3
    # Initialize possible messages this function would print out.
08b3a3
    local -a MESSAGES
08b3a3
819c26
    # Define regular expression list of all directories inside the
08b3a3
    # repository that can have translation. Try to keep regular
08b3a3
    # expressions as simple as possible, so they can be understood by
08b3a3
    # sed program.
08b3a3
    DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Identity/Models/Themes/[[:alnum:]-]+/Distro/$(\
08b3a3
        cli_getPathComponent --release-pattern)/(Anaconda|Concept|Posters|Media)"
08b3a3
    DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Documentation/Models/Docbook/[[:alnum:]-]+"
08b3a3
    DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Documentation/Models/Svg/[[:alnum:]-]+"
08b3a3
    DIRS[++((${#DIRS[*]}))]="${TCAR_WORKDIR}/Scripts/Bash"
878a2b
819c26
    # Verify location passed as first argument against the list of
878a2b
    # directories that can have translation messages. By default, the
878a2b
    # location passed as first argument is considered as a location
878a2b
    # that cannot have translation messages until a positive answer
878a2b
    # says otherwise.
878a2b
    for DIR in ${DIRS[@]};do
08b3a3
08b3a3
        # Define the path part which is not present in the
08b3a3
        # localizable directories.
08b3a3
        local PATHDIFF=$(echo ${LOCATION} | sed -r "s,${DIR}/,,")
08b3a3
08b3a3
        # Define the path part that is present in the localizable
08b3a3
        # directories.
08b3a3
        local PATHSAME=$(echo ${LOCATION} | sed -r "s,/${PATHDIFF},,")
08b3a3
08b3a3
        # Initiate verification between location provided and
08b3a3
        # localizable directories.
08b3a3
        if [[ $LOCATION =~ "^$DIR$" ]];then
08b3a3
08b3a3
            # At this point the location provided is exactly the same
08b3a3
            # that matches the localizable directories. There is
08b3a3
            # nothing else to do here but return the script flow to
08b3a3
            # this function caller.
08b3a3
            L10N_ACCEPTED='yes' 
08b3a3
            break
08b3a3
08b3a3
        elif [[ ${PATHSAME} =~ "^${DIR}" ]] && [[ -d ${LOCATION} ]];then
08b3a3
08b3a3
            # At this point the location provided is a directory in
08b3a3
            # the repository which doesn't match any localizable
08b3a3
            # directory in the list, but it could be rendered if the
08b3a3
            # --filter option is provided with the appropriate path
08b3a3
            # argument. Print a suggestion about it.
08b3a3
            cli_printMessage "${PATHSAME} --filter=\"$PATHDIFF\"" --as-suggestion-line
08b3a3
            break
08b3a3
            
878a2b
        fi
08b3a3
878a2b
    done
878a2b
08b3a3
    # At this point, we are safe to say that the path provided isn't
08b3a3
    # allow to have any localization for it. So, finish the script
08b3a3
    # execution with an error message.
08b3a3
    if [[ $L10N_ACCEPTED == 'no' ]];then
08b3a3
        cli_printMessage "`gettext "The path provided doesn't support localization."`" --as-error-line
08b3a3
    fi
878a2b
878a2b
}