Index: turbogears/i18n/tg_gettext.py
===================================================================
--- turbogears/i18n/tg_gettext.py	(Revision 3076)
+++ turbogears/i18n/tg_gettext.py	(Arbeitskopie)
@@ -12,22 +12,27 @@
 def get_locale_dir():
     localedir = turbogears.config.get("i18n.locale_dir")
     if not localedir:
-        localedir = os.path.join(os.path.dirname(
-            sys.modules[get_package_name()].__path__[0]), "locales")
+        package = get_package_name()
+        if package:
+            localedir = os.path.join(os.path.dirname(
+                sys.modules[package].__path__[0]), "locales")
     return localedir
 
 def is_locale_supported(locale, domain=None):
     """Checks if [domain].mo file exists for this language
     """
-    if not domain: domain = turbogears.config.get("i18n.domain", "messages")
+    if not domain:
+        domain = turbogears.config.get("i18n.domain", "messages")
 
     localedir = get_locale_dir()
-    return os.path.exists(os.path.join(localedir, locale, "LC_MESSAGES", "%s.mo" % domain))
+    return localedir and os.path.exists(os.path.join(
+        localedir, locale, "LC_MESSAGES", "%s.mo" % domain))
 
 def get_catalog(locale, domain = None):
     """Return translations for given locale.
     """
-    if not domain: domain = turbogears.config.get("i18n.domain", "messages")
+    if not domain:
+        domain = turbogears.config.get("i18n.domain", "messages")
 
     catalog = _catalogs.get(domain)
 
@@ -45,8 +50,7 @@
 def plain_gettext(key, locale=None, domain=None):
     """Gets the gettext value for key.Added to builtins as '_'. Returns Unicode string.
     @param key: text to be translated
-    @param locale: locale code to be used. If locale is None, gets the value provided
-    by get_locale.
+    @param locale: locale code to be used.If locale is None, gets the value provided by get_locale.
     """
     gettext_func = turbogears.config.get("i18n.gettext", tg_gettext)
     return gettext_func(key, locale, domain)
@@ -54,8 +58,7 @@
 def tg_gettext(key, locale=None, domain=None):
     """Gets the gettext value for key.Added to builtins as '_'. Returns Unicode string.
     @param key: text to be translated
-    @param locale: locale code to be used. If locale is None, gets the value provided by
-    get_locale.
+    @param locale: locale code to be used. If locale is None, gets the value provided by get_locale.
     """
     if locale is None:locale = get_locale()
     if not is_locale_supported(locale):locale = locale[:2]
@@ -72,20 +75,13 @@
     """Translates two possible texts based on whether num is greater than 1
     @param key1: text if num==1
     @param key2: text if num!=1
-
     @param num: a number
     @type num: integer
-
-    @param locale: locale code to be used.If locale is None, gets the value
-    provided by get_locale.
+    @locale:locale code to be used. If locale is None, gets the value provided by get_locale.
     """
-
     if num==1:
-
         return plain_gettext(key1, locale)
-
     else:
-
         return plain_gettext(key2, locale)
 
 class lazystring(object):
@@ -138,12 +134,10 @@
 lazy_ngettext = lazify(plain_ngettext)
 
 def gettext(key, locale=None, domain=None):
-    """Gets the gettext value for key. Added to builtins as '_'.
-    Returns Unicode string.
+    """Gets the gettext value for key. Added to builtins as '_'. Returns Unicode string.
 
     @param key: text to be translated
-    @param locale: locale code to be used. If locale is None,
-    gets the value provided by get_locale.
+    @param locale: locale code to be used. If locale is None, gets the value provided by get_locale.
      """
 
     if request_available():
@@ -156,12 +150,9 @@
 
     @param key1: text if num==1
     @param key2: text if num!=1
-
     @param num: a number
     @type num: integer
-
-    @param locale: locale code to be used. If locale is None, gets the value
-    provided by get_locale.
+    @param locale: locale code to be used. If locale is None, gets the value provided by get_locale.
     """
     if request_available():
         return plain_ngettext(key1, key2, num, locale)

