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
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 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
2f2639
    # Verify current locale information to avoid English messages from
2f2639
    # being localized to themselves.  The English language is used as
2f2639
    # reference to write translatable strings inside the source files.
bf603a
    if [[ ${CLI_LANG_LC} =~ '^en' ]];then
2f2639
        cli_printMessage "`gettext "The English language cannot be localized to itself."`" --as-error-line
2f2639
    fi
2f2639
e38698
    # Verify directory passed as non-option argument to be sure it
e38698
    # supports localization.
e38698
    locale_isLocalizable "${ACTIONVAL}"
e38698
    if [[ $? -ne 0 ]];then
e38698
        cli_printMessage "`gettext "The path provided does not support localization."`" --as-error-line
e38698
    fi
e38698
878a2b
    local PO_FILE=''
878a2b
    local PO_FILES=''
878a2b
feac3d
    # Prepare working directory to receive translation files.
1090ef
    locale_prepareWorkingDirectory ${L10N_WORKDIR}
878a2b
e38698
    # Syncronize changes between repository and working copy. At this
e38698
    # point, changes in the repository are merged in the working copy
e38698
    # and changes in the working copy committed up to repository.
02d7e1
    cli_synchronizeRepoChanges "${L10N_WORKDIR}"
e38698
878a2b
    # Define list of PO files to process based on paths provided as
878a2b
    # non-option arguments through centos-art.sh script command-line.
bf603a
    if [[ $ACTIONVAL =~ "^${TCAR_WORKDIR}/trunk/(Documentation/Models/Docbook|Identity/Models)/.*$" ]];then
878a2b
878a2b
        # Define list of PO files for XML-based files.
f2ec26
        PO_FILES=$(cli_getFilesList ${L10N_WORKDIR} --type="f" --pattern="^.+/messages\.po$")
878a2b
878a2b
        # Do not create MO files for XML-based files.
878a2b
        FLAG_DONT_CREATE_MO='true'
878a2b
bf603a
    elif [[ $ACTIONVAL =~ "^${TCAR_WORKDIR}/trunk/Scripts/Bash$" ]];then
878a2b
feac3d
        # Define list of PO files for script files.
f2ec26
        PO_FILES=$(cli_getFilesList ${L10N_WORKDIR} --pattern="^.*${FLAG_FILTER}/messages\.po$")
878a2b
878a2b
    else
878a2b
        cli_printMessage "`gettext "The path provided does not support localization."`" --as-error-line
878a2b
    fi
878a2b
feac3d
    # Verify list of PO files.
feac3d
    if [[ $PO_FILES = "" ]];then
feac3d
        cli_printMessage "`gettext "The path provided hasn't translations yet."`" --as-error-line
feac3d
    else
feac3d
        cli_printMessage '-' --as-separator-line
feac3d
    fi
feac3d
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
    done
878a2b
1090ef
    # At this point some changes might be realized inside the PO file,
1090ef
    # so we need to update the related MO file based on recently
1090ef
    # updated PO files here in order for `centos-art.sh' script to
1090ef
    # print out the most up to date revision of localized messages.
1090ef
    # Notice that this is required only if we were localizaing shell
1090ef
    # scripts.
1090ef
    locale_updateMessageBinary
1090ef
e38698
    # Syncronize changes between repository and working copy. At this
e38698
    # point, changes in the repository are merged in the working copy
e38698
    # and changes in the working copy committed up to repository.
02d7e1
    cli_synchronizeRepoChanges "${L10N_WORKDIR}"
e38698
878a2b
}