Ticket #16903: no-location-3.patch

File no-location-3.patch, 7.9 KB (added by Alpár Jüttner, 13 years ago)

Fix tests, add docs

  • docs/ref/django-admin.txt

     
    475475Use the ``--no-wrap`` option to disable breaking long message lines into
    476476several lines in language files.
    477477
     478.. django-admin-option:: --no-location
     479
     480.. versionadded:: 1.4
     481
     482Use the ``--no-location`` option to not write ``#: filename:line``
     483comment lines in language files.
     484
    478485reset <appname appname ...>
    479486---------------------------
    480487
  • django/core/management/commands/makemessages.py

     
    115115
    116116def make_messages(locale=None, domain='django', verbosity='1', all=False,
    117117        extensions=None, symlinks=False, ignore_patterns=[], no_wrap=False,
     118        no_location=False,
    118119        no_obsolete=False):
    119120    """
    120121    Uses the locale directory from the Django SVN tree or an application/
     
    163164        languages = [os.path.basename(l) for l in locale_dirs]
    164165
    165166    wrap = no_wrap and '--no-wrap' or ''
     167    location = no_location and '--no-location' or ''
    166168
    167169    for locale in languages:
    168170        if verbosity > 0:
     
    191193                finally:
    192194                    f.close()
    193195                cmd = (
    194                     'xgettext -d %s -L C %s --keyword=gettext_noop '
     196                    'xgettext -d %s -L C %s %s --keyword=gettext_noop '
    195197                    '--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 '
    196198                    '--keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 '
    197199                    '--from-code UTF-8 --add-comments=Translators -o - "%s"' % (
    198                         domain, wrap, os.path.join(dirpath, thefile)
     200                        domain, wrap, location, os.path.join(dirpath, thefile)
    199201                    )
    200202                )
    201203                msgs, errors = _popen(cmd)
     
    235237                if verbosity > 1:
    236238                    sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
    237239                cmd = (
    238                     'xgettext -d %s -L Python %s --keyword=gettext_noop '
     240                    'xgettext -d %s -L Python %s %s --keyword=gettext_noop '
    239241                    '--keyword=gettext_lazy --keyword=ngettext_lazy:1,2 '
    240242                    '--keyword=ugettext_noop --keyword=ugettext_lazy '
    241243                    '--keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2 '
    242244                    '--keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2 '
    243245                    '--keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 '
    244246                    '--add-comments=Translators -o - "%s"' % (
    245                         domain, wrap, os.path.join(dirpath, thefile))
     247                        domain, wrap, location, os.path.join(dirpath, thefile))
    246248                )
    247249                msgs, errors = _popen(cmd)
    248250                if errors:
     
    272274                    os.unlink(os.path.join(dirpath, thefile))
    273275
    274276        if os.path.exists(potfile):
    275             msgs, errors = _popen('msguniq %s --to-code=utf-8 "%s"' %
    276                                   (wrap, potfile))
     277            msgs, errors = _popen('msguniq %s %s --to-code=utf-8 "%s"' %
     278                                  (wrap, location, potfile))
    277279            if errors:
    278280                os.unlink(potfile)
    279281                raise CommandError(
     
    284286                    f.write(msgs)
    285287                finally:
    286288                    f.close()
    287                 msgs, errors = _popen('msgmerge %s -q "%s" "%s"' %
    288                                       (wrap, pofile, potfile))
     289                msgs, errors = _popen('msgmerge %s %s -q "%s" "%s"' %
     290                                      (wrap, location, pofile, potfile))
    289291                if errors:
    290292                    os.unlink(potfile)
    291293                    raise CommandError(
     
    301303                f.close()
    302304            os.unlink(potfile)
    303305            if no_obsolete:
    304                 msgs, errors = _popen('msgattrib %s -o "%s" --no-obsolete "%s"' %
    305                                       (wrap, pofile, pofile))
     306                msgs, errors = _popen('msgattrib %s %s -o "%s" --no-obsolete "%s"' %
     307                                      (wrap, location, pofile, pofile))
    306308                if errors:
    307309                    raise CommandError(
    308310                        "errors happened while running msgattrib\n%s" % errors)
     
    327329            default=True, help="Don't ignore the common glob-style patterns 'CVS', '.*' and '*~'."),
    328330        make_option('--no-wrap', action='store_true', dest='no_wrap',
    329331            default=False, help="Don't break long message lines into several lines"),
     332        make_option('--no-location', action='store_true', dest='no_location',
     333            default=False, help="Don't write '#: filename:line' lines"),
    330334        make_option('--no-obsolete', action='store_true', dest='no_obsolete',
    331335            default=False, help="Remove obsolete message strings"),
    332336    )
     
    351355            ignore_patterns += ['CVS', '.*', '*~']
    352356        ignore_patterns = list(set(ignore_patterns))
    353357        no_wrap = options.get('no_wrap')
     358        no_location = options.get('no_location')
    354359        no_obsolete = options.get('no_obsolete')
    355360        if domain == 'djangojs':
    356361            extensions = handle_extensions(extensions or ['js'])
     
    361366            sys.stdout.write('examining files with the extensions: %s\n'
    362367                             % get_text_list(list(extensions), 'and'))
    363368
    364         make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_obsolete)
     369        make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_location, no_obsolete)
  • tests/regressiontests/i18n/commands/extraction.py

     
    214214        self.assertTrue(os.path.exists(self.PO_FILE))
    215215        po_contents = open(self.PO_FILE, 'r').read()
    216216        self.assertMsgId('""\n"This literal should also be included wrapped or not wrapped depending on the "\n"use of the --no-wrap option."', po_contents, use_quotes=False)
     217
     218
     219class NoLocationExtractorTests(ExtractorTests):
     220
     221    def test_no_location_enabled(self):
     222        os.chdir(self.test_dir)
     223        management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=True)
     224        self.assertTrue(os.path.exists(self.PO_FILE))
     225        po_contents = open(self.PO_FILE, 'r').read()
     226        self.assertFalse('#: templates/test.html:55' in po_contents)
     227
     228    def test_no_location_disabled(self):
     229        os.chdir(self.test_dir)
     230        management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=False)
     231        self.assertTrue(os.path.exists(self.PO_FILE))
     232        po_contents = open(self.PO_FILE, 'r').read()
     233        self.assertTrue('#: templates/test.html:55' in po_contents)
  • tests/regressiontests/i18n/tests.py

     
    2828if can_run_extraction_tests:
    2929    from .commands.extraction import (ExtractorTests, BasicExtractorTests,
    3030        JavascriptExtractorTests, IgnoredExtractorTests, SymlinkExtractorTests,
    31         CopyPluralFormsExtractorTests, NoWrapExtractorTests)
     31        CopyPluralFormsExtractorTests, NoWrapExtractorTests,
     32        NoLocationExtractorTests)
    3233if can_run_compilation_tests:
    3334    from .commands.compilation import MessageCompilationTests, PoFileTests
    3435from .contenttypes.tests import ContentTypeTests
Back to Top