Blame Scripts/Functions/Locale/locale_updateMessageMetadata.sh

4e4b4d
#!/bin/bash
4e4b4d
#
4e4b4d
# locale_updateMessageMetadata.sh -- This function sanitates .pot and
4e4b4d
# .po files to use common translation markers inside top comment.
4e4b4d
# Later, replacement of common translation markers is applied to set
4e4b4d
# the final information.
4e4b4d
#
4e4b4d
# Copyright (C) 2009-2011 Alain Reguera Delgado
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
dcd347
# This program is distributed in the hope that it will be useful,
dcd347
# but WITHOUT ANY WARRANTY; without even the implied warranty of
4e4b4d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4e4b4d
# General Public License for more details.
4e4b4d
#
4e4b4d
# You should have received a copy of the GNU General Public License
4e4b4d
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4e4b4d
# ----------------------------------------------------------------------
4e4b4d
# $Id4
4e4b4d
# ----------------------------------------------------------------------
4e4b4d
4e4b4d
function locale_updateMessageMetadata {
4e4b4d
4e4b4d
    local COUNT=0
4e4b4d
    local -a SRC
4e4b4d
    local -a DST
4e4b4d
4e4b4d
    # Retrive absolute path of portable object we'll work with.
4e4b4d
    local FILE="$1"
4e4b4d
4e4b4d
    # Define current locale.
4e4b4d
    local CURRENTLOCALE=$(cli_getCurrentLocale)
4e4b4d
4e4b4d
    # Define language name from current locale.
4e4b4d
    local LANGNAME=$(cli_getLangName ${CURRENTLOCALE})
4e4b4d
4e4b4d
    # Check existence of file before work with it.
4e4b4d
    cli_checkFiles "${FILE}" 'f'
4e4b4d
bf6bff
    # Define pattern lines. The pattern lines are put inside portable
bec0a3
    # objects through xgettext and xml2po commands .
4e4b4d
    SRC[0]='Project-Id-Version:'
bec0a3
    SRC[1]='Report-Msgid-Bugs-To:'
bec0a3
    SRC[2]='Last-Translator:'
bec0a3
    SRC[3]='Language-Team:'
4e4b4d
bf6bff
    # Define replacement lines for pattern line.
7b46a4
    DST[0]="\"Project-Id-Version: ${CLI_PROGRAM} (${CURRENTLOCALE})\\\n\""
988694
    DST[1]="\"Report-Msgid-Bugs-To: CentOS Documentation SIG <=MAIL_DOCS=>\\\n\""
988694
    DST[2]="\"Last-Translator: CentOS Documentation SIG <=MAIL_DOCS=>\\\n\""
bec0a3
    DST[3]="\"Language-Team: ${LANGNAME}\\\n\""
4e4b4d
bec0a3
    # Change pattern lines with their replacement lines.
4e4b4d
    while [[ $COUNT -lt ${#SRC[*]} ]];do
4e4b4d
        sed -i -r "/${SRC[$COUNT]}/c${DST[$COUNT]}" ${FILE}
4e4b4d
        COUNT=$(($COUNT + 1))
4e4b4d
    done
4e4b4d
988694
    # When the .pot file is created using xml2po the
988694
    # `Report-Msgid-Bugs-To:' metadata field isn't created like it
988694
    # does when xgettext is used. So, in order to have such metadata
988694
    # field in all .pot files, verify its existence and add it if it
988694
    # doesn't exist.
988694
    egrep "^\"${SRC[1]}" $FILE > /dev/null
988694
    if [[ $? -ne 0 ]];then
988694
        sed -i -r "/^\"${SRC[0]}/a${DST[1]}" $FILE
988694
    fi
988694
bec0a3
    # Replace package information using gettext domain information.
bec0a3
    sed -i -r "s/PACKAGE/${TEXTDOMAIN}/g" ${FILE}
bec0a3
988694
    # Expand translation markers inside file.
988694
    cli_replaceTMarkers ${FILE}
988694
4e4b4d
    # Unset array variables to avoid undesired concatenations.
4e4b4d
    unset SRC
4e4b4d
    unset DST
4e4b4d
4e4b4d
}