Blame Scripts/Bash/Functions/Render/render_getActionsTranslations.sh

4c79b5
#!/bin/bash
4c79b5
#
4c79b5
# render_getActionsTranslations.sh -- This function takes translation
4c79b5
# templates and produces the release-specific translation structures
4c79b5
# needed by renderImage function.
4c79b5
#
4c79b5
# Copyright (C) 2009-2010 Alain Reguera Delgado
4c79b5
# 
4c79b5
# This program is free software; you can redistribute it and/or
4c79b5
# modify it under the terms of the GNU General Public License as
4c79b5
# published by the Free Software Foundation; either version 2 of the
4c79b5
# 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
# ----------------------------------------------------------------------
4c79b5
# $Id: render_getActionsTranslations.sh 98 2010-09-19 16:01:53Z al $
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function render_getActionsTranslations {
4c79b5
4c79b5
    # Check directory content. Translation rendering can be realized
4c79b5
    # only if inside the option value directory there is a 'Tpl/'
4c79b5
    # directory. Translation rendering is based on translation
4c79b5
    # templates inside 'Tpl/' directory. If that directory doesn't
4c79b5
    # exist leave a message and quit execution. 
4c79b5
    if [[ ! -d $OPTIONVAL/Tpl ]];then
4c79b5
        cli_printMessage "`gettext "Can't find translation templates in the directory provided."`"
1f1b3c
        cli_printMessage "$(caller)" "AsToKnowMoreLine"
4c79b5
    fi
4c79b5
4c79b5
    # Check if there are pre-defined configuration scripts for the
4c79b5
    # current translation directory being processed. If you passed the
4c79b5
    # previous checks, it is time to check if the directory you are
4c79b5
    # processing already has render.conf.sh configuration scripts,
4c79b5
    # inside its trunk/Scripts/Bash/Config/... asociated strucutre. If
4c79b5
    # such directory entry exists, the translation rendering should
4c79b5
    # end immediatly on at this point because it is surely not a
4c79b5
    # release-specif translation rendering.
4c79b5
    if [[ -d $ARTCONF ]];then
4c79b5
        for FILE in $(find $ARTCONF -name 'render.conf.sh');do
4c79b5
            # Initialize configuration function.
4c79b5
            . $FILE
4c79b5
            # Execute configuration function
4c79b5
            render_loadConfig
4c79b5
        done
4c79b5
        # In this point, an entry inside trunk/Scripts/Bash/Config/...
4c79b5
        # was found for the directory being processed. If the
4c79b5
        # render.conf.sh files were there, they were executed. Because
4c79b5
        # render.conf.sh has to do with very specificy translation
4c79b5
        # rendering features (e.g., brands translation rendering),
4c79b5
        # that doesn't match release-specifc rendering translation
4c79b5
        # (the one done after this block), we need to end the
4c79b5
        # translation rendering right here.
1f1b3c
        cli_printMessage "$(caller)" "AsToKnowMoreLine"
4c79b5
    fi
4c79b5
4c79b5
    # -------------------------------------------------------------
4c79b5
    # - release-specific translation rendering stuff from this point on.
4c79b5
    # -------------------------------------------------------------
4c79b5
4c79b5
    # Initialize variables as local to avoid conflicts in other places.
4c79b5
    local RELEASES=''
4c79b5
    local MAJOR_RELEASE=''
4c79b5
    local MINOR_RELEASE=''
4c79b5
    local RELEASE_INFO=''
4c79b5
    local TRANSLATION=''
4c79b5
    local FILE=''
4c79b5
4c79b5
    # Define warnning message about the nature of release notes
4c79b5
    # translation files. This message is included in the very top of
4c79b5
    # every translation file.
4c79b5
    local MESSAGE="\
4c79b5
        # Warning: Do not modify this file directly. This file is created
4c79b5
        # automatically using 'centos-art' command line interface.  Any change
4c79b5
        # you do in this file will be lost the next time you update
4c79b5
        # translation files using 'centos-art' command line interface. If you
4c79b5
        # want to improve the content of this translation file, improve its
4c79b5
        # template file instead and run the 'centos-art' command line
4c79b5
        # interface later to propagate your changes."
4c79b5
4c79b5
    # Strip opening spaces from warning message output lines. 
4c79b5
    MESSAGE=$(echo "$MESSAGE" | sed 's!^[[:space:]]*!!')
4c79b5
4c79b5
    # Re-define releases using option value. If there is an
4c79b5
    # --option=value arguments then use the value to create/update
4c79b5
    # release-specific directories.  Otherwise, all release-specific
4c79b5
    # translations directories available in the current location will
4c79b5
    # be affected.
4c79b5
    if [[ $REGEX =~ "^$RELEASE_FORMAT$" ]];then
4c79b5
        RELEASES=$OPTIONVAL/$REGEX
4c79b5
4c79b5
    # Re-define releases using regular expression value. If you need
4c79b5
    # to create/update two or more release-specific directories (e.g.,
4c79b5
    # 5, 5.1, 5.2, and 6.0), you can use a command similar to
4c79b5
    # 'centos-art render --translation=./ --filter=5,5.1,5.2,6.0' to
4c79b5
    # create them all using just one command.
4c79b5
    elif [[ $REGEX =~ "^($RELEASE_FORMAT,?)+" ]];then
4c79b5
        for RELEASE in $(echo $REGEX | tr ',' ' ');do
4c79b5
            RELEASES="$RELEASES $RELEASE"
4c79b5
        done
4c79b5
4c79b5
    # By default look for available release-specific directories and
4c79b5
    # use them all.
4c79b5
    else
4c79b5
        RELEASES=$(find $OPTIONVAL -regextype posix-egrep \
4c79b5
            -regex "^$OPTIONVAL/$RELEASE_FORMAT$" | sort)
4c79b5
    fi
4c79b5
4c79b5
    # At this point, if there isn't release-specific directories
4c79b5
    # inside translation entry, output a message and quit script
4c79b5
    # execution.
4c79b5
    if [[ $RELEASES == "" ]];then
4c79b5
        cli_printMessage "`gettext "There is not release-specific directory in the translation entry."`"
1f1b3c
        cli_printMessage "$(caller)" "AsToKnowMoreLine"
4c79b5
    fi
4c79b5
4c79b5
    for RELEASE in $RELEASES;do
4c79b5
4c79b5
        # Strip directory path from release number.
4c79b5
        RELEASE=$(basename $RELEASE)
4c79b5
4c79b5
        # Check release format.
4c79b5
        if [[ ! "$RELEASE" =~ "^${RELEASE_FORMAT}$" ]]; then
4c79b5
            cli_printMessage "`eval_gettext "The \\\"\\\$RELEASE\\\" release number isn't valid."`"
1f1b3c
            cli_printMessage "$(caller)" "AsToKnowMoreLine"
4c79b5
        fi
4c79b5
4c79b5
        # Define major and minor release format.
4c79b5
        if [[ "$RELEASE" =~ '^[[:digit:]]+\.[[:digit:]]+$' ]]; then
4c79b5
            MAJOR_RELEASE="$(echo $RELEASE | cut -d. -f1)"
4c79b5
            MINOR_RELEASE="$(echo $RELEASE | cut -d. -f2)"
4c79b5
        elif [[ "$RELEASE" =~ '^[[:digit:]]+$' ]]; then
4c79b5
            MAJOR_RELEASE="$RELEASE"
4c79b5
            MINOR_RELEASE='0'
4c79b5
        fi
4c79b5
4c79b5
        # Define release translation markers.
4c79b5
        RELEASE_INFO="
4c79b5
            # Release number information.
4c79b5
            s!=RELEASE=!=MAJOR_RELEASE=.=MINOR_RELEASE=!g
4c79b5
            s!=MINOR_RELEASE=!$MINOR_RELEASE!g
4c79b5
            s!=MAJOR_RELEASE=!$MAJOR_RELEASE!g"
4c79b5
    
4c79b5
        # Strip opening spaces from release info output lines.
4c79b5
        RELEASE_INFO=$(echo "$RELEASE_INFO" | sed 's!^[[:space:]]*!!')
4c79b5
  
4c79b5
        # Get translation templates and process them using release
4c79b5
        # information previously defined.
4c79b5
        for FILE in $(find $OPTIONVAL/Tpl -name '*.sed');do
4c79b5
4c79b5
            # Define translation file.
4c79b5
            TRANSLATION=$FILE
4c79b5
4c79b5
            # Define destination for final file.
4c79b5
            FILE=$(echo $FILE | sed "s!/Tpl!/$RELEASE!")
4c79b5
4c79b5
            # Create release-specific directory if it doesn't exist.
4c79b5
            DIRNAME=$(dirname $FILE)
4c79b5
            if [[ ! -d $DIRNAME ]];then
4c79b5
                mkdir -p $DIRNAME
4c79b5
            fi
4c79b5
4c79b5
            # Show some verbose about file being processed.
4c79b5
            cli_printMessage $TRANSLATION "AsTranslationLine"
4c79b5
            cli_printMessage $FILE "AsSavedAsLine"
4c79b5
4c79b5
            # Add warnning message to final translation file.
4c79b5
            echo "$MESSAGE" > $FILE
4c79b5
4c79b5
            # Add template content to final translation file. 
4c79b5
            cat $TRANSLATION >> $FILE
4c79b5
4c79b5
            # Add release markers to final translation file.
4c79b5
            echo "$RELEASE_INFO" >> $FILE
4c79b5
4c79b5
            echo "------------------------------------------------------------"
4c79b5
4c79b5
        done
4c79b5
4c79b5
    done \
f3bce7
        | awk -f /home/centos/artwork/trunk/Scripts/Bash/Style/output_forRendering.awk
4c79b5
}