Blame Scripts/Bash/Functions/Commons/cli_expandTMarkers.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# cli_expandTMarkers.sh -- This function standardizes
878a2b
# replacements for common translation markers. Raplacements are
878a2b
# applied to temporal instances used to produce the final file.
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function cli_expandTMarkers {
878a2b
878a2b
    # Initialize variables.
878a2b
    local -a SRC
878a2b
    local -a DST
878a2b
    local COUNT=0
878a2b
    local COUNTSRC=0
878a2b
    local COUNTDST=0
878a2b
    local LOCATION=''
878a2b
878a2b
    # Define source location on which sed replacements take place.
878a2b
    LOCATION="$1" 
878a2b
878a2b
    # Verify file source location.
878a2b
    cli_checkFiles $LOCATION
878a2b
878a2b
    # Define copyright translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_YEAR_LAST='
878a2b
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --copyright-year)"
878a2b
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_YEAR='
878a2b
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --copyright-year)"
878a2b
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_YEAR_LIST='
878a2b
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --copyright-year-list)"
878a2b
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_HOLDER='
878a2b
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --copyright-holder)"
878a2b
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_HOLDER_PREDICATE='
878a2b
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --copyright-holder-predicate)"
878a2b
bd18b1
    # Define name of branding files. This files are mainly used under
bd18b1
    # Identity/(Images|Models)/Brands/ directory structure. These
bd18b1
    # file names may vary from one project to another so we use this
bd18b1
    # variable to control the name of such files.
