Blame Scripts/Bash/centos-art/Functions/cli_replaceTMarkers.sh

ce40cb
#!/bin/bash
ce40cb
#
79e54d
# cli_replaceTMarkers.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
79e54d
function cli_replaceTMarkers {
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
35950d
    # Define source location on which sed replacements take place.
35950d
    LOCATION="$1" 
28f865
35950d
    # Verify file source location.
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).
f3fcd3
    SRC[0]='=COPYRIGHT_YEAR='
f3fcd3
    SRC[1]='=COPYRIGHT_HOLDER='
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='
1cb9cb
    SRC[17]='=MAIL_DOCS='
f3fcd3
    SRC[18]='=LOCALE_LL='
ce40cb
ce40cb
    # Define replacements for translation markers.
f3fcd3
    DST[0]="$(cli_getCopyrightInfo '--copyright-year')"
f3fcd3
    DST[1]="$(cli_getCopyrightInfo '--copyright-holder')"
567435
    DST[2]="$(cli_getCopyrightInfo '--license')"
9b4d7d
    DST[3]="$(cli_getCopyrightInfo '--license-url')"
f3fcd3
    DST[4]="$(cli_getPathComponent "$OUTPUT" '--theme')"
f3fcd3
    DST[5]="$(cli_getPathComponent "$OUTPUT" '--theme-name')"
f3fcd3
    DST[6]="$(cli_getPathComponent "$OUTPUT" '--theme-release')"
f3fcd3
    DST[7]="$(cli_getPathComponent "$FLAG_RELEASE" '--release')"
f3fcd3
    DST[8]="$(cli_getPathComponent "$FLAG_RELEASE" '--release-major')"
f3fcd3
    DST[9]="$(cli_getPathComponent "$FLAG_RELEASE" '--release-minor')"
f3fcd3
    DST[10]="http://=LOCALE_LL=.centos.org/"
f3fcd3
    DST[11]="$(cli_getPathComponent "$FLAG_ARCHITECTURE" '--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/"
1cb9cb
    DST[17]="centos-docs@$(cli_getCurrentLocale '--langcode-only').centos.org"
f3fcd3
    DST[18]="$(cli_getCurrentLocale '--langcode-only')"
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
}