From 786ebb4a2d79be07261ae26d0c1e1080e5318f08 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Feb 08 2011 17:09:54 +0000 Subject: Update `locale' functionality. --- diff --git a/Scripts/Bash/Functions/Locale/locale.sh b/Scripts/Bash/Functions/Locale/locale.sh index d7d72d5..df1b368 100644 --- a/Scripts/Bash/Functions/Locale/locale.sh +++ b/Scripts/Bash/Functions/Locale/locale.sh @@ -1,7 +1,7 @@ #!/bin/bash # -# locale.sh -- This function provides locale features to centos-art.sh -# script. +# locale.sh -- This function provides internationalization features to +# centos-art.sh script by means of gettext. # # Copyright (C) 2009-2011 Alain Reguera Delgado # diff --git a/Scripts/Bash/Functions/Locale/locale_doMessages.sh b/Scripts/Bash/Functions/Locale/locale_doMessages.sh deleted file mode 100755 index 8da3121..0000000 --- a/Scripts/Bash/Functions/Locale/locale_doMessages.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash -# -# locale_doMessages.sh -- This function standardize centos-art.sh -# localization process using gettext commands. All messages inside -# centos-art.sh script are written in English language. -# -# 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_doMessages { - - # 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 9b8f4c2..408060a 100644 --- a/Scripts/Bash/Functions/Locale/locale_getActions.sh +++ b/Scripts/Bash/Functions/Locale/locale_getActions.sh @@ -27,10 +27,10 @@ function locale_getActions { # Define short options we want to support. - local ARGSS="f:" + local ARGSS="" # Define long options we want to support. - local ARGSL="filter:,status,edit" + local ARGSL="filter:,stats:,edit:,update:" # Parse arguments using getopt(1) command parser. cli_doParseArguments @@ -43,35 +43,40 @@ function locale_getActions { while true; do case "$1" in - --status ) + --update ) # Redefine action name. - ACTIONNAM="${FUNCNAM}_doMessagesStatus" + ACTIONNAM="${FUNCNAM}_updateMessages" - # Redefine action value. There is no action value to - # verify here. + # Redefine action value. + ACTIONVAL="$2" # Break while loop. - shift 1 + shift 2 ;; --edit ) # Redefine action name. - ACTIONNAM="${FUNCNAM}_doMessages" + ACTIONNAM="${FUNCNAM}_editMessages" + + # Redefine action value. + ACTIONVAL="$2" + + # Break while loop. + shift 2 + ;; + + --stats ) - # Redefine action value. It is required for - # cli_commitRepoChanges to know where locale changes - # are. - ACTIONVAL=/home/centos/artwork/trunk/Scripts/Bash/Locale + # Redefine action name. + ACTIONNAM="${FUNCNAM}_getStats" - # Verify action value variable. - if [[ $ACTIONVAL == '' ]];then - cli_printMessage "$(caller)" 'AsToKnowMoreLine' - fi + # Redefine action value. + ACTIONVAL="$2" # Break while loop. - shift 1 + shift 2 ;; --filter ) @@ -88,6 +93,11 @@ function locale_getActions { esac done + # Check action value. Be sure the action value matches the + # convenctions defined for source locations inside the working + # copy. + cli_checkRepoDirSource + # Execute action name. if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then eval $ACTIONNAM diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessages.sh b/Scripts/Bash/Functions/Locale/locale_updateMessages.sh new file mode 100755 index 0000000..c869d85 --- /dev/null +++ b/Scripts/Bash/Functions/Locale/locale_updateMessages.sh @@ -0,0 +1,83 @@ +#!/bin/bash +# +# locale_updateMessages.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_updateMessages { + + # 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" + +}