Blame Scripts/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
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
dcd347
# This program is distributed in the hope that it will be useful,
dcd347
# but 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
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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='
f4f773
    SRC[18]='=URL_LL='
f4f773
    SRC[19]='=DOMAIN_LL='
f4f773
    SRC[20]='=URL_IRC='
88f09f
    SRC[21]='=LOCALE_LL='
6e7d60
    SRC[22]='=LOCALE='
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')"
49237e
    DST[7]="$(cli_getPathComponent "$FLAG_RELEASEVER" '--release')"
49237e
    DST[8]="$(cli_getPathComponent "$FLAG_RELEASEVER" '--release-major')"
49237e
    DST[9]="$(cli_getPathComponent "$FLAG_RELEASEVER" '--release-minor')"
f4f773
    DST[10]="http://www.centos.org/=URL_LL="
49237e
    DST[11]="$(cli_getPathComponent "$FLAG_BASEARCH" '--architecture')"
f4f773
    DST[12]="http://wiki.centos.org/=URL_LL="
f4f773
    DST[13]="http://lists.centos.org/=URL_LL="
f4f773
    DST[14]="http://forums.centos.org/=URL_LL="
f4f773
    DST[15]="http://mirrors.centos.org/=URL_LL="
f4f773
    DST[16]="http://docs.centos.org/=URL_LL="
88f09f
    DST[17]="centos-docs@centos.org"
64e325
    if [[ ! $(cli_getCurrentLocale) =~ '^en' ]];then
64e325
        DST[18]="$(cli_getCurrentLocale '--langcode-only')/"
64e325
    else
f4f773
        DST[18]=""
64e325
    fi
f4f773
    if [[ ! $(cli_getCurrentLocale) =~ '^en' ]];then
f4f773
        DST[19]="$(cli_getCurrentLocale '--langcode-only')."
f4f773
    else
f4f773
        DST[19]=""
f4f773
    fi
f4f773
    DST[20]='http://www.centos.org/modules/tinycontent/index.php?id=8'
88f09f
    DST[21]="$(cli_getCurrentLocale '--langcode-only')"
6e7d60
    DST[22]="$(cli_getCurrentLocale)"
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
}