diff --git a/Scripts/Bash/Functions/Locale/locale_doUpdate.sh b/Scripts/Bash/Functions/Locale/locale_doUpdate.sh deleted file mode 100755 index ad16889..0000000 --- a/Scripts/Bash/Functions/Locale/locale_doUpdate.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/bash -# -# locale_doUpdate.sh -- This function standardize centos-art.sh -# internationalization processes using xml2po and gettext commands. -# -# 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 locale_doUpdate { - - # Define variables as local to avoid conflicts outside. - local POT_FILE=$TEXTDOMAINDIR/$(cli_getCurrentLocale)/$TEXTDOMAIN.pot - local PO_FILE=$TEXTDOMAINDIR/$(cli_getCurrentLocale)/$TEXTDOMAIN.po - local MO_FILE=$TEXTDOMAINDIR/$(cli_getCurrentLocale)/LC_MESSAGES/$TEXTDOMAIN.mo - local LANGNAME=$(cli_getLangName $(cli_getCurrentLocale)) - local PO_HEAD_DATE='' - local PO_HEAD_BUGS='' - - # Output action message. - cli_printMessage "`gettext "The following translation files will be updated:"`" - cli_printMessage "$POT_FILE" "AsResponseLine" - cli_printMessage "$PO_FILE" "AsResponseLine" - cli_printMessage "$MO_FILE" "AsResponseLine" - cli_printMessage "`gettext "Do you want to continue?"`" "AsYesOrNoRequestLine" - - # Prepare directory structure for centos-art.sh localization - # files. - if [[ ! -d $(dirname $MO_FILE) ]];then - mkdir -p $(dirname $MO_FILE) - fi - - # Create portable object template (.pot). - find /home/centos/artwork/trunk/Scripts/Bash -name '*.sh' \ - | xargs xgettext --language=Shell --output=$POT_FILE - - - # Create portable object (.po) for the current language. - if [[ ! -f $PO_FILE ]];then - msginit --input=$POT_FILE --output=$PO_FILE - else - msgmerge --update $PO_FILE $POT_FILE - fi - - # Update portable object bugs report in its header entries. This - # entry is removed each time the portable object is generated. To - # avoid loosing its value, re-define it before editing the portable - # object (.po) file. - PO_HEAD_BUGS="\"Report-Msgid-Bugs-To: CentOS Documentation SIG \\\n\"" - sed -i -r "/^\"Report-Msgid-Bugs-To:/c$PO_HEAD_BUGS" $PO_FILE - - # Edit portable object (.po) for the current language. In this - # step is when translators do their work. - eval $EDITOR $PO_FILE - - # Update portable object revision date in its header entries. - PO_HEAD_DATE="\"PO-Revision-Date: $(date "+%Y-%m-%d %H:%M%z")\\\n\"" - sed -i -r "/^\"PO-Revision-Date:/c$PO_HEAD_DATE" $PO_FILE - - # Create machine object (.mo). - msgfmt $PO_FILE --output=$MO_FILE - - # Check repository changes and ask you to commit them up to - # central repository. - cli_commitRepoChanges "$TEXTDOMAINDIR" - -} diff --git a/Scripts/Bash/Functions/Locale/locale_getActions.sh b/Scripts/Bash/Functions/Locale/locale_getActions.sh index 3d2d6c5..abe52ea 100644 --- a/Scripts/Bash/Functions/Locale/locale_getActions.sh +++ b/Scripts/Bash/Functions/Locale/locale_getActions.sh @@ -30,7 +30,7 @@ function locale_getActions { local ARGSS="" # Define long options we want to support. - local ARGSL="filter:,report:,edit:,update:" + local ARGSL="update:,edit:,report:" # Parse arguments using getopt(1) command parser. cli_doParseArguments @@ -46,7 +46,7 @@ function locale_getActions { --update ) # Redefine action name. - ACTIONNAM="${FUNCNAM}_doUpdate" + ACTIONNAM="${FUNCNAM}_updateMessages" # Redefine action value. ACTIONVAL="$2" @@ -58,7 +58,7 @@ function locale_getActions { --edit ) # Redefine action name. - ACTIONNAM="${FUNCNAM}_doEdit" + ACTIONNAM="${FUNCNAM}_editMessages" # Redefine action value. ACTIONVAL="$2" @@ -67,10 +67,10 @@ function locale_getActions { shift 2 ;; - --stats ) + --report ) # Redefine action name. - ACTIONNAM="${FUNCNAM}_doReport" + ACTIONNAM="${FUNCNAM}_printTranslationReport" # Redefine action value. ACTIONVAL="$2" @@ -79,17 +79,9 @@ function locale_getActions { shift 2 ;; - --filter ) - - # Redefine filter (regular expression) flag. - FLAG_FILTER="$2" - - # Rotate positional parameters - shift 2 - ;; - * ) break + ;; esac done diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageMetadata.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageMetadata.sh new file mode 100755 index 0000000..f8e500c --- /dev/null +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageMetadata.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# +# locale_updateMessageMetadata.sh -- This function sanitates .pot and +# .po files to use common translation markers inside top comment. +# Later, replacement of common translation markers is applied to set +# the final information. +# +# 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. +# +# ---------------------------------------------------------------------- +# $Id4 +# ---------------------------------------------------------------------- + +function locale_updateMessageMetadata { + + local COUNT=0 + local -a SRC + local -a DST + + # Retrive absolute path of portable object we'll work with. + local FILE="$1" + + # Define current locale. + local CURRENTLOCALE=$(cli_getCurrentLocale) + + # Define language name from current locale. + local LANGNAME=$(cli_getLangName ${CURRENTLOCALE}) + + # Define language code from current locale. + local LANGCODE=$(cli_getLangCodes ${CURRENTLOCALE}) + + # Check existence of file before work with it. + cli_checkFiles "${FILE}" 'f' + + # Define comment patterns. Comment patterns are put inside + # portable objects when they are built using xgettext or xml2po + # commands. + SRC[0]='Project-Id-Version:' + SRC[1]='Last-Translator:' + SRC[2]='Language-Team:' + + # Define comment replacements. Comment replacements is the + # convenction we use inside centos-art.sh to set standard + # information related to CentOS (e.g., URLs, mail addresses, + # release numbers, etc.). + DST[0]="\"Project-Id-Version: $(cli_getRepoName "${FILE}" 'dfd')\\\n\"" + DST[1]="\"Last-Translator: CentOS Documentation SIG \\\n\"" + DST[2]="\"Language-Team: ${LANGNAME} \\\n\"" + + # Replace comment patterns with comment replacements. + while [[ $COUNT -lt ${#SRC[*]} ]];do + sed -i -r "/${SRC[$COUNT]}/c${DST[$COUNT]}" ${FILE} + COUNT=$(($COUNT + 1)) + done + + # Apply common replacements to sanitated patterns. + cli_replaceTMarkers "${FILE}" + + # Unset array variables to avoid undesired concatenations. + unset SRC + unset DST + +} diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh b/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh new file mode 100755 index 0000000..74b01e0 --- /dev/null +++ b/Scripts/Bash/Functions/Locale/locale_updateMessageXml.sh @@ -0,0 +1,83 @@ +#!/bin/bash +# +# locale_updateMessageXml.sh -- This function parses scalable vector +# graphics files, retrives translatable strings and creates/update +# portable object templates for each one of them. +# +# 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 locale_updateMessageXml { + + # Redefine filter pattern in order to reduce match to scalable + # vector graphics only. + local FLAG_FILTER="${FLAG_FILTER}.*\.(xml|svg)" + + # Define location where XML-based files (e.g., scalable vector + # graphics), we want to have translation for, are place in. + local LOCATION="${ACTIONVAL}" + + # Define name of file used to create both portable object + # templates (.pot) and portable objects (.po) files. + local FILE="${ACTIONVAL}/$(cli_getCurrentLocale)" + + # Build list of XML-base files which we want retrive translatable + # strings from. + cli_getFilesList "${LOCATION}" + + # Print out action preamble. Since the `--filter' option can be + # supplied, it is useful to know which files we are getting + # translatable strings from. + cli_printActionPreamble "${FILES}" "doLocale" 'AsResponseLine' + + # Print action message. + cli_printMessage "${FILE}.pot" 'AsUpdatingLine' + + # Retrive translatable strings from XML-based files and + # create the portable object template (.pot) for them. + /usr/bin/xml2po ${FILES} \ + | msgcat --output=${FILE}.pot --width=70 --sort-by-file - + + if [[ ! -f ${FILE}.po ]];then + + # Create portable object using portable object template, at + # the same time we use output to print the action message. + # There is no --quiet option for msginit command that let to + # separate both printing action message and creation command + # apart one from another). + cli_printMessage $(msginit -i ${FILE}.pot -o ${FILE}.po --width=70 \ + --no-translator 2>&1 | cut -d' ' -f2 | sed -r 's!\.$!!') 'AsCreatingLine' + + # Sanitate portable object metadata. + locale_updateMessageMetadata "${FILE}.po" + + else + + # Print action message. + cli_printMessage "${FILE}.po" 'AsUpdatingLine' + + # Update portable object merging both portable object and + # portable object template. + msgmerge --output="${FILE}.po" "${FILE}.po" "${FILE}.pot" --quiet + + fi + +} diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessages.sh b/Scripts/Bash/Functions/Locale/locale_updateMessages.sh new file mode 100755 index 0000000..5cd4d6e --- /dev/null +++ b/Scripts/Bash/Functions/Locale/locale_updateMessages.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# +# locale_updateMessages.sh -- This function updates translatable +# strings inside portable object templates (.pot) and creates portable +# objects (.po) from it. Translatable strings are taken from both +# XML-based files (using xml2po) and shell scripts (using xgettext). +# +# 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 locale_updateMessages { + + local ACTIONNAM='' + + # Define base directory structure where locale files (.pot, .po, + # .mo) are stored using parallel directories layout. + local ACTIONDIR="$(cli_getRepoTLDir)/Locales" + + # Syncronize changes between the working copy and the central + # repository. + cli_commitRepoChanges "${ACTIONDIR}" + + # Evaluate action value to determine whether to use xml2po to + # extract translatable strings from XML-based files or to use + # xgettext to extract translatable strings from shell script + # files. + if [[ $ACTIONVAL =~ "^${ACTIONDIR}/(Identity|Manuals)/.+$" ]];then + # Update translatable strings inside portable object templates + # for XML-based files (e.g., scalable vector graphics). + ACTIONNAM="${FUNCNAM}_updateMessageXml" + elif [[ $ACTIONVAL =~ "^${ACTIONDIR}/Scripts/.+$" ]];then + # Update translatable strings inside portable object templates + # for shell scripts (e.g., centos-art.sh script). + ACTIONNAM="${FUNCNAM}_updateMessageShell" + else + cli_printMessage "`gettext "The path provided can't be processed."`" 'AsErrorLine' + cli_printMessage "$(caller)" 'AsToKnowMoreLine' + fi + + # Execute action name. + if [[ $ACTIONNAM != '' ]];then + eval $ACTIONNAM + fi + + # Syncronize changes between the working copy and the central + # repository. + cli_commitRepoChanges "${ACTIONDIR}" + +}