|
Alain Reguera Delgado |
2c7b25 |
#!/bin/bash
|
|
Alain Reguera Delgado |
2c7b25 |
######################################################################
|
|
Alain Reguera Delgado |
2c7b25 |
#
|
|
Alain Reguera Delgado |
2c7b25 |
# render_setLocalizedXml.sh -- This function standardizes the way
|
|
Alain Reguera Delgado |
2c7b25 |
# (.po) translation files are applied to XML files (e.g., .docbook,
|
|
Alain Reguera Delgado |
2c7b25 |
# .svg) in order to produce their related translated instances, used
|
|
Alain Reguera Delgado |
2c7b25 |
# to expand translation markers and produce the final file format in
|
|
Alain Reguera Delgado |
2c7b25 |
# different languages. Assuming no translation file exists, an
|
|
Alain Reguera Delgado |
2c7b25 |
# untranslated instance is taken from the design model and created
|
|
Alain Reguera Delgado |
2c7b25 |
# (i.e., just a copy) from it. Using a design model instance
|
|
Alain Reguera Delgado |
2c7b25 |
# (translated or not) is required in order to expand translation
|
|
Alain Reguera Delgado |
2c7b25 |
# markers safely.
|
|
Alain Reguera Delgado |
2c7b25 |
#
|
|
Alain Reguera Delgado |
2c7b25 |
# Written by:
|
|
Alain Reguera Delgado |
2c7b25 |
# * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
|
|
Alain Reguera Delgado |
2c7b25 |
#
|
|
Alain Reguera Delgado |
2c7b25 |
# Copyright (C) 2009-2013 The CentOS Artwork SIG
|
|
Alain Reguera Delgado |
2c7b25 |
#
|
|
Alain Reguera Delgado |
2c7b25 |
# This program is free software; you can redistribute it and/or modify
|
|
Alain Reguera Delgado |
2c7b25 |
# it under the terms of the GNU General Public License as published by
|
|
Alain Reguera Delgado |
2c7b25 |
# the Free Software Foundation; either version 2 of the License, or (at
|
|
Alain Reguera Delgado |
2c7b25 |
# your option) any later version.
|
|
Alain Reguera Delgado |
2c7b25 |
#
|
|
Alain Reguera Delgado |
2c7b25 |
# This program is distributed in the hope that it will be useful, but
|
|
Alain Reguera Delgado |
2c7b25 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Alain Reguera Delgado |
2c7b25 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Alain Reguera Delgado |
2c7b25 |
# General Public License for more details.
|
|
Alain Reguera Delgado |
2c7b25 |
#
|
|
Alain Reguera Delgado |
2c7b25 |
# You should have received a copy of the GNU General Public License
|
|
Alain Reguera Delgado |
2c7b25 |
# along with this program; if not, write to the Free Software
|
|
Alain Reguera Delgado |
2c7b25 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
Alain Reguera Delgado |
2c7b25 |
#
|
|
Alain Reguera Delgado |
2c7b25 |
######################################################################
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
function render_setLocalizedXml {
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Define absolute path to source instance.
|
|
Alain Reguera Delgado |
2c7b25 |
local SOURCE="${1}"
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Define absolute path to target instance.
|
|
Alain Reguera Delgado |
2c7b25 |
local TARGET="${2}"
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Verify source instance and the no-locale flag. When source
|
|
Alain Reguera Delgado |
2c7b25 |
# instance already exists, don't create a new file for it.
|
|
Alain Reguera Delgado |
2c7b25 |
# Instead, link it using a symbolic link. Be careful, such
|
|
Alain Reguera Delgado |
2c7b25 |
# behavior only applies when the source file has no locale.
|
|
Alain Reguera Delgado |
2c7b25 |
# Otherwise, the source file needs to go through the translation
|
|
Alain Reguera Delgado |
2c7b25 |
# process inevitably.
|
|
Alain Reguera Delgado |
2c7b25 |
if [[ -f ${SOURCE} ]];then
|
|
Alain Reguera Delgado |
2c7b25 |
if [[ ${SOURCE} =~ "^${TCAR_SCRIPT_TEMPDIR}" ]];then
|
|
Alain Reguera Delgado |
2c7b25 |
if [[ ${RENDER_FLAG_NO_LOCALE} == 'true' ]];then
|
|
Alain Reguera Delgado |
2c7b25 |
tcar_checkFiles -i 'text/xml' ${SOURCE}
|
|
Alain Reguera Delgado |
2c7b25 |
/bin/ln -s ${SOURCE} ${TARGET}
|
|
Alain Reguera Delgado |
2c7b25 |
return
|
|
Alain Reguera Delgado |
2c7b25 |
fi
|
|
Alain Reguera Delgado |
2c7b25 |
elif [[ ${RENDER_FLAG_NO_LOCALE} == 'true' ]];then
|
|
Alain Reguera Delgado |
2c7b25 |
tcar_printFile ${SOURCE} > ${TARGET}
|
|
Alain Reguera Delgado |
2c7b25 |
tcar_checkFiles -i 'text/xml' ${TARGET}
|
|
Alain Reguera Delgado |
2c7b25 |
return
|
|
Alain Reguera Delgado |
2c7b25 |
fi
|
|
Alain Reguera Delgado |
2c7b25 |
fi
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Verify existence of translation files.
|
|
Alain Reguera Delgado |
2c7b25 |
tcar_checkFiles -efi 'text/x-po' ${TRANSLATIONS[*]}
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Define absolute path to translation instance.
|
|
Alain Reguera Delgado |
2c7b25 |
local TRANSLATION=$(tcar_getTemporalFile "messages.po")
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Combine available translations file into one translation
|
|
Alain Reguera Delgado |
2c7b25 |
# instance.
|
|
Alain Reguera Delgado |
2c7b25 |
msgcat -u -o ${TRANSLATION} ${TRANSLATIONS[*]}
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Verify existence of final location. In case it doesn't exist,
|
|
Alain Reguera Delgado |
2c7b25 |
# create it.
|
|
Alain Reguera Delgado |
2c7b25 |
if [[ $(dirname ${RENDER_TARGET}) ]];then
|
|
Alain Reguera Delgado |
2c7b25 |
mkdir -p $(dirname ${RENDER_TARGET})
|
|
Alain Reguera Delgado |
2c7b25 |
fi
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Move to final location before processing source file in order
|
|
Alain Reguera Delgado |
2c7b25 |
# for relative calls (e.g., image files) inside the source files
|
|
Alain Reguera Delgado |
2c7b25 |
# can be found by xml2po and no warning be printed from it.
|
|
Alain Reguera Delgado |
2c7b25 |
pushd $(dirname ${RENDER_TARGET}) > /dev/null
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Create the localized instance from design model.
|
|
Alain Reguera Delgado |
2c7b25 |
tcar_printFile ${SOURCE} | xml2po -a -l ${TCAR_SCRIPT_LANG_LC} \
|
|
Alain Reguera Delgado |
2c7b25 |
-p ${TRANSLATION} -o ${TARGET} -
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Remove .xml2po.mo temporal file.
|
|
Alain Reguera Delgado |
2c7b25 |
if [[ -f ./.xml2po.mo ]];then
|
|
Alain Reguera Delgado |
2c7b25 |
rm ./.xml2po.mo
|
|
Alain Reguera Delgado |
2c7b25 |
fi
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Return to previous location.
|
|
Alain Reguera Delgado |
2c7b25 |
popd > /dev/null
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
# Remove instance created to store template translations.
|
|
Alain Reguera Delgado |
2c7b25 |
if [[ -f ${TRANSLATION} ]];then
|
|
Alain Reguera Delgado |
2c7b25 |
rm ${TRANSLATION}
|
|
Alain Reguera Delgado |
2c7b25 |
fi
|
|
Alain Reguera Delgado |
2c7b25 |
|
|
Alain Reguera Delgado |
2c7b25 |
}
|