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
#
7cd8e9
# 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
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function render_getActionsTranslations {
4c79b5
4c79b5
    # Check directory content. Translation rendering can be realized
1b89c2
    # only if inside the action 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. 
8219f0
    if [[ ! -d $ACTIONVAL/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
07c2fe
    # end immediatly at this point because it is surely not a
07c2fe
    # release-specific 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
07c2fe
        # At 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
07c2fe
        # (the one done after this block). So, 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=''
50dae2
    local LOCALES_INFO=''
50dae2
    local LOCALE=''
4c79b5
    local TRANSLATION=''
4c79b5
    local FILE=''
4c79b5
07c2fe
    # Define warning 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
1b89c2
    # Re-define releases using action 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.
07c2fe
    if [[ $REGEX =~ "^${RELEASE_FORMAT}$" ]];then
8219f0
        RELEASES=$ACTIONVAL/$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.
07c2fe
    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
8219f0
        RELEASES=$(find $ACTIONVAL -regextype posix-egrep \
07c2fe
            -regex "^${ACTIONVAL}/${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.
8219f0
        for FILE in $(find $ACTIONVAL/Tpl -name '*.sed');do
4c79b5
50dae2
            # Define translation file locale.
50dae2
            LOCALE=$(echo $FILE | sed -r 's!^/.+/Tpl/([a-z]{2}|[a-z]{2}_[A-Z]{2})/.+$!\1!' )
50dae2
            if [[ $LOCALE =~ '^([a-z]{2}|[a-z]{2}_[A-Z]{2})$' ]];then
50dae2
50dae2
                # Define locales translation markers.
50dae2
                LOCALES_INFO="
50dae2
                    # Locale information.
50dae2
                    s!=LOCALE=!${LOCALE}!g"
50dae2
50dae2
                # Strip opening spaces from locales translation markers
50dae2
                # output lines.
50dae2
                LOCALES_INFO=$(echo "$LOCALES_INFO" | sed 's!^[[:space:]]*!!')
50dae2
50dae2
            fi
50dae2
50dae2
            # Define absolute path to translation template file.
4c79b5
            TRANSLATION=$FILE
4c79b5
50dae2
            # Define absolute path to translation final file.
4c79b5
            FILE=$(echo $FILE | sed "s!/Tpl!/$RELEASE!")
4c79b5
50dae2
            # 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
50dae2
            # Output information about files 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
50dae2
            # 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
50dae2
            # Add locales markers to final translation file, if they
50dae2
            # have locales information only.
50dae2
            if [[ $LOCALES_INFO != '' ]];then
50dae2
                echo "$LOCALES_INFO" >> $FILE
50dae2
                # Clean up locales information variable to receive
50dae2
                # next value. If we don't clean up the variable here,
50dae2
                # translation files without locale information (e.g.,
50dae2
                # progress-first.sed, firstboot-left.sed, etc.) will
50dae2
                # use the locale information of the last translation
50dae2
                # template which does have locale information and we
50dae2
                # don't want that. We want to set locale information
50dae2
                # for each translation template individually.
50dae2
                LOCALES_INFO=''
50dae2
            fi
50dae2
4c79b5
            echo "------------------------------------------------------------"
4c79b5
4c79b5
        done
4c79b5
4c79b5
    done \
e92b23
        | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
4c79b5
}