Ticket #11686: pgettext.patch
File pgettext.patch, 6.9 KB (added by , 14 years ago) |
---|
-
django/core/management/commands/makemessages.py
225 225 raise SyntaxError(msg) 226 226 if verbosity > 1: 227 227 sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 228 cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 -- from-code UTF-8 -o - "%s"' % (228 cmd = 'xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2 --keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 -o - "%s"' % ( 229 229 domain, os.path.join(dirpath, thefile)) 230 230 msgs, errors = _popen(cmd) 231 231 if errors: -
django/utils/translation/trans_real.py
279 279 def ugettext(message): 280 280 return do_translate(message, 'ugettext') 281 281 282 def pgettext(context, message): 283 # \x04 is a magic gettext number to separate context from message 284 result = do_translate(u"%s\x04%s" % (context, message), 'ugettext') 285 if "\x04" in result: 286 # Translation not found 287 result = message 288 return result 289 282 290 def gettext_noop(message): 283 291 """ 284 292 Marks strings for translation but doesn't translate them now. This can be … … 313 321 """ 314 322 return do_ntranslate(singular, plural, number, 'ungettext') 315 323 324 def npgettext(context, singular, plural, number): 325 # \x04 is a magic gettext number to separate context from message 326 result = do_ntranslate(u"%s\x04%s" % (context, singular), 327 u"%s\x04%s" % (context, plural), number, 'ungettext') 328 if "\x04" in result: 329 # Translation not found 330 result = do_ntranslate(singular, plural, number, 'ungettext') 331 return result 332 316 333 def check_for_language(lang_code): 317 334 """ 318 335 Checks whether there is a global language file for the given language -
django/utils/translation/__init__.py
10 10 'get_language', 'get_language_bidi', 'get_date_formats', 11 11 'get_partial_date_formats', 'check_for_language', 'to_locale', 12 12 'get_language_from_request', 'templatize', 'ugettext', 'ugettext_lazy', 13 'ungettext', 'deactivate_all'] 13 'ungettext', 'ungettext_lazy', 'pgettext', 'pgettext_lazy', 14 'npgettext', 'npgettext_lazy', 'deactivate_all'] 14 15 15 16 # Here be dragons, so a short explanation of the logic won't hurt: 16 17 # We are trying to solve two problems: (1) access settings, in particular … … 63 64 def ungettext(singular, plural, number): 64 65 return _trans.ungettext(singular, plural, number) 65 66 67 def pgettext(context, message): 68 return _trans.pgettext(context, message) 69 70 def npgettext(context, singular, plural, number): 71 return _trans.npgettext(context, singular, plural, number) 72 66 73 ngettext_lazy = lazy(ngettext, str) 67 74 gettext_lazy = lazy(gettext, str) 68 75 ungettext_lazy = lazy(ungettext, unicode) 69 76 ugettext_lazy = lazy(ugettext, unicode) 77 pgettext_lazy = lazy(pgettext, unicode) 78 npgettext_lazy = lazy(npgettext, unicode) 70 79 71 80 def activate(language): 72 81 return _trans.activate(language) -
django/utils/translation/trans_null.py
15 15 def ungettext(singular, plural, number): 16 16 return force_unicode(ngettext(singular, plural, number)) 17 17 18 def pgettext(context, message): 19 return ugettext(message) 20 21 def npgettext(context, singular, plural, number): 22 return ungettext(singular, plural, number) 23 18 24 activate = lambda x: None 19 25 deactivate = deactivate_all = lambda: None 20 26 get_language = lambda: settings.LANGUAGE_CODE -
tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.po
20 20 #: models.py:3 21 21 msgid "Date/time" 22 22 msgstr "Datum/Zeit (LOCALE_PATHS)" 23 24 #: models.py:5 25 msgctxt "month name" 26 msgid "May" 27 msgstr "Mai" 28 29 #: models.py:7 30 msgctxt "verb" 31 msgid "May" 32 msgstr "Kann" 33 34 #: models.py:9 35 msgctxt "search" 36 msgid "%d result" 37 msgid_plural "%d results" 38 msgstr[0] "%d Resultat" 39 msgstr[1] "%d Resultate" -
tests/regressiontests/i18n/tests.py
11 11 from django.utils.formats import get_format, date_format, time_format, localize, localize_input, iter_format_modules 12 12 from django.utils.numberformat import format as nformat 13 13 from django.utils.safestring import mark_safe, SafeString, SafeUnicode 14 from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy, to_locale14 from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy, pgettext, npgettext, to_locale 15 15 from django.utils.importlib import import_module 16 16 17 17 … … 54 54 s2 = pickle.loads(pickle.dumps(s1)) 55 55 self.assertEqual(unicode(s2), "test") 56 56 57 def test_pgettext(self): 58 # Reset translation catalog to include other/locale/de 59 self.old_locale_paths = settings.LOCALE_PATHS 60 settings.LOCALE_PATHS += (os.path.join(os.path.dirname(os.path.abspath(__file__)), 'other', 'locale'),) 61 from django.utils.translation import trans_real 62 trans_real._active = {} 63 trans_real._translations = {} 64 activate('de') 65 66 self.assertEqual(pgettext("unexisting", "May"), u"May") 67 self.assertEqual(pgettext("month name", "May"), u"Mai") 68 self.assertEqual(pgettext("verb", "May"), u"Kann") 69 self.assertEqual(npgettext("search", "%d result", "%d results", 4) % 4, u"4 Resultate") 70 71 settings.LOCALE_PATHS = self.old_locale_paths 72 57 73 def test_string_concat(self): 58 74 """ 59 75 unicode(string_concat(...)) should not raise a TypeError - #4796