Index: pykota/trunk/pykota/dumper.py
===================================================================
--- pykota/trunk/pykota/dumper.py (revision 3050)
+++ pykota/trunk/pykota/dumper.py (revision 3055)
@@ -283,5 +283,5 @@
                               and (typval == "str") :
                         try :
-                            strvalue = unicode(strvalue, self.getCharset()).encode("UTF-8")
+                            strvalue = unicode(strvalue, self.charset).encode("UTF-8")
                         except UnicodeError :    
                             pass
Index: pykota/trunk/pykota/tool.py
===================================================================
--- pykota/trunk/pykota/tool.py (revision 3050)
+++ pykota/trunk/pykota/tool.py (revision 3055)
@@ -130,30 +130,21 @@
         
         # locale stuff
-        self.defaultToCLocale = 0
-        try :
-            locale.setlocale(locale.LC_ALL, lang)
+        try :
+            locale.setlocale(locale.LC_ALL, (lang, charset))
         except (locale.Error, IOError) :
-            # locale.setlocale(locale.LC_ALL, "C")
-            self.defaultToCLocale = 1
-        try :
-            gettext.install("pykota")
+            locale.setlocale(locale.LC_ALL, None)
+        (self.language, self.charset) = locale.getlocale()
+        self.language = self.language or "C"
+        self.charset = self.charset or locale.getpreferredencoding()
+        
+        # translation stuff
+        try :
+            try :
+                trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)], codeset=self.charset)
+            except TypeError : # Python <2.4
+                trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)])
+            trans.install()
         except :
             gettext.NullTranslations().install()
-            
-        # Finds the correct charset
-        self.localecharset = sys.getfilesystemencoding()
-        if self.localecharset is None :
-            try :
-                try :
-                    self.localecharset = locale.getpreferredencoding()
-                except AttributeError :    
-                    try :
-                        self.localecharset = locale.getlocale()[1]
-                        self.localecharset = self.localecharset or locale.getdefaultlocale()[1]
-                    except ValueError :    
-                        pass        # Unknown locale, strange...
-            except locale.Error :            
-                pass
-        self.charset = charset or self.localecharset or "UTF-8"
     
         # pykota specific stuff
@@ -189,6 +180,4 @@
         self.softwareJobPrice = 0.0
         
-        if self.defaultToCLocale :
-            self.printInfo("Incorrect locale settings. PyKota falls back to the default locale.", "warn")
         if environHome :
             self.printInfo("PYKOTA_HOME environment variable is set. Configuration files were searched in %s" % confdir, "info")
@@ -197,6 +186,7 @@
                 self.printInfo("The 'pykota' system account is missing. Configuration files were searched in %s instead." % confdir, "warn")
         
-        self.logdebug("Charset detected from locale settings : %s" % self.localecharset)
+        self.logdebug("Language in use : %s" % self.language)
         self.logdebug("Charset in use : %s" % self.charset)
+        
         arguments = " ".join(['"%s"' % arg for arg in sys.argv])
         self.logdebug("Command line arguments : %s" % arguments)
@@ -237,8 +227,4 @@
                 self.logdebug(_("Regained priviledges. Now running as root."))
                 self.privdropped = 0
-        
-    def getCharset(self) :    
-        """Returns the charset in use."""
-        return self.charset
         
     def UTF8ToUserCharset(self, text) :
Index: pykota/trunk/pykota/cgifuncs.py
===================================================================
--- pykota/trunk/pykota/cgifuncs.py (revision 2622)
+++ pykota/trunk/pykota/cgifuncs.py (revision 3055)
@@ -20,4 +20,5 @@
 #
 
+import sys
 import os
 
@@ -26,5 +27,6 @@
     languages = os.environ.get("HTTP_ACCEPT_LANGUAGE", "")
     langs = [l.strip().split(';')[0] for l in languages.split(",")]
-    return "%s_%s" % (langs[0], langs[0].upper())
+    sys.stderr.write("Languages preferences : %s\n" % langs)
+    return langs[0].replace("-", "_")
     
 def getCharsetPreference() :
@@ -32,3 +34,4 @@
     charsets = os.environ.get("HTTP_ACCEPT_CHARSET", "UTF-8")
     charsets = [l.strip().split(';')[0] for l in charsets.split(",")]
+    sys.stderr.write("Charsets preferences : %s\n" % charsets)
     return charsets[0]
