Blame Automation/Modules/centos-art.sh-locale/locale_updateMessageMetadata.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# locale_updateMessageMetadata.sh -- This function sanitates .pot and
Alain Reguera Delgado 8f60cb
# .po files to use common translation markers inside top comment.
Alain Reguera Delgado 8f60cb
# Later, replacement of common translation markers is applied to set
Alain Reguera Delgado 8f60cb
# the final information.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function locale_updateMessageMetadata {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local COUNT=0
Alain Reguera Delgado 8f60cb
    local -a SRC
Alain Reguera Delgado 8f60cb
    local -a DST
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Retrive absolute path of portable object we'll work with.
Alain Reguera Delgado 8f60cb
    local FILE="$1"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Check existence of file before work with it.
Alain Reguera Delgado 8f60cb
    cli_checkFiles -e "${FILE}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define pattern lines. The pattern lines are put inside portable
Alain Reguera Delgado 8f60cb
    # objects through xgettext and xml2po commands. In the case of
Alain Reguera Delgado 8f60cb
    # Last-Translators, be sure to remplace it only when it is empty
Alain Reguera Delgado 8f60cb
    # or refer the Documentation SIG only. This way translators' names
Alain Reguera Delgado 8f60cb
    # will survive metadata updates. We don't want they have to type
Alain Reguera Delgado 8f60cb
    # their name each time they edit a file.
Alain Reguera Delgado 8f60cb
    SRC[0]="\"Project-Id-Version:"
Alain Reguera Delgado 8f60cb
    SRC[1]="\"Report-Msgid-Bugs-To:"
Alain Reguera Delgado 8f60cb
    SRC[2]="\"Last-Translator: (Documentation SIG)?"
Alain Reguera Delgado 8f60cb
    SRC[3]="\"Language-Team:"
Alain Reguera Delgado 8f60cb
    SRC[4]="\"PO-Revision-Date:"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define replacement lines for pattern line.
Alain Reguera Delgado 8f60cb
    DST[0]="\"Project-Id-Version: ${CLI_NAME}-${CLI_VERSION}\\\n\""
Alain Reguera Delgado 8f60cb
    DST[1]="\"Report-Msgid-Bugs-To: Documentation SIG <$(cli_printMailingList --docs)>\\\n\""
Alain Reguera Delgado 8f60cb
    DST[2]="\"Last-Translator: Documentation SIG\\\n\""
Alain Reguera Delgado 8f60cb
    DST[3]="\"Language-Team: $(locale_getLanguageName)\\\n\""
Alain Reguera Delgado 8f60cb
    DST[4]="\"PO-Revision-Date: $(date "+%F %H:%M%z")\\\n\""
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Change pattern lines with their replacement lines.
Alain Reguera Delgado 8f60cb
    while [[ $COUNT -lt ${#SRC[*]} ]];do
Alain Reguera Delgado 8f60cb
        sed -i -r "/${SRC[$COUNT]}/c${DST[$COUNT]}" ${FILE}
Alain Reguera Delgado 8f60cb
        COUNT=$(($COUNT + 1))
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # When the .pot file is created using xml2po the
Alain Reguera Delgado 8f60cb
    # `Report-Msgid-Bugs-To:' metadata field isn't created like it
Alain Reguera Delgado 8f60cb
    # does when xgettext is used. So, in order to have such metadata
Alain Reguera Delgado 8f60cb
    # field in all .pot files, verify its existence and add it if it
Alain Reguera Delgado 8f60cb
    # doesn't exist.
Alain Reguera Delgado 8f60cb
    egrep "^\"${SRC[1]}" $FILE > /dev/null
Alain Reguera Delgado 8f60cb
    if [[ $? -ne 0 ]];then
Alain Reguera Delgado 8f60cb
        sed -i -r "/^\"${SRC[0]}/a${DST[1]}" $FILE
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Replace package information using gettext domain information.
Alain Reguera Delgado 8f60cb
    sed -i -r "s/PACKAGE/${CLI_NAME}-${CLI_VERSION}/g" ${FILE}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Remove absolute path to the working copy so it doesn't appear on
Alain Reguera Delgado 8f60cb
    # comments related to locations. Remember that people can download
Alain Reguera Delgado 8f60cb
    # their working copies in different locations and we don't want to
Alain Reguera Delgado 8f60cb
    # version those changes each time a translation message be
Alain Reguera Delgado 8f60cb
    # updated. To be consistent about this, show path information from
Alain Reguera Delgado 8f60cb
    # first level on. Don't show the variable part of the path.
Alain Reguera Delgado 8f60cb
    sed -i -r "s,${TCAR_WORKDIR}/,,g" ${FILE}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Unset array variables to avoid undesired concatenations.
Alain Reguera Delgado 8f60cb
    unset SRC
Alain Reguera Delgado 8f60cb
    unset DST
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}