Blame Automation/Modules/Locale/locale_updateMessageMetadata.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 52ee2e
######################################################################
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 52ee2e
#   locale_updateMessageMetadata.sh -- This function sanitates .pot
Alain Reguera Delgado 52ee2e
#   and .po files to use common translation markers inside top
Alain Reguera Delgado 52ee2e
#   comment.  Later, replacement of common translation markers is
Alain Reguera Delgado 52ee2e
#   applied to set the final information.
Alain Reguera Delgado 52ee2e
#
Alain Reguera Delgado 52ee2e
#   Written by:
Alain Reguera Delgado 52ee2e
#   * Alain Reguera Delgado <al@centos.org.cu>
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 52ee2e
# the Free Software Foundation; either version 2 of the License, or
Alain Reguera Delgado 52ee2e
# (at 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 52ee2e
######################################################################
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 52ee2e
    # Retrieve absolute path of portable object we'll work with.
Alain Reguera Delgado 52ee2e
    local PO="${1}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Check existence of file before work with it.
Alain Reguera Delgado 52ee2e
    tcar_checkFiles "${PO}" -f
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 52ee2e
    SRC[2]="\"Last-Translator: (.+)?"
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 52ee2e
    DST[0]="\"Project-Id-Version: ${TCAR_SCRIPT_NAME} ${TCAR_SCRIPT_VERSION}\\\n\""
Alain Reguera Delgado 52ee2e
    DST[1]="\"Report-Msgid-Bugs-To: Documentation SIG <centos-docs@centos.org.cu>\\\n\""
Alain Reguera Delgado 52ee2e
    DST[2]="\"Last-Translator: Documentation SIG <centos-docs@centos.org.cu>\\\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 52ee2e
        sed -i -r "/${SRC[$COUNT]}/c${DST[$COUNT]}" ${PO}
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 52ee2e
    egrep "^\"${SRC[1]}" ${PO} > /dev/null
Alain Reguera Delgado 8f60cb
    if [[ $? -ne 0 ]];then
Alain Reguera Delgado 52ee2e
        sed -i -r "/^\"${SRC[0]}/a${DST[1]}" ${PO}
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Replace package information using gettext domain information.
Alain Reguera Delgado 52ee2e
    sed -i -r "s/PACKAGE/${TCAR_SCRIPT_NAME} ${TCAR_SCRIPT_VERSION}/g" ${PO}
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 52ee2e
    sed -i -r "s,${TCAR_BASEDIR}/,,g" ${PO}
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
}