2015-11-27 17:32:47 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
2015-11-27 17:54:21 +01:00
|
|
|
# A script to create and install translations for commands
|
2015-11-27 17:32:47 +01:00
|
|
|
|
|
|
|
# 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
|
2015-12-03 16:35:58 +01:00
|
|
|
language=( fr de es )
|
2015-11-27 17:32:47 +01:00
|
|
|
|
|
|
|
COMMAND_FILES=src/${PROJECT_NAME}*
|
|
|
|
|
2015-12-03 17:41:21 +01:00
|
|
|
function install_i18next-conv {
|
|
|
|
if [ ! -f /usr/bin/i18next-conv ]; then
|
|
|
|
sudo apt-get install -y curl npm
|
|
|
|
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
|
|
|
|
sudo apt-get install -y nodejs
|
|
|
|
sudo npm install i18next-conv -g
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-11-27 17:32:47 +01:00
|
|
|
function create_translation_files {
|
2015-12-03 17:41:21 +01:00
|
|
|
if [ ! -d /tmp/${PROJECT_NAME} ]; then
|
|
|
|
mkdir -p /tmp/${PROJECT_NAME}
|
|
|
|
fi
|
2015-12-01 15:38:37 +01:00
|
|
|
|
|
|
|
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 -
|
2015-12-03 17:41:21 +01:00
|
|
|
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}.json ]; then
|
|
|
|
# create po file
|
|
|
|
echo "Creating ${lang} Translation file for ${COMMAND_NAME}..."
|
|
|
|
msginit -l ${lang} -i /tmp/${PROJECT_NAME}/${COMMAND_NAME}.pot -o locale/${lang}/${COMMAND_NAME}.po
|
|
|
|
|
|
|
|
# convert po to json
|
|
|
|
if [ -f /usr/bin/i18next-conv ]; then
|
|
|
|
if [ -f locale/${lang}/${COMMAND_NAME}.po ]; then
|
|
|
|
if [ ! -f locale/${lang}/${COMMAND_NAME}.json ]; then
|
|
|
|
i18next-conv -l ${lang} -s locale/${lang}/${COMMAND_NAME}.po -t locale/${lang}/${COMMAND_NAME}.json
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm locale/${lang}/${COMMAND_NAME}.po
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
rm /tmp/${PROJECT_NAME}/${COMMAND_NAME}.pot
|
|
|
|
fi
|
2015-12-01 15:38:37 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_translations {
|
2015-11-27 17:32:47 +01:00
|
|
|
for f in $COMMAND_FILES
|
|
|
|
do
|
|
|
|
COMMAND_NAME=$(echo $f | awk -F '/' '{print $2}')
|
|
|
|
for lang in "${language[@]}"
|
|
|
|
do
|
2015-12-03 17:41:21 +01:00
|
|
|
# convert json to mo
|
|
|
|
if [ -f /usr/bin/i18next-conv ]; then
|
|
|
|
if [ -f locale/${lang}/${COMMAND_NAME}.json ]; then
|
|
|
|
i18next-conv -l ${lang} -s locale/${lang}/${COMMAND_NAME}.json -t /usr/share/locale/${lang}/${COMMAND_NAME}.mo
|
|
|
|
fi
|
2015-11-27 17:32:47 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2015-12-01 15:38:37 +01:00
|
|
|
function uninstall_translations {
|
2015-11-27 17:32:47 +01:00
|
|
|
for f in $COMMAND_FILES
|
|
|
|
do
|
|
|
|
COMMAND_NAME=$(echo $f | awk -F '/' '{print $2}')
|
|
|
|
for lang in "${language[@]}"
|
|
|
|
do
|
2015-12-01 15:38:37 +01:00
|
|
|
if [ -f /usr/share/locale/${lang}/${COMMAND_NAME}.mo ]; then
|
|
|
|
rm /usr/share/locale/${lang}/${COMMAND_NAME}.mo
|
2015-11-27 17:32:47 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $1 == "make" ]]; then
|
2015-12-03 17:41:21 +01:00
|
|
|
install_i18next-conv
|
2015-11-27 17:32:47 +01:00
|
|
|
create_translation_files
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $1 == "install" ]]; then
|
2015-12-03 17:41:21 +01:00
|
|
|
install_i18next-conv
|
2015-11-27 17:32:47 +01:00
|
|
|
install_translations
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2015-12-01 15:38:37 +01:00
|
|
|
if [[ $1 == "uninstall" ]]; then
|
|
|
|
uninstall_translations
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2015-11-27 17:32:47 +01:00
|
|
|
exit 1
|