Blame Automation/centos-art.sh-mods/Cli/cli_expandTMarkers.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# cli_expandTMarkers.sh -- This function standardizes construction of
Alain Reguera Delgado 8f60cb
# translation markers and their related expansion. As convention,
Alain Reguera Delgado 8f60cb
# translation markers must be set inside source files (e.g., Docbook,
Alain Reguera Delgado 8f60cb
# Svg, etc.) and expanded inside temporal instances used to produce
Alain Reguera Delgado 8f60cb
# final contents.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function cli_expandTMarkers {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize variables.
Alain Reguera Delgado 8f60cb
    local -a SRC
Alain Reguera Delgado 8f60cb
    local -a DST
Alain Reguera Delgado 8f60cb
    local COUNT=0
Alain Reguera Delgado 8f60cb
    local COUNTSRC=0
Alain Reguera Delgado 8f60cb
    local COUNTDST=0
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define source location on which sed replacements take place.
Alain Reguera Delgado 8f60cb
    local LOCATION="$1"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify that source location does exist.
Alain Reguera Delgado 8f60cb
    cli_checkFiles -e ${LOCATION}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define copyright translation markers.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_YEAR(_LAST)?='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --year)"
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_YEAR(S)?_LIST='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --years-list)"
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_HOLDER='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --holder)"
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_HOLDER_PREDICATE='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --holder-predicate)"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define name of branding files. This files are mainly used under
Alain Reguera Delgado 8f60cb
    # Identity/(Images|Models)/Brands/ directory structure. These
Alain Reguera Delgado 8f60cb
    # file names may vary from one project to another so we use this
Alain Reguera Delgado 8f60cb
    # variable to control the name of such files.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=BRAND='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="${TCAR_BRAND}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define license translation markers.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=LICENSE='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --license)"
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=LICENSE_URL='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --license-url)"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define theme translation markers.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=THEME='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_getPathComponent $OUTPUT --motif)"
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=THEMENAME='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_getPathComponent $OUTPUT --motif-name)"
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=THEMERELEASE='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_getPathComponent $OUTPUT --motif-release)"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define release-specific translation markers.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=RELEASE='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$FLAG_RELEASEVER"
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=MAJOR_RELEASE='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(echo $FLAG_RELEASEVER | cut -d'.' -f1)"
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=MINOR_RELEASE='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(echo $FLAG_RELEASEVER | cut -d'.' -f2)"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define architectures translation markers.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=ARCH='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_getPathComponent $FLAG_BASEARCH --architecture)"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define url translation markers.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--home' '--with-locale')
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL_WIKI='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--wiki' '--with-locale')
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL_LISTS='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--lists' '--with-locale')
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL_FORUMS='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--forums' '--with-locale')
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL_MIRRORS='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--mirrors' '--with-locale')
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL_DOCS='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--docs' '--with-locale')
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL_PROJECTS='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--projects' '--with-locale')
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL_BUGS='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--bugs' '--with-locale')
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL_SVN='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--svn' '--with-locale')
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL_TRAC='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--trac' '--with-locale')
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=URL_PLANET='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]=$(cli_printUrl '--planet' '--with-locale')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define emails translation markers.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=MAIL_DOCS='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="$(cli_printMailingList --docs)"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define locale translation markers.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=LOCALE='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="${CLI_LANG_LC}"
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=LOCALE_LL='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="${CLI_LANG_LL}"
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=LOCALE_CC='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="${CLI_LANG_CC}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define domain translation markers for domains.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=DOMAIN_LL='
Alain Reguera Delgado 8f60cb
    if [[ ! ${CLI_LANG_LL} =~ '^en' ]];then
Alain Reguera Delgado 8f60cb
        DST[((++${#DST[*]}))]="${CLI_LANG_LL}"
Alain Reguera Delgado 8f60cb
    else
Alain Reguera Delgado 8f60cb
        DST[((++${#DST[*]}))]=""
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define repository translation markers.
Alain Reguera Delgado 8f60cb
    SRC[((++${#SRC[*]}))]='=(REPO_TLDIR|REPO_HOME|TCAR_WORKDIR)='
Alain Reguera Delgado 8f60cb
    DST[((++${#DST[*]}))]="${TCAR_WORKDIR}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Do replacement of nested translation markers.
Alain Reguera Delgado 8f60cb
    while [[ $COUNTDST -lt ${#DST[@]} ]];do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Verify existence of translation markers. If there is no
Alain Reguera Delgado 8f60cb
        # translation marker on replacement, continue with the next
Alain Reguera Delgado 8f60cb
        # one in the list.
Alain Reguera Delgado 8f60cb
        if [[ ! ${DST[$COUNTDST]} =~ '=[A-Z_]+=' ]];then
Alain Reguera Delgado 8f60cb
            # Increment destination counter.
Alain Reguera Delgado 8f60cb
            COUNTDST=$(($COUNTDST + 1))
Alain Reguera Delgado 8f60cb
            # The current replacement value doesn't have translation
Alain Reguera Delgado 8f60cb
            # marker inside, so skip it and evaluate the next
Alain Reguera Delgado 8f60cb
            # replacement value in the list.
Alain Reguera Delgado 8f60cb
            continue
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        while [[ $COUNTSRC -lt ${#SRC[*]} ]];do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Update replacements.
Alain Reguera Delgado 8f60cb
            DST[$COUNTDST]=$(echo ${DST[$COUNTDST]} \
Alain Reguera Delgado 8f60cb
                | sed -r "s!${SRC[$COUNTSRC]}!${DST[$COUNTSRC]}!g")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Increment source counter.
Alain Reguera Delgado 8f60cb
            COUNTSRC=$(($COUNTSRC + 1))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Reset source counter
Alain Reguera Delgado 8f60cb
        COUNTSRC=0
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Increment destination counter.
Alain Reguera Delgado 8f60cb
        COUNTDST=$(($COUNTDST + 1))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Apply replacements for translation markers.
Alain Reguera Delgado 8f60cb
    while [[ ${COUNT} -lt ${#SRC[*]} ]];do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Use sed to replace translation markers inside the design
Alain Reguera Delgado 8f60cb
        # model instance.
Alain Reguera Delgado 8f60cb
        sed -r -i "s!${SRC[$COUNT]}!${DST[$COUNT]}!g" ${LOCATION}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Increment counter.
Alain Reguera Delgado 8f60cb
        COUNT=$(($COUNT + 1))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Remove escaped character from translation markers. This is one
Alain Reguera Delgado 8f60cb
    # of the reasons why translation marker should be expanded in
Alain Reguera Delgado 8f60cb
    # source files instances not the source files themselves.
Alain Reguera Delgado 8f60cb
    # Escaping translation markers provides a way of talking about
Alain Reguera Delgado 8f60cb
    # them without expanding them.
Alain Reguera Delgado 8f60cb
    sed -r -i 's/(=)\\([A-Z_]+=)/\1\2/g' ${LOCATION}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Unset specific translation markers and specific replacement
Alain Reguera Delgado 8f60cb
    # variables in order to clean them up. Otherwise, undesired values
Alain Reguera Delgado 8f60cb
    # may remain from one file to another.
Alain Reguera Delgado 8f60cb
    unset SRC
Alain Reguera Delgado 8f60cb
    unset DST
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}