Blame Scripts/Modules/Locale/Modules/Files/Modules/Update/update_convertPotToPo.sh

Alain Reguera Delgado f23b0d
#!/bin/bash
Alain Reguera Delgado f23b0d
######################################################################
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado c0ca71
#   tcar - The CentOS Artwork Repository automation tool.
Alain Reguera Delgado c0ca71
#   Copyright © 2014 The CentOS Artwork SIG
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado c0ca71
#   This program is free software; you can redistribute it and/or
Alain Reguera Delgado c0ca71
#   modify it under the terms of the GNU General Public License as
Alain Reguera Delgado c0ca71
#   published by the Free Software Foundation; either version 2 of the
Alain Reguera Delgado c0ca71
#   License, or (at your option) any later version.
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado c0ca71
#   This program is distributed in the hope that it will be useful,
Alain Reguera Delgado c0ca71
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado c0ca71
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado c0ca71
#   General Public License for more details.
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado c0ca71
#   You should have received a copy of the GNU General Public License
Alain Reguera Delgado c0ca71
#   along with this program; if not, write to the Free Software
Alain Reguera Delgado c0ca71
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado c0ca71
#   Alain Reguera Delgado <al@centos.org.cu>
Alain Reguera Delgado c0ca71
#   39 Street No. 4426 Cienfuegos, Cuba.
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado f23b0d
######################################################################
Alain Reguera Delgado f23b0d
Alain Reguera Delgado c0ca71
# This function takes a portable object template (.pot) and creates a
Alain Reguera Delgado c0ca71
# language-specific portable object (.po) for it.
Alain Reguera Delgado f23b0d
function update_convertPotToPo {
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    local POT_FILE="${1}"
Alain Reguera Delgado f23b0d
    local PO_FILE="${2}"
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    # Verify the portable object template. The portable object
Alain Reguera Delgado f23b0d
    # template is used to create the portable object. We cannot
Alain Reguera Delgado f23b0d
    # continue without it.
Alain Reguera Delgado f23b0d
    tcar_checkFiles -ef ${POT_FILE}
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    # Print action message.
Alain Reguera Delgado f23b0d
    tcar_printMessage "${PO_FILE}" --as-creating-line
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    # Verify existence of portable object. The portable object is the
Alain Reguera Delgado f23b0d
    # file translators edit in order to make translation works.
Alain Reguera Delgado f23b0d
    if [[ -f ${PO_FILE} ]];then
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        # Update portable object merging both portable object and
Alain Reguera Delgado f23b0d
        # portable object template.
Alain Reguera Delgado f23b0d
        msgmerge --output-file="${PO_FILE}" "${PO_FILE}" "${POT_FILE}" --quiet
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    else
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        # Create the PO's parent directory if it doesn't exist.
Alain Reguera Delgado f23b0d
        if [[ ! -d $(dirname ${PO_FILE}) ]];then
Alain Reguera Delgado f23b0d
            mkdir -p $(dirname ${PO_FILE})
Alain Reguera Delgado f23b0d
        fi
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        # Initiate portable object using portable object template.
Alain Reguera Delgado f23b0d
        # Do not print msginit sterr output, use centos-art action
Alain Reguera Delgado f23b0d
        # message instead.
Alain Reguera Delgado f23b0d
        msginit -i ${POT_FILE} -o ${PO_FILE} --width=70 \
Alain Reguera Delgado f23b0d
            --no-translator > /dev/null 2>&1
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    fi
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    # Sanitate metadata inside the PO file.
Alain Reguera Delgado f23b0d
    update_setPoMetadata "${PO_FILE}"
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
}