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

878a2b
#!/bin/bash
878a2b
#
9ec67b
# cli_expandTMarkers.sh -- This function standardizes construction of
9ec67b
# translation markers and their related expansion. As convention,
9ec67b
# translation markers must be set inside source files (e.g., Docbook,
9ec67b
# Svg, etc.) and expanded inside temporal instances used to produce
9ec67b
# final contents.
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 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
878a2b
    # Define source location on which sed replacements take place.
819c26
    local LOCATION="$1"
878a2b
3c1e22
    # Verify that source location does exist.
3c1e22
    cli_checkFiles -e ${LOCATION}
878a2b
878a2b
    # Define copyright translation markers.
9ec67b
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_YEAR(_LAST)?='
9691ae
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --year)"
9ec67b
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_YEAR(S)?_LIST='
9691ae
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --years-list)"
878a2b
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_HOLDER='
9691ae
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --holder)"
878a2b
    SRC[((++${#SRC[*]}))]='=COPYRIGHT_HOLDER_PREDICATE='
9691ae
    DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --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.
f2a242
    SRC[((++${#SRC[*]}))]='=BRAND='
4cabd6
    DST[((++${#DST[*]}))]="${TCAR_BRAND}"
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')
9ec67b
    SRC[((++${#SRC[*]}))]='=URL_PROJECTS='
9ec67b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--projects' '--with-locale')
9ec67b
    SRC[((++${#SRC[*]}))]='=URL_BUGS='
9ec67b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--bugs' '--with-locale')
9ec67b
    SRC[((++${#SRC[*]}))]='=URL_SVN='
9ec67b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--svn' '--with-locale')
9ec67b
    SRC[((++${#SRC[*]}))]='=URL_TRAC='
9ec67b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--trac' '--with-locale')
9ec67b
    SRC[((++${#SRC[*]}))]='=URL_PLANET='
9ec67b
    DST[((++${#DST[*]}))]=$(cli_printUrl '--planet' '--with-locale')
878a2b
878a2b
    # Define emails translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=MAIL_DOCS='
4cabd6
    DST[((++${#DST[*]}))]="$(cli_printMailingList --docs)"
878a2b
878a2b
    # Define locale translation markers.
878a2b
    SRC[((++${#SRC[*]}))]='=LOCALE='
3c1e22
    DST[((++${#DST[*]}))]="${CLI_LANG_LC}"
9ec67b
    SRC[((++${#SRC[*]}))]='=LOCALE_LL='
9ec67b
    DST[((++${#DST[*]}))]="${CLI_LANG_LL}"
9ec67b
    SRC[((++${#SRC[*]}))]='=LOCALE_CC='
9ec67b
    DST[((++${#DST[*]}))]="${CLI_LANG_CC}"
878a2b
878a2b
    # Define domain translation markers for domains.
878a2b
    SRC[((++${#SRC[*]}))]='=DOMAIN_LL='
3c1e22
    if [[ ! ${CLI_LANG_LL} =~ '^en' ]];then
3c1e22
        DST[((++${#DST[*]}))]="${CLI_LANG_LL}"
878a2b
    else
878a2b
        DST[((++${#DST[*]}))]=""
878a2b
    fi
878a2b
878a2b
    # Define repository translation markers.
819c26
    SRC[((++${#SRC[*]}))]='=(REPO_TLDIR|REPO_HOME|TCAR_WORKDIR)='
630333
    DST[((++${#DST[*]}))]="${TCAR_WORKDIR}"
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
9ec67b
    # Remove escaped character from translation markers. This is one
9ec67b
    # of the reasons why translation marker should be expanded in
9ec67b
    # source files instances not the source files themselves.
9ec67b
    # Escaping translation markers provides a way of talking about
9ec67b
    # them without expanding them.
9ec67b
    sed -r -i 's/(=)\\([A-Z_]+=)/\1\2/g' ${LOCATION}
9ec67b
878a2b
    # Unset specific translation markers and specific replacement
878a2b
    # variables in order to clean them up. Otherwise, undesired values
9ec67b
    # may remain from one file to another.
878a2b
    unset SRC
878a2b
    unset DST
878a2b
878a2b
}