#!/bin/dash
# quick-locale-switcher.sh, replacement for rox AppRun
# display an icon on icon tray showing actual language and launch quick-locale-switcher
# (C) L18L 2015
# License: GPL Version 3 or later
#
# uses 'sit' (simple-icon-tray) from technosaurus
# icon by courtesy of http://www.languageicon.org/

export TEXTDOMAIN=fatdog

all_LANGUAGE_names=/usr/share/i18n/lang_names
 
LOCALES_ICON=/usr/share/pixmaps/midi-icons/language48.png
LOCALES_TOOLTIP=/tmp/locale-switcher.$$
LOCALES_LEFT_CLICK=fatdog-quick-locale-switcher
LOCALES_RIGHT_CLICK="$LOCALES_LEFT_CLICK -h"

L=${LANG%_*}                                                              #ex: nl
[ -f $all_LANGUAGE_names ] && L="`grep -m 1 "^${L}" $all_LANGUAGE_names`" #ex: nl:Nederlands
> $LOCALES_TOOLTIP
[ "`locale -a | grep -i utf | grep -v ^en_`" ] && echo -n "
 $(gettext 'Change
 language
 from')
___________
" > $LOCALES_TOOLTIP
echo -n " ${L#*:} " >> $LOCALES_TOOLTIP	#ex: 'nl' OR 'Nederlands' but always at least: 'English'
 
# right click gives info about adding a locale

# launch sit and set trap handler
sit $LOCALES_ICON $LOCALES_TOOLTIP "$LOCALES_LEFT_CLICK" "$LOCALES_RIGHT_CLICK" &
XPID=$!
trap 'kill $XPID; rm -rf $LOCALES_TOOLTIP; exit' INT TERM HUP # kill sit when we die
