Blame Scripts/Bash/Functions/Locale/locale_editMessages.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# locale_editMessages.sh -- This function edits portable objects (.po)
878a2b
# using default text editor.
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function locale_editMessages {
878a2b
878a2b
    # Print separator line.
878a2b
    cli_printMessage '-' --as-separator-line
878a2b
878a2b
    local PO_FILE=''
878a2b
    local PO_FILES=''
878a2b
878a2b
    # Prepare localization working directory for receiving translation
878a2b
    # files.
878a2b
    if [[ ! -d ${L10N_WORKDIR} ]];then
878a2b
878a2b
        # Print separator line.
878a2b
        cli_printMessage "-" --as-separator-line
878a2b
878a2b
        # Output action message.
878a2b
        cli_printMessage "${L10N_WORKDIR}" --as-creating-line
878a2b
878a2b
        # Create localization working directory making parent
878a2b
        # directories as needed. Subversion doesn't create directories
878a2b
        # recursively, so we use the system's `mkdir' command and then
878a2b
        # subversion to register the changes.
878a2b
        mkdir -p ${L10N_WORKDIR}
878a2b
878a2b
        # Commit changes from working copy to central repository only.
878a2b
        # At this point, changes in the repository are not merged in
878a2b
        # the working copy, but chages in the working copy do are
878a2b
        # committed up to repository.
878a2b
        cli_commitRepoChanges "${L10N_BASEDIR}"
878a2b
878a2b
    fi
878a2b
878a2b
    # Define list of PO files to process based on paths provided as
878a2b
    # non-option arguments through centos-art.sh script command-line.
878a2b
    if [[ $ACTIONVAL =~ "^$(cli_getRepoTLDir)/(Manuals|Identity/Models)/.*$" ]];then
878a2b
878a2b
        # Define list of PO files for XML-based files.
878a2b
        PO_FILES=$(cli_getFilesList ${L10N_WORKDIR} --pattern=".*/messages\.po")
878a2b
878a2b
        # Do not create MO files for XML-based files.
878a2b
        FLAG_DONT_CREATE_MO='true'
878a2b
878a2b
    elif [[ $ACTIONVAL =~ "^$(cli_getRepoTLDir)/Scripts$" ]];then
878a2b
878a2b
        # Define list of PO files for shell scripts.
878a2b
        PO_FILES=$(cli_getFilesList ${L10N_WORKDIR} --pattern=".*/${TEXTDOMAIN}\.po")
878a2b
878a2b
    else
878a2b
        cli_printMessage "`gettext "The path provided does not support localization."`" --as-error-line
878a2b
    fi
878a2b
878a2b
    # Loop through list of PO files to process in order to edit them
878a2b
    # one by one using user's default text editor.
878a2b
    for PO_FILE in ${PO_FILES};do
878a2b
878a2b
        # Print the file we are editing.
878a2b
        cli_printMessage "${PO_FILE}" --as-updating-line
878a2b
878a2b
        # Use default text editor to edit the PO file.
878a2b
        eval ${EDITOR} ${PO_FILE}
878a2b
878a2b
        # At this point some changes might be realized inside the PO
878a2b
        # file, so we need to update the related MO files based on
878a2b
        # recently updated PO files here in order for `centos-art.sh'
878a2b
        # script to print out the most up to date revision of
878a2b
        # localized messages. Notice that this is required only if we
878a2b
        # were localizaing shell scripts.
878a2b
        locale_updateMessageBinary ${PO_FILE}
878a2b
878a2b
    done
878a2b
878a2b
}