bd18b1
    SRC[((++${#SRC[*]}))]='=BRAND_FILENAME='
bd18b1
    DST[((++${#DST[*]}))]="${BRAND_FILENAME}"
bd18b1
878a2b
    # Define license translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=LICENSE='
878a2b
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --license)"
878a2b
    SRC[((++${#SRC[*]}))]='=LICENSE_URL='
878a2b
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --license-url)"
878a2b
878a2b
    # Define theme translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=THEME='
878a2b
    DST[((++${#DST[*]}))]="$(cli_getPathComponent $OUTPUT --motif)"
878a2b
    SRC[((++${#SRC[*]}))]='=THEMENAME='
878a2b
    DST[((++${#DST[*]}))]="$(cli_getPathComponent $OUTPUT --motif-name)"
878a2b
    SRC[((++${#SRC[*]}))]='=THEMERELEASE='
878a2b
    DST[((++${#DST[*]}))]="$(cli_getPathComponent $OUTPUT --motif-release)"
878a2b
878a2b
    # Define release-specific translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=RELEASE='
878a2b
    DST[((++${#DST[*]}))]="$FLAG_RELEASEVER"
878a2b
    SRC[((++${#SRC[*]}))]='=MAJOR_RELEASE='
878a2b
    DST[((++${#DST[*]}))]="$(echo $FLAG_RELEASEVER | cut -d'.' -f1)"
878a2b
    SRC[((++${#SRC[*]}))]='=MINOR_RELEASE='
878a2b
    DST[((++${#DST[*]}))]="$(echo $FLAG_RELEASEVER | cut -d'.' -f2)"
878a2b
878a2b
    # Define architectures translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=ARCH='
878a2b
    DST[((++${#DST[*]}))]="$(cli_getPathComponent $FLAG_BASEARCH --architecture)"
878a2b
878a2b
    # Define url translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=URL='
878a2b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--home' '--with-locale')
878a2b
    SRC[((++${#SRC[*]}))]='=URL_WIKI='
878a2b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--wiki' '--with-locale')
878a2b
    SRC[((++${#SRC[*]}))]='=URL_LISTS='
878a2b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--lists' '--with-locale')
878a2b
    SRC[((++${#SRC[*]}))]='=URL_FORUMS='
878a2b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--forums' '--with-locale')
878a2b
    SRC[((++${#SRC[*]}))]='=URL_MIRRORS='
878a2b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--mirrors' '--with-locale')
878a2b
    SRC[((++${#SRC[*]}))]='=URL_DOCS='
878a2b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--docs' '--with-locale')
878a2b
    SRC[((++${#SRC[*]}))]='=URL_IRC='
878a2b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--irc')
878a2b
878a2b
    # Define emails translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=MAIL_DOCS='
bd18b1
    DST[((++${#DST[*]}))]="${BRAND_FILENAME}-docs@centos.org"
878a2b
    SRC[((++${#SRC[*]}))]='=MAIL_L10N='
bd18b1
    DST[((++${#DST[*]}))]="${BRAND_FILENAME}-l10n@centos.org"
878a2b
878a2b
    # Define locale translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=LOCALE_LL='
878a2b
    DST[((++${#DST[*]}))]="$(cli_getCurrentLocale '--langcode-only')"
878a2b
    SRC[((++${#SRC[*]}))]='=LOCALE='
878a2b
    DST[((++${#DST[*]}))]="$(cli_getCurrentLocale)"
878a2b
878a2b
    # Define domain translation markers for domains.
878a2b
    SRC[((++${#SRC[*]}))]='=DOMAIN_LL='
878a2b
    if [[ ! $(cli_getCurrentLocale) =~ '^en' ]];then
878a2b
        DST[((++${#DST[*]}))]="$(cli_getCurrentLocale '--langcode-only')."
878a2b
    else
878a2b
        DST[((++${#DST[*]}))]=""
878a2b
    fi
878a2b
878a2b
    # Define repository translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=REPO_TLDIR='
878a2b
    DST[((++${#DST[*]}))]="$(cli_getRepoTLDir)"
878a2b
    SRC[((++${#SRC[*]}))]='=REPO_HOME='
878a2b
    DST[((++${#DST[*]}))]="${CLI_WRKCOPY}"
878a2b
878a2b
    # Do replacement of nested translation markers.
878a2b
    while [[ $COUNTDST -lt ${#DST[@]} ]];do
878a2b
878a2b
        # Verify existence of translation markers. If there is no
878a2b
        # translation marker on replacement, continue with the next
878a2b
        # one in the list.
878a2b
        if [[ ! ${DST[$COUNTDST]} =~ '=[A-Z_]+=' ]];then
878a2b
            # Increment destination counter.
878a2b
            COUNTDST=$(($COUNTDST + 1))
878a2b
            # The current replacement value doesn't have translation
878a2b
            # marker inside, so skip it and evaluate the next
878a2b
            # replacement value in the list.
878a2b
            continue
878a2b
        fi
878a2b
878a2b
        while [[ $COUNTSRC -lt ${#SRC[*]} ]];do
878a2b
878a2b
            # Update replacements.
878a2b
            DST[$COUNTDST]=$(echo ${DST[$COUNTDST]} \
878a2b
                | sed -r "s!${SRC[$COUNTSRC]}!${DST[$COUNTSRC]}!g")
878a2b
878a2b
            # Increment source counter.
878a2b
            COUNTSRC=$(($COUNTSRC + 1))
878a2b
878a2b
        done
878a2b
878a2b
        # Reset source counter
878a2b
        COUNTSRC=0
878a2b
878a2b
        # Increment destination counter.
878a2b
        COUNTDST=$(($COUNTDST + 1))
878a2b
878a2b
    done
878a2b
878a2b
    # Apply replacements for translation markers.
878a2b
    while [[ ${COUNT} -lt ${#SRC[*]} ]];do
878a2b
878a2b
        # Use sed to replace translation markers inside the design
878a2b
        # model instance.
878a2b
        sed -r -i "s!${SRC[$COUNT]}!${DST[$COUNT]}!g" ${LOCATION}
878a2b
878a2b
        # Increment counter.
878a2b
        COUNT=$(($COUNT + 1))
878a2b
878a2b
    done
878a2b
878a2b
    # Unset specific translation markers and specific replacement
878a2b
    # variables in order to clean them up. Otherwise, undesired values
878a2b
    # may ramain from one file to another.
878a2b
    unset SRC
878a2b
    unset DST
878a2b
878a2b
}