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
#
e6bbbf
# Copyright (C) 2009-2013 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
08b3a3
    # Verify directory passed as non-option argument to be sure it
08b3a3
    # supports localization.
08b3a3
    locale_isLocalizable "${ACTIONVAL}"
08b3a3
878a2b
    local PO_FILE=''
878a2b
    local PO_FILES=''
878a2b
78487b
    # Define location where translation files will be stored in
78487b
    # without language information in it. The language information is
78487b
    # put later, when we build the list of files.
78487b
    local L10N_WORKDIR=$(cli_getLocalizationDir "${ACTIONVAL}" "--no-lang")
878a2b
78487b
    # Prepare working directory to receive translation files. Don't do
78487b
    # this here. It is already done as part the update actions, but we
78487b
    # need it here for those cases when no update action is run and
78487b
    # one execute the edit option.
78487b
    locale_prepareWorkingDirectory ${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.
78487b
    if [[ $ACTIONVAL =~ "^${TCAR_WORKDIR}/(Documentation/Models/(Docbook|Svg)|Identity/Models)/.*$" ]];then
878a2b
878a2b
        # Do not create MO files for XML-based files.
878a2b
        FLAG_DONT_CREATE_MO='true'
878a2b
878a2b
    fi
78487b
     
78487b
    # Define list of PO files we want to work with. Don't forget to
78487b
    # include the language information here.
78487b
    PO_FILES=$(cli_getFilesList ${L10N_WORKDIR} --type="f" \
78487b
        --pattern=".+/${FLAG_FILTER}/${CLI_LANG_LC}/messages\.po$")
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
78487b
    # Synchronize changes between repository and working copy. At this
78487b
    # point, changes in the repository are merged in the working copy
78487b
    # and changes in the working copy committed up to repository.
78487b
    cli_synchronizeRepoChanges "${PO_FILES}"
78487b
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.
819c26
    # Notice that this is required only if we were localizing shell
1090ef
    # scripts.
1090ef
    locale_updateMessageBinary
1090ef
78487b
    # Synchronize 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.
78487b
    cli_synchronizeRepoChanges "${PO_FILES}"
e38698
878a2b
}