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
#
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_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.
878a2b
    local CURRENTLOCALE=$(cli_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
878a2b
    # objects through xgettext and xml2po commands .
878a2b
    SRC[0]="\"Project-Id-Version:"
878a2b
    SRC[1]="\"Report-Msgid-Bugs-To:"
878a2b
    SRC[2]="\"Last-Translator:"
878a2b
    SRC[3]="\"Language-Team:"
878a2b
    SRC[4]="\"PO-Revision-Date:"
878a2b
878a2b
    # Define replacement lines for pattern line.
b74d4e
    DST[0]="\"Project-Id-Version: ${CLI_NAME}-${CLI_VERSION}\\\n\""
b74d4e
    DST[1]="\"Report-Msgid-Bugs-To: Translation SIG\\\n\""
b74d4e
    DST[2]="\"Last-Translator: Translation SIG <${MAILINGLIST_L10N}>\\\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.
b74d4e
    sed -i -r "s/PACKAGE/${CLI_NAME}-${CLI_VERSION}/g" ${FILE}
878a2b
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
}