Blame tcar-scripts-locale/Modules/Files/Modules/Update/Modules/Sh/sh.sh

Alain Reguera Delgado f72cfe
#!/bin/bash
Alain Reguera Delgado f72cfe
######################################################################
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
#   sh.sh -- This module retrieves translatable strings from shell
Alain Reguera Delgado f72cfe
#   scripts files. Normally, this function takes the file provided as
Alain Reguera Delgado f72cfe
#   argument in the command-line and creates a list of all files that
Alain Reguera Delgado f72cfe
#   share the same file extension in the same directory structure and
Alain Reguera Delgado f72cfe
#   retrieve translation messages from it.  Translation messages are
Alain Reguera Delgado f72cfe
#   stored in a PO file for each supported language under the Locales
Alain Reguera Delgado f72cfe
#   directory. In case the --recursive option is also provided, the
Alain Reguera Delgado f72cfe
#   list of files to process is build recursively.
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
#   Written by:
Alain Reguera Delgado f72cfe
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado f72cfe
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado f72cfe
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado f72cfe
# your option) any later version.
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado f72cfe
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado f72cfe
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado f72cfe
# General Public License for more details.
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado f72cfe
# along with this program; if not, write to the Free Software
Alain Reguera Delgado f72cfe
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
######################################################################
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
function sh {
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Verify existence and type of file being processed.
Alain Reguera Delgado f72cfe
    tcar_checkFiles -efi 'application/x-shellscript' "${RENDER_FROM}"
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    local FILES=''
Alain Reguera Delgado f72cfe
    local DIRECTORY=$(dirname ${RENDER_FROM})
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Build list of all script files that xgettext will look for
Alain Reguera Delgado f72cfe
    # translatable strings inside. By default only scripts in the
Alain Reguera Delgado f72cfe
    # current directory will be looked out.
Alain Reguera Delgado f72cfe
    if [[ ${LOCALE_FLAG_RECURSIVE} == 'true' ]];then
Alain Reguera Delgado f72cfe
        FILES=$(tcar_getFilesList "${DIRECTORY}" \
Alain Reguera Delgado f72cfe
            --type=f --pattern='.+\.sh$')
Alain Reguera Delgado f72cfe
    else
Alain Reguera Delgado f72cfe
        FILES=$(tcar_getFilesList "${DIRECTORY}" \
Alain Reguera Delgado f72cfe
            --mindepth=1 --maxdepth=1 --type=f \
Alain Reguera Delgado f72cfe
            --pattern='.+\.sh$')
Alain Reguera Delgado f72cfe
    fi
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Verify found files existence and type before processing them.
Alain Reguera Delgado f72cfe
    tcar_checkFiles -efi 'application/x-shellscript' "${FILES}"
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Retrieve translatable strings from shell script files and create
Alain Reguera Delgado f72cfe
    # the portable object template (.pot) from them.
Alain Reguera Delgado f72cfe
    xgettext --output=${POT_FILE} --width=70 \
Alain Reguera Delgado f72cfe
        --package-name=${PACKAGE_NAME} \
Alain Reguera Delgado f72cfe
        --package-version=${PACKAGE_VERSION} \
Alain Reguera Delgado f72cfe
        --msgid-bugs-address="centos-l10n-${TCAR_SCRIPT_LANG_LL}@centos.org.cu" \
Alain Reguera Delgado f72cfe
        --sort-by-file ${FILES}
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # When there is not any translatable string to retrieve from file,
Alain Reguera Delgado f72cfe
    # the POT file is not created. Be aware of this when retrieving
Alain Reguera Delgado f72cfe
    # translatable strings from several files (e.g., you are
Alain Reguera Delgado f72cfe
    # processing a directory full of svgz files, but some of them have
Alain Reguera Delgado f72cfe
    # no translatable string inside).
Alain Reguera Delgado f72cfe
    if [[ ! -f ${POT_FILE} ]];then
Alain Reguera Delgado f72cfe
        return
Alain Reguera Delgado f72cfe
    fi
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Verify, initialize or update portable objects from portable
Alain Reguera Delgado f72cfe
    # object templates.
Alain Reguera Delgado f72cfe
    update_convertPotToPo "${POT_FILE}" "${PO_FILE}"
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # At this point some changes might be realized inside the PO file,
Alain Reguera Delgado f72cfe
    # so we need to update the related MO file based on recently
Alain Reguera Delgado f72cfe
    # updated PO files here in order for `centos-art.sh' script to
Alain Reguera Delgado f72cfe
    # print out the most up to date revision of localized messages.
Alain Reguera Delgado f72cfe
    # Notice that this is required only if we were localizing shell
Alain Reguera Delgado f72cfe
    # scripts because xml-based files don't need the MO files.
Alain Reguera Delgado f72cfe
    update_convertPoToMo
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
}