Ticket #7704: makemessages.diff

File makemessages.diff, 5.0 KB (added by Ned Batchelder, 14 years ago)

Adapt makemessages to use JsLexer

  • django/core/management/commands/makemessages.py

     
    99
    1010from django.core.management.base import CommandError, NoArgsCommand
    1111from django.utils.text import get_text_list
     12from django.utils.jslex import js_to_c_for_gettext
    1213
    13 pythonize_re = re.compile(r'(?:^|\n)\s*//')
    1414plural_forms_re = re.compile(r'^(?P<value>"Plural-Forms.+?\\n")\s*$', re.MULTILINE | re.DOTALL)
    1515
    1616def handle_extensions(extensions=('html',)):
     
    184184                if verbosity > 1:
    185185                    sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    186186                src = open(os.path.join(dirpath, file), "rU").read()
    187                 src = pythonize_re.sub('\n#', src)
    188                 thefile = '%s.py' % file
     187                src = js_to_c_for_gettext(src)
     188                thefile = '%s.c' % file
    189189                f = open(os.path.join(dirpath, thefile), "w")
    190190                try:
    191191                    f.write(src)
    192192                finally:
    193193                    f.close()
    194194                cmd = (
    195                     'xgettext -d %s -L Perl %s --keyword=gettext_noop '
     195                    'xgettext -d %s -L C %s --keyword=gettext_noop '
    196196                    '--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 '
    197197                    '--keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 '
    198198                    '--from-code UTF-8 --add-comments=Translators -o - "%s"' % (
  • tests/regressiontests/i18n/commands/javascript.js

     
    11// '
    22gettext('This literal should be included.')
    3 // '
    4 gettext('This one as well.')
     3x = y; // '
     4gettext("This one as well.")
     5
     6/** (from ticket 7704)
     7 * *****************************
     8 * AddModule main / window
     9 * @constructor
     10 * @class MyDesktop.AddModule
     11 * *****************************
     12 */
     13
     14gettext('He said, \"hello".')
     15
     16// from ticket 14045
     17function mfunc() {
     18    var val = 0;
     19    return val ? 1 : 0;
     20}
     21gettext('okkkk');
     22print mysub();
     23
     24// from ticket 15495
     25/* / ' */ gettext("TEXT");
     26
     27gettext("It's at http://example.com")
     28
     29// also from ticket 15495
     30gettext("String"); // This comment won't be caught by pythonize_re and it contains "'" which is a string start in Perl
     31/*
     32 * This one will be removed by the patch
     33 */
     34gettext("/* but this one will be too */ 'cause there is no way of telling...");
     35f(/* ... if it's different from this one */);
     36
     37// from ticket 15331
     38gettext("foo");
     39true ? true : false;
     40gettext("bar");
     41true ? true : false;
     42gettext("baz");
     43true ? true : false; // ?
     44gettext("quz");
     45"?";
     46gettext("foobar");
     47
  • tests/regressiontests/i18n/commands/extraction.py

     
    3030    def assertMsgId(self, msgid, s, use_quotes=True):
    3131        if use_quotes:
    3232            msgid = '"%s"' % msgid
     33        msgid = re.escape(msgid)
    3334        return self.assertTrue(re.search('^msgid %s' % msgid, s, re.MULTILINE))
    3435
    3536    def assertNotMsgId(self, msgid, s, use_quotes=True):
    3637        if use_quotes:
    3738            msgid = '"%s"' % msgid
     39        msgid = re.escape(msgid)
    3840        return self.assertTrue(not re.search('^msgid %s' % msgid, s, re.MULTILINE))
    3941
    4042
     
    6971        self.assertTrue(os.path.exists(self.PO_FILE))
    7072        po_contents = open(self.PO_FILE, 'r').read()
    7173        self.assertMsgId('I think that 100%% is more that 50%% of anything.', po_contents)
    72         self.assertMsgId('I think that 100%% is more that 50%% of %\(obj\)s.', po_contents)
     74        self.assertMsgId('I think that 100%% is more that 50%% of %(obj)s.', po_contents)
    7375
    7476    def test_extraction_error(self):
    7577        os.chdir(self.test_dir)
     
    9597        po_contents = open(self.PO_FILE, 'r').read()
    9698        self.assertMsgId('This literal should be included.', po_contents)
    9799        self.assertMsgId('This one as well.', po_contents)
     100        self.assertMsgId(r'He said, \"hello\".', po_contents)
     101        self.assertMsgId("okkkk", po_contents)
     102        self.assertMsgId("TEXT", po_contents)
     103        self.assertMsgId("It's at http://example.com", po_contents)
     104        self.assertMsgId("String", po_contents)
     105        self.assertMsgId("/* but this one will be too */ 'cause there is no way of telling...", po_contents)
     106        self.assertMsgId("foo", po_contents)
     107        self.assertMsgId("bar", po_contents)
     108        self.assertMsgId("baz", po_contents)
     109        self.assertMsgId("quz", po_contents)
     110        self.assertMsgId("foobar", po_contents)
    98111
    99 
    100112class IgnoredExtractorTests(ExtractorTests):
    101113
    102114    def test_ignore_option(self):
Back to Top