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