From 2eb4e73186590e6ead19d3b589b79862f0a024a7 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Oct 07 2013 05:56:49 +0000 Subject: Update locale module of centos-art.sh script. - Previously, when updating shell script localization files, the sh function was using the script name and version. In a per-module localization such information isn't accurate. This update changes the sh function to set the name of the file being localized as name of the package and keep using the script version. - Previously, the update_setPoMetadata function was creating PO files with the script information. In this update, it was changed to use the package name and package version based on the information set in sh function. - Previously, the update_setPoMetadata function was creating PO files with both package name and package version inside comments. The comments are created just one so the next time the PO file be updated none information in the comment will be updated. This would result in comments describing an older version of the current file. This update changes the update_setPoMetadata function to use only the name of the package and removes the package version from it. - Add the locale_getFilesList.sh file. - Previously, the locale module controlled the number of files it would process using the --filter option and the configuration section of configuration files as reference. Locations that doesn't have a configuration file (because don't need one) had no way to control the way files inside would be processed by the locale module. This update changes the locale.sh file to introduce the LOCALE_FLAG_TYPE flag. This flag is controlled from the command-line using the --type option. This option receives one value as argument. When the value is "self" (the default), the locale module produces localization files just for the file you passed as argument in the command-line. When the value is "siblings", the locale module creates localization files for all the files considered siblings of that you provided in the command-line line. When the value is "all", the locale looks recursively for all the files that share the same file extension of that one you provided in the command-line and create localization files for all of them. In all these three cases, the locale module creates just one set of POT, PO and MO files using the file name of the file you provided as argument in the command-line. - Previously, the locale module doesn't allow you to localize variation of English language. This update changes the locales.sh file to allow localization of any English variant. In fact, the restriction was changed to restrict self translations of C locale only. The locale module must now be able to support localization of any language supported by the system you are running it on. --- diff --git a/Automation/Modules/Locale/Modules/Actions/Modules/Update/Modules/Sh/sh.sh b/Automation/Modules/Locale/Modules/Actions/Modules/Update/Modules/Sh/sh.sh index 0e2691c..a7d3477 100755 --- a/Automation/Modules/Locale/Modules/Actions/Modules/Update/Modules/Sh/sh.sh +++ b/Automation/Modules/Locale/Modules/Actions/Modules/Update/Modules/Sh/sh.sh @@ -30,11 +30,21 @@ function sh { # Print action message. tcar_printMessage "${POT_FILE}" --as-updating-line + # Define package name. This is the name of the initialization file + # you provided as argument to the command line to provide + # localization for. + local PACKAGE_NAME=${FILE_NAME} + + # Define package version. The script version is used here. Modules + # doesn't have a version by now. They share the same version of + # the centos-art.sh script. + local PACKAGE_VERSION=${TCAR_SCRIPT_VERSION} + # Retrieve translatable strings from shell script files and create # the portable object template (.pot) from them. xgettext --output=${POT_FILE} --width=70 \ - --package-name=${TCAR_SCRIPT_NAME} \ - --package-version=${TCAR_SCRIPT_VERSION} \ + --package-name=${PACKAGE_NAME} \ + --package-version=${PACKAGE_VERSION} \ --msgid-bugs-address="centos-l10n-${TCAR_SCRIPT_LANG_LL}@centos.org.cu" \ --copyright-holder="$(tcar_printCopyrightInfo --holder)" \ --sort-by-file ${SOURCES[*]} diff --git a/Automation/Modules/Locale/Modules/Actions/Modules/Update/update_setPoMetadata.sh b/Automation/Modules/Locale/Modules/Actions/Modules/Update/update_setPoMetadata.sh index d8b6764..438e8d8 100755 --- a/Automation/Modules/Locale/Modules/Actions/Modules/Update/update_setPoMetadata.sh +++ b/Automation/Modules/Locale/Modules/Actions/Modules/Update/update_setPoMetadata.sh @@ -49,7 +49,7 @@ function update_setPoMetadata { SRC[3]="\"PO-Revision-Date: (.+)?" # Define replacement lines for pattern line. - DST[0]="\"Project-Id-Version: ${TCAR_SCRIPT_NAME} ${TCAR_SCRIPT_VERSION}\\\n\"" + DST[0]="\"Project-Id-Version: ${PACKAGE_NAME} ${PACKAGE_VERSION}\\\n\"" DST[1]="\"Last-Translator: Localization SIG \\\n\"" DST[2]="\"Language-Team: $(update_getLanguageName)\\\n\"" DST[3]="\"PO-Revision-Date: $(date "+%F %H:%M%z")\\\n\"" @@ -61,7 +61,9 @@ function update_setPoMetadata { done # Replace package information using gettext domain information. - sed -i -r "s/PACKAGE/${TCAR_SCRIPT_NAME}-${TCAR_SCRIPT_VERSION}/g" ${PO_FILE} + # Don't include version here to prevent old version to be shown in + # the comment area when new versions of the package are created. + sed -i -r "s/PACKAGE/${PACKAGE_NAME}/g" ${PO_FILE} # Remove absolute path to the working copy so it doesn't appear on # comments related to locations. Remember that people can download diff --git a/Automation/Modules/Locale/Modules/File/file.sh b/Automation/Modules/Locale/Modules/File/file.sh index a98ff81..f1d5eed 100755 --- a/Automation/Modules/Locale/Modules/File/file.sh +++ b/Automation/Modules/Locale/Modules/File/file.sh @@ -44,12 +44,14 @@ function file { local DIRECTORY=$(dirname ${FILE}) # Define list of files to process. - local RENDER_FROM=$(tcar_getFilesList ${DIRECTORY} \ - --pattern="^.+/.+\.${FILE_EXTENSION}$" --type="f") + local RENDER_FROM=$(locale_getFilesList) # Define absolute path to directory holding language-specific # content. local LOCALE_FROM=${DIRECTORY}/Locales + if [[ ! -d ${LOCALE_FROM} ]];then + mkdir ${LOCALE_FROM} + fi # Define absolute path to portable and machine objects. local POT_FILE=${LOCALE_FROM}/${FILE_NAME}.pot diff --git a/Automation/Modules/Locale/locale.sh b/Automation/Modules/Locale/locale.sh index 8bbc85b..ddf4d91 100755 --- a/Automation/Modules/Locale/locale.sh +++ b/Automation/Modules/Locale/locale.sh @@ -29,6 +29,12 @@ function locale { local ACTIONS='' + # Define the type of file processing the locale module will do. + # The locale module can perform process just one file (self), all + # the siblings files in the current location (siblings) only, or + # all files in the current location recursively (all). + local LOCALE_FLAG_TYPE='self' + # Interpret arguments and options passed through command-line. locale_getOptions @@ -36,8 +42,8 @@ function locale { # from being localized to themselves. The English language is used # as reference to write translatable strings inside the source # files. - if [[ ${TCAR_SCRIPT_LANG_LC} =~ '^en' ]];then - tcar_printMessage "`gettext "The English language cannot be localized to itself."`" --as-error-line + if [[ ${TCAR_SCRIPT_LANG_LC} =~ '^C$' ]];then + tcar_printMessage "`gettext "The C locale cannot be localized to itself."`" --as-error-line fi # Process arguments passed to locale module, based on whether they diff --git a/Automation/Modules/Locale/locale_getFilesList.sh b/Automation/Modules/Locale/locale_getFilesList.sh new file mode 100755 index 0000000..62016c1 --- /dev/null +++ b/Automation/Modules/Locale/locale_getFilesList.sh @@ -0,0 +1,56 @@ +#!/bin/bash +###################################################################### +# +# locale_getFilesList.sh -- This function prints to standard output +# the list of files that locale module will use for processing. The +# list of files is conditioned by the LOCALE_FLAG_TYPE variable to +# determine whether the processing is applied to one file, all files +# in a directory only or all files in a directory recursively. By +# default one file processing is performed. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function locale_getFilesList { + + case ${LOCALE_FLAG_TYPE} in + + 'all' ) + # Process all files in the current location recursively. + tcar_getFilesList ${DIRECTORY} --type="f" \ + --pattern="^.+/.+\.${FILE_EXTENSION}$" + ;; + + 'siblings' ) + # Process all files in the current location only. + tcar_getFilesList ${DIRECTORY} --maxdepth=1 --mindepth=1 \ + --type="f" --pattern="^.+/.+\.${FILE_EXTENSION}$" + ;; + + 'self' | * ) + # Process the file provided only. + tcar_getFilesList ${DIRECTORY} --maxdepth=1 --mindepth=1 \ + --type="f" --pattern="^.+/${FILE_NAME}$" + ;; + + esac + +} diff --git a/Automation/Modules/Locale/locale_getOptions.sh b/Automation/Modules/Locale/locale_getOptions.sh index 585e8d4..0da249d 100755 --- a/Automation/Modules/Locale/locale_getOptions.sh +++ b/Automation/Modules/Locale/locale_getOptions.sh @@ -28,10 +28,10 @@ function locale_getOptions { # Define short options we want to support. - local ARGSS="h::,v,f:" + local ARGSS="h::,v,f:,t:" # Define long options we want to support. - local ARGSL="help::,version,filter:,update,edit,delete" + local ARGSL="help::,version,filter:,update,edit,delete,type:" # Redefine arguments using getopt(1) command parser. tcar_setModuleArguments @@ -72,6 +72,13 @@ function locale_getOptions { shift 1 ;; + -t | --type ) + LOCALE_FLAG_TYPE="${2:-self}" + tcar_checkFiles -m '^(self|siblings|all)$' "${LOCALE_FLAG_TYPE}" + shift 2 + ;; + + -- ) shift 1 break