Blame tcar-scripts-locale/Modules/Files/Modules/Update/update_setPoMetadata.sh

Alain Reguera Delgado f72cfe
#!/bin/bash
Alain Reguera Delgado f72cfe
######################################################################
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
#   update_setPoMetadata -- This function sets metadata to portable
Alain Reguera Delgado f72cfe
#   object (.po) files, using CentOS-specific data.
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
#   Written by:
Alain Reguera Delgado f72cfe
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado f72cfe
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado f72cfe
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado f72cfe
# your option) any later version.
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado f72cfe
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado f72cfe
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado f72cfe
# General Public License for more details.
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado f72cfe
# along with this program; if not, write to the Free Software
Alain Reguera Delgado f72cfe
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado f72cfe
#
Alain Reguera Delgado f72cfe
######################################################################
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
function update_setPoMetadata {
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    local COUNT=0
Alain Reguera Delgado f72cfe
    local -a SRC
Alain Reguera Delgado f72cfe
    local -a DST
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Retrieve absolute path of portable object we'll work with.
Alain Reguera Delgado f72cfe
    local PO_FILE="${1}"
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Check existence of file before work with it.
Alain Reguera Delgado f72cfe
    tcar_checkFiles -ef "${PO_FILE}"
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Define pattern lines. The pattern lines are put inside portable
Alain Reguera Delgado f72cfe
    # objects through xgettext and xml2po commands. In the case of
Alain Reguera Delgado f72cfe
    # Last-Translators, be sure to remplace it only when it is empty
Alain Reguera Delgado f72cfe
    # or refer the Documentation SIG only. This way translators' names
Alain Reguera Delgado f72cfe
    # will survive metadata updates. We don't want they have to type
Alain Reguera Delgado f72cfe
    # their name each time they edit a file.
Alain Reguera Delgado f72cfe
    SRC[0]="\"Project-Id-Version: (.+)?"
Alain Reguera Delgado f72cfe
    SRC[1]="\"Last-Translator: (.+)?"
Alain Reguera Delgado f72cfe
    SRC[2]="\"Language-Team: (.+)?"
Alain Reguera Delgado f72cfe
    SRC[3]="\"PO-Revision-Date: (.+)?"
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Define replacement lines for pattern line.
Alain Reguera Delgado f72cfe
    DST[0]="\"Project-Id-Version: ${PACKAGE_NAME} ${PACKAGE_VERSION}\\\n\""
Alain Reguera Delgado f72cfe
    DST[1]="\"Last-Translator: Localization SIG <centos-l10n-${TCAR_SCRIPT_LANG_LL}@centos.org.cu>\\\n\""
Alain Reguera Delgado f72cfe
    DST[2]="\"Language-Team: $(update_getLanguageName)\\\n\""
Alain Reguera Delgado f72cfe
    DST[3]="\"PO-Revision-Date: $(date "+%F %H:%M%z")\\\n\""
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Change pattern lines with their replacement lines.
Alain Reguera Delgado f72cfe
    while [[ ${COUNT} -lt ${#SRC[*]} ]];do
Alain Reguera Delgado f72cfe
        sed -i -r "/${SRC[${COUNT}]}/c${DST[${COUNT}]}" ${PO_FILE}
Alain Reguera Delgado f72cfe
        COUNT=$((${COUNT} + 1))
Alain Reguera Delgado f72cfe
    done
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Replace package information using gettext domain information.
Alain Reguera Delgado f72cfe
    # Don't include version here to prevent old version to be shown in
Alain Reguera Delgado f72cfe
    # the comment area when new versions of the package are created.
Alain Reguera Delgado f72cfe
    sed -i -r "s/PACKAGE/${PACKAGE_NAME}/g" ${PO_FILE}
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Remove absolute path to the working copy so it doesn't appear on
Alain Reguera Delgado f72cfe
    # comments related to locations. Remember that people can download
Alain Reguera Delgado f72cfe
    # their working copies in different locations and we don't want to
Alain Reguera Delgado f72cfe
    # version those changes each time a translation message be
Alain Reguera Delgado f72cfe
    # updated. To be consistent about this, show path information from
Alain Reguera Delgado f72cfe
    # first level on. Don't show the variable part of the path.
Alain Reguera Delgado f72cfe
    sed -i -r "s,${TCAR_BASEDIR}/,,g" ${PO_FILE}
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
    # Unset array variables to avoid undesired concatenations.
Alain Reguera Delgado f72cfe
    unset SRC
Alain Reguera Delgado f72cfe
    unset DST
Alain Reguera Delgado f72cfe
Alain Reguera Delgado f72cfe
}