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
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='
567435
    SRC[3]='=THEME='
567435
    SRC[4]='=THEMENAME='
567435
    SRC[5]='=THEMERELEASE='
567435
    SRC[6]='=RELEASE='
567435
    SRC[7]='=MAJOR_RELEASE='
567435
    SRC[8]='=MINOR_RELEASE='
28f865
    SRC[9]='=URL='
ce40cb
    SRC[10]='=URLLOCALE='
28f865
    SRC[11]='=ARCH='
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')"
567435
    DST[3]="$(cli_getPathComponent "$FILE" '--theme')"
567435
    DST[4]="$(cli_getPathComponent "$FILE" '--theme-name')"
567435
    DST[5]="$(cli_getPathComponent "$FILE" '--theme-release')"
567435
    DST[6]="$(cli_getPathComponent "$FILE" '--release')"
567435
    DST[7]="$(cli_getPathComponent "$FILE" '--release-major')"
567435
    DST[8]="$(cli_getPathComponent "$FILE" '--release-minor')"
28f865
    DST[9]="http://www.centos.org"
ce40cb
    # Define url locale information. We don't want to show locale
ce40cb
    # information inside url for English language. English is the
ce40cb
    # default locale and no locale level is used for it.  However, if
28f865
    # we are rendering a language different from English, the locale
28f865
    # information should be present in the url.
ce40cb
    if [[ $(cli_getCurrentLocale) == 'en' ]];then
ce40cb
        DST[10]=''
ce40cb
    else
ce40cb
        DST[10]="$(cli_getCurrentLocale)/"
ce40cb
    fi
28f865
    DST[11]="$(cli_getPathComponent "$FILE" '--architecture')"
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
}