#!/bin/sh

VERSION=1.7
CHROMEDIR=/usr/lib/mozilla/chrome

set_UILocale()
{
  if [ -f /usr/lib/mozilla/chrome/$1.jar ] ; then
    UILocale="-UILocale $1";
  else
    unset UILocale;
  fi
}

set_ContentLocale()
{
  if [ -f /usr/lib/mozilla/chrome/$1.jar ] ; then
    ContentLocale="-ContentLocale $1";
  else
    unset ContentLocale;
  fi
}

if [ "$LD_LIBRARY_PATH" ] ; then
  LD_LIBRARY_PATH=/usr/lib/mozilla:/usr/lib/mozilla/plugins:/usr/lib:$LD_LIBRARY_PATH
else
  LD_LIBRARY_PATH=/usr/lib/mozilla:/usr/lib/mozilla/plugins:/usr/lib
fi
export LD_LIBRARY_PATH

if /usr/lib/mozilla/mozilla-xremote-client 'ping()' >/dev/null 2>&1 ; then
	/usr/bin/mozilla-${VERSION} "$@"
else

	lang="$(locale | sed -ne 's/"$//;s/="/=/;s/^LC_MESSAGES=\(.*\)/\1/p')"
	l=$(sed -ne "s/^$(echo $lang | sed 's/\([].^$*[]\)/\\\1/g')[    ]\+//ip" /etc/locale.alias)
	[ -n "$l" ] && lang="$l"

	case "$lang" in
		ca*)
		  	set_UILocale "ca";		# Catalan 
		;;
		cs*)
			set_UILocale "cs-CZ";           # Czech
			set_ContentLocale "CZ";
		;;
		cy*)
			set_UILocale "cy-GB";		# Welsh
		;;
		da*)
			set_UILocale "da-DK";		# Danish
		;;
		de*)
			set_UILocale "de-AT";		# German
			set_ContentLocale "AT";
		;;
		es_ar*)
                        set_UILocale "es-AR" 	   	# Spanish (Argentinia)
                        set_ContentLocale "AR";
                ;;
		es_hn*)
                        set_UILocale "es-HN";   	# Spanish (Honduras)
                ;;
		es*)
                        set_UILocale "es-ES"		# Spanish (Spain)
                ;;
		eu*)
			set_UILocale "eu-ES"		# Basque
		;;
		fr*)	
			set_UILocale "fr-FR" 		# French
			set_ContentLocale "FR";
		;;
		gl*)
			set_UILocale "gl-ES";		# Galician
		;;
		hu_HU*)
			set_UILocale "hu-HU"		# Hungarian
		;;
                it)
                        set_UILocale "it-IT" 		# Italian
                        set_ContentLocale "IT";
                ;;
		ja*)
			set_UILocale "ja-JP"		# Japanese
			set_ContentLocale "JP";
		;;
		ko*)
			set_UILocale "ko-KR"		# Korean
			set_ContentLocale "KR";
		;;
		no*)
			set_UILocale "nb-NO"		# Norwegian
			set_ContentLocale "NO";
		;;
		pl*)
			set_UILocale "pl-PL"		# Polish
			set_ContentLocale "PL";
		;;
		pt_BR*)
			set_UILocale "pt-BR"		# Brazilian Portuguese
			set_ContentLocale "BR";
		;;
		sl*)
			set_UILocale "sl-SI"		# Slovenian
			set_ContentLocale "SI";
		;;
		zh_HK*)
                        set_UILocale "zh-HK"		# Traditional Chinese (Honk Kong)
                        set_ContentLocale "HK";
                ;;
		zh_TW*)
			set_UILocale "zh-TW"		# Traditional Chinese (Taiwan)
			set_ContentLocale "TW";
		;;
		zh*)
			set_UILocale "zh-CN"		# Simplified Chinese
			set_ContentLocale "CN";
		;;
		*)
			set_UILocale "en-US"		# American english
			set_ContentLocale "US";
		;;
												
	esac
	
	/usr/bin/mozilla-${VERSION} ${UILocale} ${ContentLocale} "$@"
fi
