Changeset 5719
- Timestamp:
- 11/18/08 17:25:37 (2 months ago)
- Files:
-
- branches/1.1/turbogears/i18n/sogettext/__init__.py (modified) (2 diffs)
- branches/1.1/turbogears/i18n/tests/test_so_gettext.py (modified) (1 diff)
- branches/1.1/turbogears/i18n/tg_gettext.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/turbogears/i18n/sogettext/__init__.py
r5718 r5719 5 5 from turbogears.i18n.utils import get_locale 6 6 7 try: 8 from sqlobject import SQLObjectNotFound 9 except ImportError: 10 pass 7 from sqlobject import SQLObjectNotFound 8 11 9 from gettext import translation 12 10 import codecs … … 120 118 for message in TG_Message.selectBy(domain=domain, locale=locale): 121 119 122 if message.name == "":continue # descriptive text 120 if message.name == "": 121 continue # descriptive text 123 122 124 123 f.write(u""" branches/1.1/turbogears/i18n/tests/test_so_gettext.py
r1507 r5719 10 10 11 11 def setup_module(): 12 turbogears.config.update({"i18n.gettext": sogettext.so_gettext})12 turbogears.config.update({"i18n.gettext": "so_gettext"}) 13 13 basic_setup_module() 14 14 15 15 def teardown_module(): 16 turbogears.config.update({"i18n.gettext": tg_gettext})16 turbogears.config.update({"i18n.gettext": "tg_gettext"}) 17 17 18 18 def test_so_gettext(): branches/1.1/turbogears/i18n/tg_gettext.py
r4362 r5719 7 7 from turbogears.i18n.utils import get_locale 8 8 from turbojson.jsonify import jsonify 9 10 import logging 11 log = logging.getLogger("turbogears.i18n") 9 12 10 13 _catalogs = {} … … 56 59 57 60 """ 58 gettext_func = config.get("i18n.gettext", tg_gettext) 59 return gettext_func(key, locale, domain) 61 gettext_func_name = config.get("i18n.gettext", "tg_gettext") 62 gettext_func = None 63 64 if gettext_func_name == "tg_gettext": 65 gettext_func = tg_gettext 66 67 elif gettext_func_name == "so_gettext": 68 try: 69 from turbogears.i18n.sogettext import so_gettext 70 gettext_func = so_gettext 71 72 except ImportError, e: 73 log.error("Could not load sogettext: %s" % e) 74 log.error("Translation disabled") 75 76 77 elif gettext_func_name == "sa_gettext": 78 try: 79 from turbogears.i18n.sagettext import sa_gettext 80 gettext_func = so_gettext 81 82 except ImportError, e: 83 log.error("Could not load sogettext: %s" % e) 84 log.error("Translation disabled") 85 86 else: 87 log.error("Invalid i18n.gettext option: %s" % gettext_func_name) 88 log.error("Translation disabled") 89 90 if gettext_func is None: 91 # gettext function could not be loaded? Just avoid 92 # to translate and return original data 93 return key 94 95 else: 96 # gettext function loaded properly, use it :) 97 return gettext_func(key, locale, domain) 60 98 61 99 def tg_gettext(key, locale=None, domain=None): … … 71 109 if locale is None: 72 110 locale = get_locale() 111 73 112 if not is_locale_supported(locale): 74 113 locale = locale[:2] 114 75 115 if key == '': 76 116 return '' # special case 117 77 118 try: 78 119 return get_catalog(locale, domain).ugettext(key) 120 79 121 except KeyError: 80 122 return key 123 81 124 except IOError: 82 125 return key … … 95 138 if num==1: 96 139 return plain_gettext(key1, locale) 140 97 141 else: 98 142 return plain_gettext(key2, locale) … … 135 179 lazystr = lazystring(func, *args, **kw) 136 180 return lazystr 181 137 182 return newfunc 138 183 … … 156 201 if request_available(): 157 202 return plain_gettext(key, locale, domain) 203 158 204 else: 159 205 return lazy_gettext(key, locale, domain)