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

ce40cb
#!/bin/bash
ce40cb
#
b46d06
# render_doIdentityTMarkersCommons.sh -- This function standardizes
ce40cb
# replacements for common translation markers. Raplacements are
ce40cb
# applied to temporal instances used to produce the final file.
ce40cb
#
ce40cb
# Copyright (C) 2009-2011 Alain Reguera Delgado
ce40cb
# 
ce40cb
# This program is free software; you can redistribute it and/or
ce40cb
# modify it under the terms of the GNU General Public License as
ce40cb
# published by the Free Software Foundation; either version 2 of the
ce40cb
# License, or (at your option) any later version.
ce40cb
# 
ce40cb
# This program is distributed in the hope that it will be useful, but
ce40cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
ce40cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce40cb
# General Public License for more details.
ce40cb
#
ce40cb
# You should have received a copy of the GNU General Public License
ce40cb
# along with this program; if not, write to the Free Software
ce40cb
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
ce40cb
# USA.
ce40cb
# 
ce40cb
# ----------------------------------------------------------------------
ce40cb
# $Id$
ce40cb
# ----------------------------------------------------------------------
ce40cb
b46d06
function render_doIdentityTMarkersCommons {
ce40cb
ce40cb
    # Initialize variables.
ce40cb
    local -a SRC
ce40cb
    local -a DST
ce40cb
    local COUNT=0
9b4d7d
    local COUNTSRC=0
9b4d7d
    local COUNTDST=0
28f865
    local LOCATION=''
28f865
28f865
    # Define source location on which sed replacements take place. By
28f865
    # default we use the value of INSTANCE variable, but if $1 is not
28f865
    # empty assume $1 as source location on which sed replacements
28f865
    # take place. This makes possible to reuse this function on
28f865
    # different source locations.
28f865
    if [[ "$1" != '' ]];then
28f865
        LOCATION="$1" 
28f865
    else
28f865
        LOCATION="${INSTANCE}" 
28f865
    fi
28f865
28f865
    # Verify source location file.
28f865
    cli_checkFiles "$LOCATION" 'f'
ce40cb
567435
    # Define translation markers. The translation marker definition
567435
    # order is important. Note that when we render concept directory
567435
    # structure, we make two replacements to produce the final
567435
    # copyright note. First, we replace =COPYRIGHT= translation marker
567435
    # and later the =THEMENAME= translation maker (not the oposite).
567435
    SRC[0]='=COPYRIGHT='
567435
    SRC[1]='=DESCRIPTION='
567435
    SRC[2]='=LICENSE='
9b4d7d
    SRC[3]='=LICENSE_URL='
9b4d7d
    SRC[4]='=THEME='
9b4d7d
    SRC[5]='=THEMENAME='
9b4d7d
    SRC[6]='=THEMERELEASE='
9b4d7d
    SRC[7]='=RELEASE='
9b4d7d
    SRC[8]='=MAJOR_RELEASE='
9b4d7d
    SRC[9]='=MINOR_RELEASE='
9b4d7d
    SRC[10]='=URL='
28f865
    SRC[11]='=ARCH='
9b4d7d
    SRC[12]='=URL_WIKI='
9b4d7d
    SRC[13]='=URL_LISTS='
9b4d7d
    SRC[14]='=URL_FORUMS='
9b4d7d
    SRC[15]='=URL_MIRRORS='
9b4d7d
    SRC[16]='=URL_DOCS='
ce40cb
ce40cb
    # Define replacements for translation markers.
567435
    DST[0]="$(cli_getCopyrightInfo '--copyright')"
567435
    DST[1]="$(cli_getCopyrightInfo '--description')"
567435
    DST[2]="$(cli_getCopyrightInfo '--license')"
9b4d7d
    DST[3]="$(cli_getCopyrightInfo '--license-url')"
9b4d7d
    DST[4]="$(cli_getPathComponent "$FILE" '--theme')"
9b4d7d
    DST[5]="$(cli_getPathComponent "$FILE" '--theme-name')"
9b4d7d
    DST[6]="$(cli_getPathComponent "$FILE" '--theme-release')"
9b4d7d
    DST[7]="$(cli_getPathComponent "$FILE" '--release')"
9b4d7d
    DST[8]="$(cli_getPathComponent "$FILE" '--release-major')"
9b4d7d
    DST[9]="$(cli_getPathComponent "$FILE" '--release-minor')"
9b4d7d
    DST[10]="http://$(cli_getCurrentLocale).centos.org/"
28f865
    DST[11]="$(cli_getPathComponent "$FILE" '--architecture')"
9b4d7d
    DST[12]="=URL=wiki/"
9b4d7d
    DST[13]="=URL=lists/"
9b4d7d
    DST[14]="=URL=forums/"
9b4d7d
    DST[15]="=URL=mirrors/"
9b4d7d
    DST[16]="=URL=docs/"
9b4d7d
9b4d7d
    # Do replacement of nested translation markers.
9b4d7d
    while [[ $COUNTDST -lt ${#DST[@]} ]];do
9b4d7d
9b4d7d
        # Verify existence of translation markers. If there is no
9b4d7d
        # translation marker on replacement, continue with the next
9b4d7d
        # one in the list.
9b4d7d
        if [[ ! ${DST[$COUNTDST]} =~ '=[A-Z_]+=' ]];then
9b4d7d
            # Increment destination counter.
9b4d7d
            COUNTDST=$(($COUNTDST + 1))
9b4d7d
            # The current replacement value doesn't have translation
9b4d7d
            # marker inside, so skip it and evaluate the next
9b4d7d
            # replacement value in the list.
9b4d7d
            continue
9b4d7d
        fi
9b4d7d
9b4d7d
        while [[ $COUNTSRC -lt ${#SRC[*]} ]];do
9b4d7d
9b4d7d
            # Update replacements.
9b4d7d
            DST[$COUNTDST]=$(echo ${DST[$COUNTDST]} \
9b4d7d
                | sed -r "s!${SRC[$COUNTSRC]}!${DST[$COUNTSRC]}!g")
9b4d7d
9b4d7d
            # Increment source counter.
9b4d7d
            COUNTSRC=$(($COUNTSRC + 1))
9b4d7d
9b4d7d
        done
9b4d7d
9b4d7d
        # Reset source counter
9b4d7d
        COUNTSRC=0
9b4d7d
9b4d7d
        # Increment destination counter.
9b4d7d
        COUNTDST=$(($COUNTDST + 1))
9b4d7d
9b4d7d
    done
ce40cb
ce40cb
    # Apply replacements for translation markers.
ce40cb
    while [[ ${COUNT} -lt ${#SRC[*]} ]];do
ce40cb
ce40cb
        # Use sed to replace translation markers inside the design
ce40cb
        # model instance.
28f865
        sed -r -i "s!${SRC[$COUNT]}!${DST[$COUNT]}!g" ${LOCATION}
ce40cb
ce40cb
        # Increment counter.
ce40cb
        COUNT=$(($COUNT + 1))
ce40cb
ce40cb
    done
ce40cb
ce40cb
    # Unset specific translation markers and specific replacement
ce40cb
    # variables in order to clean them up. Otherwise, undesired values
ce40cb
    # may ramain from one file to another.
ce40cb
    unset SRC
ce40cb
    unset DST
ce40cb
ce40cb
}