From 7655b2360708bb866109adb64f43806d0852d691 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Feb 08 2011 17:18:44 +0000 Subject: Update `locale' functionality. --- diff --git a/Scripts/Bash/Functions/Locale/locale_doMessagesStatus.sh b/Scripts/Bash/Functions/Locale/locale_doMessagesStatus.sh deleted file mode 100755 index 22494fc..0000000 --- a/Scripts/Bash/Functions/Locale/locale_doMessagesStatus.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash -# -# locale_doMessagesStatus.sh -- This function outputs the -# centos-art.sh translations table. Use this function to know how many -# languages the centos-art.sh script is available in, the last -# translators and revision dates. -# -# 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_doMessagesStatus { - - # Define variables as local to avoid conflicts outside. - local LOCALESLIST='' - local LANG_NAME='' - local LANG_COUNTRY='' - local PO_LASTAUTHOR='' - local PO_REVDATE='' - local PO_STATUS='' - - # Define list of locale codes. - LOCALESLIST=$(cli_getLocales) - - for LOCALECODE in $LOCALESLIST;do - - LANG_NAME=$(cli_getLangName $LOCALECODE) - LANG_COUNTRY=$(cli_getCountryName $LOCALECODE) - - if [[ -f $TEXTDOMAINDIR/$LOCALECODE/$TEXTDOMAIN.po ]] \ - && [[ -f $TEXTDOMAINDIR/$LOCALECODE/LC_MESSAGES/$TEXTDOMAIN.mo ]];then - - # Re-define translation's status. - PO_STATUS="`gettext "Available"`" - - # Re-define translation's last update. - PO_REVDATE=$(egrep '^"PO-Revision-Date:' $TEXTDOMAINDIR/$LOCALECODE/$TEXTDOMAIN.po \ - | cut -d: -f2- | sed -r 's!\\n"!!' | sed -r 's!^[[:space:]]+!!' | cut -d ' ' -f1) - - # Re-define translation's last author. - PO_LASTAUTHOR=$(egrep '^"Last-Translator:' $TEXTDOMAINDIR/$LOCALECODE/$TEXTDOMAIN.po \ - | cut -d: -f2 | sed -r 's!\\n"!!' | sed -r 's!^[[:space:]]+!!') - - else - - LANGCOUNTRY="" - PO_LASTAUTHOR="" - PO_REVDATE="" - PO_STATUS="" - - fi - - # Output information line. - echo "$LOCALECODE | $LANG_NAME | $LANG_COUNTRY | $PO_STATUS | $PO_REVDATE | $PO_LASTAUTHOR" - - done \ - | egrep -i "$FLAG_FILTER" \ - | awk 'BEGIN {FS="|"; format ="%7s\t%-15s\t%-15s\t%-12s\t%-12s\t%-s\n" - printf "--------------------------------------------------------------------------------\n" - printf format, "'`gettext "Code"`'", " '`gettext "Language"`'", " '`gettext "Country"`'",\ - " '`gettext "Status"`'", " '`gettext "LastRev"`'", " '`gettext "Author"`'" - printf "--------------------------------------------------------------------------------\n"} - {printf format, substr($1,0,7), substr($2,0,15), substr($3,0,15), $4, $5, $6} - END {printf "--------------------------------------------------------------------------------\n"}' -} diff --git a/Scripts/Bash/Functions/Locale/locale_doReport.sh b/Scripts/Bash/Functions/Locale/locale_doReport.sh new file mode 100755 index 0000000..7deb529 --- /dev/null +++ b/Scripts/Bash/Functions/Locale/locale_doReport.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# +# locale_doReport.sh -- This function outputs the centos-art.sh +# translations table. Use this function to know how many languages the +# centos-art.sh script is available in, the last translators and +# revision dates. +# +# 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_doReport { + + # Define variables as local to avoid conflicts outside. + local LOCALESLIST='' + local LANG_NAME='' + local LANG_COUNTRY='' + local PO_LASTAUTHOR='' + local PO_REVDATE='' + local PO_STATUS='' + + # Define list of locale codes. + LOCALESLIST=$(cli_getLocales) + + for LOCALECODE in $LOCALESLIST;do + + LANG_NAME=$(cli_getLangName $LOCALECODE) + LANG_COUNTRY=$(cli_getCountryName $LOCALECODE) + + if [[ -f $TEXTDOMAINDIR/$LOCALECODE/$TEXTDOMAIN.po ]] \ + && [[ -f $TEXTDOMAINDIR/$LOCALECODE/LC_MESSAGES/$TEXTDOMAIN.mo ]];then + + # Re-define translation's status. + PO_STATUS="`gettext "Available"`" + + # Re-define translation's last update. + PO_REVDATE=$(egrep '^"PO-Revision-Date:' $TEXTDOMAINDIR/$LOCALECODE/$TEXTDOMAIN.po \ + | cut -d: -f2- | sed -r 's!\\n"!!' | sed -r 's!^[[:space:]]+!!' | cut -d ' ' -f1) + + # Re-define translation's last author. + PO_LASTAUTHOR=$(egrep '^"Last-Translator:' $TEXTDOMAINDIR/$LOCALECODE/$TEXTDOMAIN.po \ + | cut -d: -f2 | sed -r 's!\\n"!!' | sed -r 's!^[[:space:]]+!!') + + else + + LANGCOUNTRY="" + PO_LASTAUTHOR="" + PO_REVDATE="" + PO_STATUS="" + + fi + + # Output information line. + echo "$LOCALECODE | $LANG_NAME | $LANG_COUNTRY | $PO_STATUS | $PO_REVDATE | $PO_LASTAUTHOR" + + done \ + | egrep -i "$FLAG_FILTER" \ + | awk 'BEGIN {FS="|"; format ="%7s\t%-15s\t%-15s\t%-12s\t%-12s\t%-s\n" + printf "--------------------------------------------------------------------------------\n" + printf format, "'`gettext "Code"`'", " '`gettext "Language"`'", " '`gettext "Country"`'",\ + " '`gettext "Status"`'", " '`gettext "LastRev"`'", " '`gettext "Author"`'" + printf "--------------------------------------------------------------------------------\n"} + {printf format, substr($1,0,7), substr($2,0,15), substr($3,0,15), $4, $5, $6} + END {printf "--------------------------------------------------------------------------------\n"}' +} diff --git a/Scripts/Bash/Functions/Locale/locale_doUpdate.sh b/Scripts/Bash/Functions/Locale/locale_doUpdate.sh new file mode 100755 index 0000000..ad16889 --- /dev/null +++ b/Scripts/Bash/Functions/Locale/locale_doUpdate.sh @@ -0,0 +1,83 @@ +#!/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 408060a..3d2d6c5 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:,stats:,edit:,update:" + local ARGSL="filter:,report:,edit:,update:" # Parse arguments using getopt(1) command parser. cli_doParseArguments @@ -46,7 +46,7 @@ function locale_getActions { --update ) # Redefine action name. - ACTIONNAM="${FUNCNAM}_updateMessages" + ACTIONNAM="${FUNCNAM}_doUpdate" # Redefine action value. ACTIONVAL="$2" @@ -58,7 +58,7 @@ function locale_getActions { --edit ) # Redefine action name. - ACTIONNAM="${FUNCNAM}_editMessages" + ACTIONNAM="${FUNCNAM}_doEdit" # Redefine action value. ACTIONVAL="$2" @@ -70,7 +70,7 @@ function locale_getActions { --stats ) # Redefine action name. - ACTIONNAM="${FUNCNAM}_getStats" + ACTIONNAM="${FUNCNAM}_doReport" # Redefine action value. ACTIONVAL="$2" diff --git a/Scripts/Bash/Functions/Locale/locale_updateMessages.sh b/Scripts/Bash/Functions/Locale/locale_updateMessages.sh deleted file mode 100755 index c869d85..0000000 --- a/Scripts/Bash/Functions/Locale/locale_updateMessages.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/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" - -}