[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r6248 - in trunk/gnue-common/src: apps datasources datasources/drivers/a
From: |
johannes |
Subject: |
r6248 - in trunk/gnue-common/src: apps datasources datasources/drivers/appserver/appserver |
Date: |
Fri, 3 Sep 2004 13:42:11 -0500 (CDT) |
Author: johannes
Date: 2004-09-03 13:42:10 -0500 (Fri, 03 Sep 2004)
New Revision: 6248
Modified:
trunk/gnue-common/src/apps/errors.py
trunk/gnue-common/src/apps/i18n.py
trunk/gnue-common/src/apps/plugin.py
trunk/gnue-common/src/datasources/GConnections.py
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
Log:
*) Added locale-information to GConnection's loginData
*) added some locale-methods to i18n
Modified: trunk/gnue-common/src/apps/errors.py
===================================================================
--- trunk/gnue-common/src/apps/errors.py 2004-09-03 18:40:20 UTC (rev
6247)
+++ trunk/gnue-common/src/apps/errors.py 2004-09-03 18:42:10 UTC (rev
6248)
@@ -85,7 +85,7 @@
@return: unicode string with the exception's traceback
"""
if self.detail is not None:
- return self._fmtUnicode (self.detail, i18n.encoding)
+ return self._fmtUnicode (self.detail, i18n.getencoding ())
if sys.exc_info () == (None, None, None):
tStack = traceback.format_exception (type, value, trace)
@@ -93,7 +93,7 @@
tStack = traceback.format_exception (*sys.exc_info ())
if count is not None:
del tStack [1:count + 1]
- return self._fmtUnicode ("%s" % string.join (tStack), i18n.encoding)
+ return self._fmtUnicode ("%s" % string.join (tStack), i18n.getencoding ())
# ---------------------------------------------------------------------------
@@ -232,7 +232,7 @@
message = unicode (aValue)
detail = string.join (lines)
if isinstance (detail, types.StringType):
- detail = unicode (detail, i18n.encoding)
+ detail = unicode (detail, i18n.getencoding ())
return ('system', name, message, detail)
Modified: trunk/gnue-common/src/apps/i18n.py
===================================================================
--- trunk/gnue-common/src/apps/i18n.py 2004-09-03 18:40:20 UTC (rev 6247)
+++ trunk/gnue-common/src/apps/i18n.py 2004-09-03 18:42:10 UTC (rev 6248)
@@ -147,6 +147,86 @@
# -----------------------------------------------------------------------------
+# Get the current encoding
+# -----------------------------------------------------------------------------
+
+def getencoding ():
+ """
+ This function returns the encoding of the currently active locale
+ @returns: encoding of the current locale
+ """
+ return locale.getlocale () [1]
+
+
+# -----------------------------------------------------------------------------
+# Get the current language
+# -----------------------------------------------------------------------------
+
+def getlanguage ():
+ """
+ This function return the language of the currently acitve locale
+ @returns: language of the current locale
+ """
+ return locale.getlocale () [0]
+
+
+# ---------------------------------------------------------------------------
+# Get the locale string of the current user
+# ---------------------------------------------------------------------------
+
+def getuserlocale ():
+ """
+ This function tries to find out which locale the user is using.
+ @returns: localestring of the user's locale, i.e. address@hidden
+ """
+ items = ['LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG']
+ for key in items:
+ if os.environ.has_key (key):
+ return os.environ [key]
+
+ try:
+ result = locale.getdefaultlocale () [0]
+
+ except locale.Error:
+ result = ''
+
+ return result
+
+
+# ---------------------------------------------------------------------------
+# Change the current locale
+# ---------------------------------------------------------------------------
+
+def setcurrentlocale (newLocale):
+ """
+ This function changes the current locale. If it fails it tries to succeed
+ using a more general form of the requested locale, i.e. if 'address@hidden'
+ fails, 'de_AT' will be tried next. If that fails too 'de' will be tried.
+ @param newLocale: string of the locale to be set, e.g. address@hidden
+ (full blown) or 'de_AT' or 'en_AU'
+ """
+ normal = locale.normalize (newLocale)
+ next = normal.split ('@') [0]
+ noenc = next.split ('.') [0]
+ alias = locale.locale_alias.get (string.lower (noenc.split ('_') [0]))
+
+ parts = [normal]
+ for item in [next, noenc, alias]:
+ if item is not None and item not in parts:
+ parts.append (item)
+
+ for item in parts:
+ try:
+ locale.setlocale (locale.LC_ALL, item)
+
+ except locale.Error:
+ pass
+
+ else:
+ break
+
+
+# -----------------------------------------------------------------------------
# Module initialization
# -----------------------------------------------------------------------------
Modified: trunk/gnue-common/src/apps/plugin.py
===================================================================
--- trunk/gnue-common/src/apps/plugin.py 2004-09-03 18:40:20 UTC (rev
6247)
+++ trunk/gnue-common/src/apps/plugin.py 2004-09-03 18:42:10 UTC (rev
6248)
@@ -92,10 +92,10 @@
for (name, exc) in exceptions.items ():
shortlist = traceback.format_exception_only (exc [0], exc [1])
del shortlist [1:2]
- shortmsg = unicode (string.join (shortlist, ''), i18n.encoding)
+ shortmsg = unicode (string.join (shortlist, ''), i18n.getencoding ())
longlist = traceback.format_exception (*exc)
del longlist [1:2]
- longmsg = unicode (string.join (longlist, ''), i18n.encoding)
+ longmsg = unicode (string.join (longlist, ''), i18n.getencoding ())
message += "* %s: %s" % (name, shortmsg)
self.detail += "* %s: %s" % (name, longmsg)
else:
Modified: trunk/gnue-common/src/datasources/GConnections.py
===================================================================
--- trunk/gnue-common/src/datasources/GConnections.py 2004-09-03 18:40:20 UTC
(rev 6247)
+++ trunk/gnue-common/src/datasources/GConnections.py 2004-09-03 18:42:10 UTC
(rev 6248)
@@ -39,7 +39,7 @@
from ConfigParser import *
import sys, string, copy, netrc
-from gnue.common.apps import plugin, errors
+from gnue.common.apps import plugin, errors, i18n
from gnue.common.datasources import Exceptions
from gnue.common.datasources import GLoginHandler
from gnue.common.utils.FileUtils import openResource, dyn_import
@@ -357,6 +357,7 @@
if not connected:
loginData = connection.parameters
+ loginData ['_language'] = i18n.getuserlocale ()
try:
# load the user's netrc file:
Modified:
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
2004-09-03 18:40:20 UTC (rev 6247)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
2004-09-03 18:42:10 UTC (rev 6248)
@@ -78,7 +78,8 @@
self._sm = self._server.request ('Session')
try:
- self._sess_id = self._sm.open ({'user': user, 'password': passwd})
+ self._sess_id = self._sm.open ({'user': user, 'password': passwd,
+ 'language': connectData ['_language']})
except errors.RemoteError, e:
if e.getName () == 'AuthError':
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r6248 - in trunk/gnue-common/src: apps datasources datasources/drivers/appserver/appserver,
johannes <=