Index: pykota/trunk/cgi-bin/printquota.cgi
===================================================================
--- pykota/trunk/cgi-bin/printquota.cgi (revision 3050)
+++ pykota/trunk/cgi-bin/printquota.cgi (revision 3055)
@@ -37,7 +37,6 @@
 from pykota.cgifuncs import getLanguagePreference, getCharsetPreference
 
-header = """Content-type: text/html
-
-<?xml version="1.0" encoding="%s"?>
+header = """Content-type: text/html;charset=%s
+
 <html>
   <head>
@@ -46,4 +45,5 @@
   </head>
   <body>
+    <!-- %s %s -->
     <p>
       <form action="printquota.cgi" method="POST">
@@ -97,5 +97,6 @@
         """Displays the administrative interface."""
         global header, footer
-        print header % (self.getCharset(), _("PyKota Reports"), \
+        print header % (self.charset, _("PyKota Reports"), \
+                        self.language, self.charset, \
                         self.config.getLogoLink(), \
                         self.config.getLogoURL(), version.__version__, \
@@ -287,6 +288,5 @@
             
 if __name__ == "__main__" :
-    os.environ["LC_ALL"] = getLanguagePreference()
-    admin = PyKotaReportGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference())
+    admin = PyKotaReportGUI(lang=getLanguagePreference(), charset=getCharsetPreference())
     admin.deferredInit()
     admin.form = cgi.FieldStorage()
Index: pykota/trunk/cgi-bin/pykotme.cgi
===================================================================
--- pykota/trunk/cgi-bin/pykotme.cgi (revision 2909)
+++ pykota/trunk/cgi-bin/pykotme.cgi (revision 3055)
@@ -37,7 +37,6 @@
     
 
-header = """Content-type: text/html
-
-<?xml version="1.0" encoding="%s"?>
+header = """Content-type: text/html;charset=%s
+
 <html>
   <head>
@@ -46,4 +45,5 @@
   </head>
   <body>
+    <!-- %s %s -->
     <p>
       <form action="pykotme.cgi" method="POST" enctype="multipart/form-data">
@@ -97,5 +97,6 @@
         """Displays the administrative interface."""
         global header, footer
-        print header % (self.getCharset(), _("PyKota Quotes"), \
+        print header % (self.charset, _("PyKota Quotes"), \
+                        self.language, self.charset, \
                         self.config.getLogoLink(), \
                         self.config.getLogoURL(), version.__version__, \
@@ -187,6 +188,5 @@
             
 if __name__ == "__main__" :
-    os.environ["LC_ALL"] = getLanguagePreference()
-    admin = PyKotMeGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference())
+    admin = PyKotMeGUI(lang=getLanguagePreference(), charset=getCharsetPreference())
     admin.deferredInit()
     admin.form = cgi.FieldStorage()
Index: pykota/trunk/cgi-bin/dumpykota.cgi
===================================================================
--- pykota/trunk/cgi-bin/dumpykota.cgi (revision 3032)
+++ pykota/trunk/cgi-bin/dumpykota.cgi (revision 3055)
@@ -35,7 +35,6 @@
 from pykota.cgifuncs import getLanguagePreference, getCharsetPreference
 
-header = """Content-type: text/html
-
-<?xml version="1.0" encoding="%s"?>
+header = """Content-type: text/html;charset=%s
+
 <html>
   <head>
@@ -70,4 +69,5 @@
   </head>
   <body>
+    <!-- %s %s -->
     <p>
       <form action="dumpykota.cgi" method="GET" name="mainform" onsubmit="return checkvalues()">
@@ -124,5 +124,6 @@
         """Displays the dumper interface."""
         global header, footer
-        print header % (self.getCharset(), _("PyKota Data Dumper"), \
+        print header % (self.charset, _("PyKota Data Dumper"), \
+                        self.language, self.charset, \
                         self.config.getLogoLink(), \
                         self.config.getLogoURL(), version.__version__, \
@@ -228,6 +229,5 @@
             
 if __name__ == "__main__" :
-    os.environ["LC_ALL"] = getLanguagePreference()
-    admin = PyKotaDumperGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference())
+    admin = PyKotaDumperGUI(lang=getLanguagePreference(), charset=getCharsetPreference())
     admin.deferredInit()
     admin.form = cgi.FieldStorage()
