Ticket #5056: ugettext.2.diff
File ugettext.2.diff, 5.4 KB (added by , 17 years ago) |
---|
-
django/utils/translation/trans_real.py
247 247 _default = translation(settings.LANGUAGE_CODE) 248 248 return _default 249 249 250 def do_translate(message, translation_function):250 def gettext(message): 251 251 """ 252 Translate 'message' using the given 'translation_function' name -- which 253 will be either gettext or ugettext. 252 This function will be patched into the builtins module to provide the _ 253 helper function. It will use the current thread as a discriminator to find 254 the translation object to use. If no current translation is activated, the 255 message will be run through the default translation object. 254 256 """ 255 257 global _default, _active 256 258 t = _active.get(currentThread(), None) 257 259 if t is not None: 258 return getattr(t, translation_function)(message)260 return t.ugettext(message) 259 261 if _default is None: 260 262 from django.conf import settings 261 263 _default = translation(settings.LANGUAGE_CODE) 262 return getattr(_default, translation_function)(message) 264 return _default.ugettext(message) 265 ugettext = gettext 263 266 264 def gettext(message):265 """266 This function will be patched into the builtins module to provide the _267 helper function. It will use the current thread as a discriminator to find268 the translation object to use. If no current translation is activated, the269 message will be run through the default translation object.270 """271 return do_translate(message, 'gettext')272 273 def ugettext(message):274 return do_translate(message, 'ugettext')275 276 267 def gettext_noop(message): 277 268 """ 278 269 Marks strings for translation but doesn't translate them now. This can be … … 282 273 """ 283 274 return message 284 275 285 def do_ntranslate(singular, plural, number, translation_function): 276 def ngettext(singular, plural, number): 277 """ 278 Returns a unicode string of the translation of either the singular or 279 plural, based on the number. 280 """ 286 281 global _default, _active 287 288 282 t = _active.get(currentThread(), None) 289 283 if t is not None: 290 return getattr(t, translation_function)(singular, plural, number)284 return t.ungetext(singular, plural, number) 291 285 if _default is None: 292 286 from django.conf import settings 293 287 _default = translation(settings.LANGUAGE_CODE) 294 return getattr(_default, translation_function)(singular, plural, number) 288 return _default.ungettext(singular, plural, number) 289 ungettext = ngettext 295 290 296 def ngettext(singular, plural, number):297 """298 Returns a UTF-8 bytestring of the translation of either the singular or299 plural, based on the number.300 """301 return do_ntranslate(singular, plural, number, 'ngettext')302 303 def ungettext(singular, plural, number):304 """305 Returns a unicode strings of the translation of either the singular or306 plural, based on the number.307 """308 return do_ntranslate(singular, plural, number, 'ungettext')309 310 291 def check_for_language(lang_code): 311 292 """ 312 293 Checks whether there is a global language file for the given language -
django/utils/translation/__init__.py
48 48 49 49 def gettext_noop(message): 50 50 return real_gettext_noop(message) 51 52 51 ugettext_noop = gettext_noop 53 52 54 53 def gettext(message): 55 54 return real_gettext(message) 55 ugettext = gettext 56 56 57 57 def ngettext(singular, plural, number): 58 58 return real_ngettext(singular, plural, number) 59 ungettext = ngettext 59 60 60 def ugettext(message):61 return real_ugettext(message)62 63 def ungettext(singular, plural, number):64 return real_ungettext(singular, plural, number)65 66 61 def string_concat(*strings): 67 62 return real_string_concat(*strings) 68 63 69 64 ngettext_lazy = lazy(ngettext, str) 70 65 gettext_lazy = lazy(gettext, str) 71 ungettext_lazy = lazy(ungettext, unicode)72 ugettext_lazy = lazy(ugettext, unicode)66 ungettext_lazy = ngettext_lazy 67 ugettext_lazy = gettext_lazy 73 68 string_concat = lazy(string_concat, unicode) 74 69 75 70 def activate(language): -
django/utils/translation/trans_null.py
6 6 from django.utils.encoding import force_unicode 7 7 8 8 def ngettext(singular, plural, number): 9 if number == 1: return singular 10 return plural 11 ngettext_lazy = ngettext 9 return force_unicode({1: singular}.get(number, plural)) 10 ungettext = ngettext_lazy = ngettext 12 11 13 def ungettext(singular, plural, number):14 return force_unicode(ngettext(singular, plural, number))15 16 12 string_concat = lambda *strings: u''.join([force_unicode(el) for el in strings]) 17 13 activate = lambda x: None 18 14 deactivate = deactivate_all = install = lambda: None … … 32 28 } 33 29 34 30 def gettext(message): 35 return TECHNICAL_ID_MAP.get(message, message) 31 return force_unicode(TECHNICAL_ID_MAP.get(message, message)) 32 ugettext = gettext_noop = gettext_lazy = _ = gettext 36 33 37 def ugettext(message):38 return force_unicode(gettext(message))39 40 gettext_noop = gettext_lazy = _ = gettext41 42 34 def to_locale(language): 43 35 p = language.find('-') 44 36 if p >= 0: