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

878a2b
#!/bin/bash
878a2b
#
878a2b
# locale_updateMessageMetadata.sh -- This function sanitates .pot and
878a2b
# .po files to use common translation markers inside top comment.
878a2b
# Later, replacement of common translation markers is applied to set
878a2b
# the final information.
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_updateMessageMetadata {
878a2b
878a2b
    local COUNT=0
878a2b
    local -a SRC
878a2b
    local -a DST
878a2b
878a2b
    # Retrive absolute path of portable object we'll work with.
878a2b
    local FILE="$1"
878a2b
878a2b
    # Define current locale.
952524
    local CURRENTLOCALE=$(locale_getCurrentLocale)
878a2b
878a2b
    # Define language name from current locale.
878a2b
    local LANGNAME=$(cli_getLangName ${CURRENTLOCALE})
878a2b
878a2b
    # Check existence of file before work with it.
878a2b
    cli_checkFiles "${FILE}"
878a2b
878a2b
    # Define pattern lines. The pattern lines are put inside portable
add5ea
    # objects through xgettext and xml2po commands. In the case of
add5ea
    # Last-Translators, be sure to remplace it only when it is empty
add5ea
    # or refer the Documentation SIG only. This way translators' names
add5ea
    # will survive metadata updates. We don't want they have to type
add5ea
    # their name each time they edit a file.
878a2b
    SRC[0]="\"Project-Id-Version:"
878a2b
    SRC[1]="\"Report-Msgid-Bugs-To:"
add5ea
    SRC[2]="\"Last-Translator: (Documentation SIG)?"
878a2b
    SRC[3]="\"Language-Team:"
878a2b
    SRC[4]="\"PO-Revision-Date:"
878a2b
878a2b
    # Define replacement lines for pattern line.
fde49a
    DST[0]="\"Project-Id-Version: ${CLI_NAME}-${CLI_VERSION}\\\n\""
5c0ed3
    DST[1]="\"Report-Msgid-Bugs-To: Documentation SIG <${MAILINGLIST_DOCS}>\\\n\""
5c0ed3
    DST[2]="\"Last-Translator: Documentation SIG\\\n\""
878a2b
    DST[3]="\"Language-Team: ${LANGNAME}\\\n\""
878a2b
    DST[4]="\"PO-Revision-Date: $(date "+%F %H:%M%z")\\\n\""
878a2b
878a2b
    # Change pattern lines with their replacement lines.
878a2b
    while [[ $COUNT -lt ${#SRC[*]} ]];do
878a2b
        sed -i -r "/${SRC[$COUNT]}/c${DST[$COUNT]}" ${FILE}
878a2b
        COUNT=$(($COUNT + 1))
878a2b
    done
878a2b
878a2b
    # When the .pot file is created using xml2po the
878a2b
    # `Report-Msgid-Bugs-To:' metadata field isn't created like it
878a2b
    # does when xgettext is used. So, in order to have such metadata
878a2b
    # field in all .pot files, verify its existence and add it if it
878a2b
    # doesn't exist.
878a2b
    egrep "^\"${SRC[1]}" $FILE > /dev/null
878a2b
    if [[ $? -ne 0 ]];then
878a2b
        sed -i -r "/^\"${SRC[0]}/a${DST[1]}" $FILE
878a2b
    fi
878a2b
878a2b
    # Replace package information using gettext domain information.
fde49a
    sed -i -r "s/PACKAGE/${CLI_NAME}-${CLI_VERSION}/g" ${FILE}
878a2b
5c0ed3
    # Remove absolute path to the working copy so it doesn't appear on
5c0ed3
    # comments related to locations. Remember that people can download
5c0ed3
    # their working copies in different locations and we don't want to
5c0ed3
    # version those changes each time a translation message be
5c0ed3
    # updated. To be consistent about this, show path information from
5c0ed3
    # trunk level on. Don't show the variable part of the path.
5c0ed3
    sed -i -r "s,${TCAR_WORKDIR}/,,g" ${FILE}
5c0ed3
878a2b
    # Expand translation markers inside file.
878a2b
    cli_expandTMarkers ${FILE}
878a2b
878a2b
    # Unset array variables to avoid undesired concatenations.
878a2b
    unset SRC
878a2b
    unset DST
878a2b
878a2b
}