| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 | #!/bin/bash
#
# .---.                  .              .
# |                      |              |
# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
#
#                    Freedom in the Cloud
#
# A script to create and install translations for commands
# License
# =======
#
# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PROJECT_NAME='freedombone'
# languages to translate into
language=( fr de )
COMMAND_FILES=src/${PROJECT_NAME}*
function create_translation_files {
	if [ ! -d /tmp/${PROJECT_NAME} ]; then
		mkdir -p /tmp/${PROJECT_NAME}
	fi
    for f in $COMMAND_FILES
    do
        COMMAND_NAME=$(echo $f | awk -F '/' '{print $2}')
        bash --dump-po-strings src/${COMMAND_NAME} | xgettext -L PO -o /tmp/${PROJECT_NAME}/${COMMAND_NAME}.pot -
		if [ -f /tmp/${PROJECT_NAME}/${COMMAND_NAME}.pot ]; then
			for lang in "${language[@]}"
			do
				if [ ! -d locale/${lang} ]; then
					mkdir -p locale/${lang}
				fi
				if [ ! -f locale/${lang}/${COMMAND_NAME}.po ]; then
				    echo "Creating ${lang} Translation file for ${COMMAND_NAME}..."
				    msginit -l ${lang} -i /tmp/${PROJECT_NAME}/${COMMAND_NAME}.pot -o locale/${lang}/${COMMAND_NAME}.po
				fi
			done
			rm /tmp/${PROJECT_NAME}/${COMMAND_NAME}.pot
		fi
    done
}
function install_translations {
    for f in $COMMAND_FILES
    do
        COMMAND_NAME=$(echo $f | awk -F '/' '{print $2}')
        for lang in "${language[@]}"
        do
            if [ -f locale/${lang}/${COMMAND_NAME}.mo ]; then
                cp locale/${lang}/${COMMAND_NAME}.mo /usr/share/locale/${lang}/${COMMAND_NAME}.mo
            fi
        done
    done
}
function uninstall_translations {
    for f in $COMMAND_FILES
    do
        COMMAND_NAME=$(echo $f | awk -F '/' '{print $2}')
        for lang in "${language[@]}"
        do
            if [ -f /usr/share/locale/${lang}/${COMMAND_NAME}.mo ]; then
                rm /usr/share/locale/${lang}/${COMMAND_NAME}.mo
            fi
        done
    done
}
if [[ $1 == "make" ]]; then
    create_translation_files
    exit 0
fi
if [[ $1 == "install" ]]; then
    install_translations
    exit 0
fi
if [[ $1 == "uninstall" ]]; then
    uninstall_translations
    exit 0
fi
exit 1
 |