From ce40cb1897dbbebc06018c76ce2aa1506dc3eb2d Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Jan 22 2011 04:14:31 +0000 Subject: Update render_doTranslationMarkers.sh: - Divide translation markers in specific translation markers (render_doTranslationMarkersSpecifics.sh) and common translation markers (render_doTranslationMarkersCommons.sh). - Add render_doTranslationMarkersSpecifics.sh - Add render_doTranslationMarkersCommons.sh --- diff --git a/Scripts/Bash/Functions/Render/render_doTranslationMarkers.sh b/Scripts/Bash/Functions/Render/render_doTranslationMarkers.sh index bf94265..37a9e11 100755 --- a/Scripts/Bash/Functions/Render/render_doTranslationMarkers.sh +++ b/Scripts/Bash/Functions/Render/render_doTranslationMarkers.sh @@ -1,10 +1,11 @@ #!/bin/bash # # render_doTranslationMarkers.sh -- This function standardizes -# replacements for common translation markers. This function must be -# called from render_getIdentityDefs.sh function (after instance -# creation and before final file creation). Raplacements are applied -# to temporal instances used to produced the final file. +# replacements for both specific and common translation markers. This +# function must be called from render_getIdentityDefs.sh function +# (after instance creation and before final file creation). +# Raplacements are applied to temporal instances used to produce the +# final file. # # Copyright (C) 2009-2011 Alain Reguera Delgado # @@ -29,38 +30,10 @@ function render_doTranslationMarkers { - # Initialize theme replacements. - local -a SRC - local -a DST - local COUNT=0 + # Apply specific replacements for specific translation markers. + render_doTranslationMarkersSpecifics - # Redefine theme translation markers. - SRC[0]='=THEME=' - SRC[1]='=COPYRIGHT=' - SRC[2]='=DESCRIPTION=' - SRC[3]='=LICENSE=' - SRC[4]='=NAME=' - SRC[5]='=RELEASE=' - SRC[6]='=URL=' - - # Redefine theme replacements. - DST[0]="$(cli_getThemeName)" - DST[1]="$(cli_getCopyrightInfo '--copyright')" - DST[2]="$(cli_getCopyrightInfo '--description')" - DST[3]="$(cli_getCopyrightInfo '--license')" - DST[4]="$(cli_getThemeName '--name')" - DST[5]="$(cli_getThemeName '--release')" - DST[6]="http://www.centos.org/" - - # Replace translation markes with theme values. - while [[ ${COUNT} -lt ${#SRC[*]} ]];do - - # Replace translation markers. - sed -r -i "s!${SRC[$COUNT]}!${DST[$COUNT]}!g" $INSTANCE - - # Increment counter. - COUNT=$(($COUNT + 1)) - - done + # Apply common replacements for common translation markers. + render_doTranslationMarkersCommons } diff --git a/Scripts/Bash/Functions/Render/render_doTranslationMarkersCommons.sh b/Scripts/Bash/Functions/Render/render_doTranslationMarkersCommons.sh new file mode 100755 index 0000000..4fd9478 --- /dev/null +++ b/Scripts/Bash/Functions/Render/render_doTranslationMarkersCommons.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# +# render_doTranslationMarkersCommons.sh -- This function standardizes +# replacements for common translation markers. Raplacements are +# applied to temporal instances used to produce the final file. +# +# Copyright (C) 2009-2011 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function render_doTranslationMarkersCommons { + + # Initialize variables. + local -a SRC + local -a DST + local COUNT=0 + + # Define translation markers. + SRC[0]='=THEME=' + SRC[1]='=COPYRIGHT=' + SRC[2]='=DESCRIPTION=' + SRC[3]='=LICENSE=' + SRC[4]='=NAME=' + SRC[5]='=RELEASE=' + SRC[6]='=URL=' + SRC[7]='=RELEASE=' + SRC[8]='=MAJOR_RELEASE=' + SRC[9]='=MINOR_RELEASE=' + SRC[10]='=URLLOCALE=' + + # Define replacements for translation markers. + DST[0]="$(cli_getThemeName)" + DST[1]="$(cli_getCopyrightInfo '--copyright')" + DST[2]="$(cli_getCopyrightInfo '--description')" + DST[3]="$(cli_getCopyrightInfo '--license')" + DST[4]="$(cli_getThemeName '--name')" + DST[5]="$(cli_getThemeName '--release')" + DST[6]="http://www.centos.org" + DST[7]="$(cli_getRelease "$FILE")" + DST[8]="$(cli_getRelease "$FILE" '--major')" + DST[9]="$(cli_getRelease "$FILE" '--minor')" + # Define url locale information. We don't want to show locale + # information inside url for English language. English is the + # default locale and no locale level is used for it. However, if + # we are rendering for a language different from English, the + # locale level in the url should be present. + if [[ $(cli_getCurrentLocale) == 'en' ]];then + DST[10]='' + else + DST[10]="$(cli_getCurrentLocale)/" + fi + + # Apply replacements for translation markers. + while [[ ${COUNT} -lt ${#SRC[*]} ]];do + + # Use sed to replace translation markers inside the design + # model instance. + sed -r -i "s!${SRC[$COUNT]}!${DST[$COUNT]}!g" ${INSTANCE} + + # Increment counter. + COUNT=$(($COUNT + 1)) + + done + + # Unset specific translation markers and specific replacement + # variables in order to clean them up. Otherwise, undesired values + # may ramain from one file to another. + unset SRC + unset DST + +} diff --git a/Scripts/Bash/Functions/Render/render_doTranslationMarkersSpecifics.sh b/Scripts/Bash/Functions/Render/render_doTranslationMarkersSpecifics.sh new file mode 100755 index 0000000..b11126b --- /dev/null +++ b/Scripts/Bash/Functions/Render/render_doTranslationMarkersSpecifics.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# +# render_doTranslationMarkersSpecifics.sh -- This function +# standardizes replacements for specific translation markers. +# Raplacements are applied to temporal instances used to produce the +# final file. +# +# Copyright (C) 2009-2011 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function render_doTranslationMarkersSpecifics { + + # Initialize variables. + local -a SRC + local -a DST + local COUNT=0 + + # Initialize specific translation markers (SRC) variable, and + # replacement (DST) variable using the appropriate translation + # file as reference. + if [[ -x ${TRANSLATION} ]];then + # Initialize action-specific functions. + . $TRANSLATION + else + cli_printMessage "`eval_gettext "The \\\$TRANSLATION hasn't execution rights."`" 'AsErrorLine' + cli_printMessage "$(caller)" "AsToKnowMoreLine" + fi + + # Execute function to retrive specific translation markers and + # specific replacement values. + eval render_loadConfig + + # Apply specific replacements for specific translation markers. + while [[ ${COUNT} -lt ${#SRC[*]} ]];do + + # Escape the character used as separator inside sed's + # replacement command. + DST[$COUNT]=$(echo ${DST[$COUNT]} | sed -r 's/!/\\!/g' ) + + # Use sed to replace specific translation markers inside the + # design model instance. + sed -r -i "s!${SRC[$COUNT]}!${DST[$COUNT]}!g" $INSTANCE + + # Increment counter. + COUNT=$(($COUNT + 1)) + + done + + # Unset specific translation markers and specific replacement + # variables in order to clean them up. Otherwise, undesired values + # may ramain from one file to another. + unset SRC + unset DST + +}