Repository: mozilla/puente

Issue:
add django gettext keywords
* upgettext
* upgettext_lazy
* pgettext
* pgettext_lazy
* etc

Add all the ones that we're currently missing.

Discussion:

Patch:
diff --git a/puente/commands.py b/puente/commands.py
index c21cdd3..a36d035 100644
--- a/puente/commands.py
+++ b/puente/commands.py
@@ -129,11 +129,10 @@ def extract_command(outputdir, domain_methods, text_domain, keywords,
     print('Done')
 
 
-def merge_command(create, backup, base_dir, domain_methods, languages):
+def merge_command(create, base_dir, domain_methods, languages):
     """
     :arg create: whether or not to create directories if they don't
         exist
-    :arg backup: whether or not to create backup .po files
     :arg base_dir: BASE_DIR setting
     :arg domain_methods: DOMAIN_METHODS setting
     :arg languages: LANGUAGES setting
@@ -214,7 +213,6 @@ def merge_command(create, backup, base_dir, domain_methods, languages):
                 'msgmerge',
                 '--update',
                 '--width=200',
-                '--backup=%s' % ('simple' if backup else 'off'),
                 domain_po,
                 '-'
             ]
diff --git a/puente/management/commands/merge.py b/puente/management/commands/merge.py
index acf9b26..74de7d9 100644
--- a/puente/management/commands/merge.py
+++ b/puente/management/commands/merge.py
@@ -32,17 +32,11 @@ class Command(BaseCommand):
             action='store_true', dest='create', default=False,
             help='Create locale subdirectories'
         ),
-        make_option(
-            '-b', '--backup',
-            action='store_true', dest='backup', default=False,
-            help='Create backup files of .po files'
-        ),
     )
 
     def handle(self, *args, **options):
         return merge_command(
             create=options.get('create'),
-            backup=options.get('backup'),
             base_dir=get_setting('BASE_DIR'),
             domain_methods=get_setting('DOMAIN_METHODS'),
             languages=getattr(settings, 'LANGUAGES', [])
diff --git a/puente/utils.py b/puente/utils.py
index e631102..ee1cc28 100644
--- a/puente/utils.py
+++ b/puente/utils.py
@@ -95,8 +95,20 @@ def generate_keywords(additional_keywords=None):
     # Shallow copy
     keywords = dict(BABEL_KEYWORDS)
 
-    keywords['_lazy'] = None
-    # FIXME: Add other keywords from Django here
+    keywords.update({
+        '_lazy': None,
+        'gettext_lazy': None,
+        'ugettext_lazy': None,
+        'gettext_noop': None,
+        'ugettext_noop': None,
+
+        'ngettext_lazy': (1, 2),
+        'ungettext_lazy': (1, 2),
+
+        'npgettext': ((1, 'c'), 2, 3),
+        'pgettext_lazy': ((1, 'c'), 2),
+        'npgettext_lazy': ((1, 'c'), 2, 3),
+    })
 
     # Add specified keywords
     if additional_keywords:


Test patch:
diff --git a/tests/test_extract.py b/tests/test_extract.py
index bc91f54..81fb63e 100644
--- a/tests/test_extract.py
+++ b/tests/test_extract.py
@@ -282,3 +282,63 @@ class TestExtractCommand:
 
             """)
         )
+
+    def test_django_pgettext_keywords(self, tmpdir):
+        # Test context
+        tmpdir.join('foo.py').write(dedent("""\
+        pgettext("context1", "string1")
+        pgettext_lazy("context2", "string2")
+        npgettext("context3", "string3", "plural3", 5)
+        npgettext_lazy("context4", "string4", "plural4", 5)
+        """))
+
+        # Extract
+        extract_command(
+            outputdir=str(tmpdir),
+            domain_methods={
+                'django': [
+                    ('*.py', 'python'),
+                ]
+            },
+            text_domain=puente_settings.TEXT_DOMAIN,
+            keywords=puente_settings.KEYWORDS,
+            comment_tags=puente_settings.COMMENT_TAGS,
+            base_dir=str(tmpdir),
+            project=puente_settings.PROJECT,
+            version=puente_settings.VERSION,
+            msgid_bugs_address=puente_settings.MSGID_BUGS_ADDRESS,
+        )
+
+        # Verify contents
+        assert os.path.exists(str(tmpdir.join('django.pot')))
+        pot_file = nix_header(tmpdir.join('django.pot').read())
+        assert (
+            pot_file ==
+            dedent("""\
+            #: foo.py:1
+            msgctxt "context1"
+            msgid "string1"
+            msgstr ""
+
+            #: foo.py:2
+            msgctxt "context2"
+            msgid "string2"
+            msgstr ""
+
+            #: foo.py:3
+            msgctxt "context3"
+            msgid "string3"
+            msgid_plural "plural3"
+            msgstr[0] ""
+            msgstr[1] ""
+
+            #: foo.py:4
+            msgctxt "context4"
+            msgid "string4"
+            msgid_plural "plural4"
+            msgstr[0] ""
+            msgstr[1] ""
+
+            """)
+        )
+
diff --git a/tests/test_merge.py b/tests/test_merge.py
index 60b46f1..29e1456 100644
--- a/tests/test_merge.py
+++ b/tests/test_merge.py
@@ -65,7 +65,6 @@ class TestMergecommand:
 
         merge_command(
             create=True,
-            backup=True,
             base_dir=str(tmpdir),
             domain_methods={
                 'django': [
@@ -84,7 +83,6 @@ class TestMergecommand:
         with pytest.raises(CommandError):
             merge_command(
                 create=True,
-                backup=True,
                 base_dir=str(tmpdir),
                 domain_methods={
                     'django': [