Repository: ckan/ckan

Issue:
Message extraction ignores jinja extensions.
### CKAN Version if known (or site URL)
master

### Please describe the expected behaviour
All translations should be extracted to ckan.pot when running python setup.py extract_messages.

### Please describe the actual behaviour
Templates that use [link_for](https://github.com/ckan/ckan/blob/master/ckan/lib/jinja_extensions.py#L302) extension are ignored in the message extraction. This is apparent as [ckan.pot](https://github.com/ckan/ckan/blob/master/ckan/i18n/ckan.pot) doens't have translations from [request_reset.html](https://github.com/ckan/ckan/blob/master/ckan/templates/user/request_reset.html) which uses link_for tag. If the tag is removed from the template, messages are extracted correctly. This is likely regression from https://github.com/ckan/ckan/pull/5339 as 2.8 still extracts them.

### What steps can be taken to reproduce the issue? 
Run python setup.py extract_messages
ckan.pot should have messages from request_reset.html but it doesn't.


Discussion:

Resolving patch:
diff --git a/ckan/lib/extract.py b/ckan/lib/extract.py
--- a/ckan/lib/extract.py
+++ b/ckan/lib/extract.py
@@ -1,15 +1,23 @@
 # encoding: utf-8
 
 from jinja2.ext import babel_extract
+from ckan.lib.jinja_extensions import _get_extensions
 
 
-# It's no longer needed but all the extensions are using this
-# function. Let's keep it, just in case we need to extract messages in
-# some special way in future
 def extract_ckan(fileobj, *args, **kw):
+    extensions = [
+        ':'.join([ext.__module__, ext.__name__])
+        if isinstance(ext, type)
+        else ext
+        for ext in _get_extensions()
+    ]
     if 'options' not in kw:
         kw['options'] = {}
     if 'trimmed' not in kw['options']:
         kw['options']['trimmed'] = 'True'
+    if 'silent' not in kw['options']:
+        kw['options']['silent'] = 'False'
+    if 'extensions' not in kw['options']:
+        kw['options']['extensions'] = ','.join(extensions)
 
     return babel_extract(fileobj, *args, **kw)
diff --git a/ckan/lib/jinja_extensions.py b/ckan/lib/jinja_extensions.py
--- a/ckan/lib/jinja_extensions.py
+++ b/ckan/lib/jinja_extensions.py
@@ -23,19 +23,23 @@
 log = logging.getLogger(__name__)
 
 
+def _get_extensions():
+    return ['jinja2.ext.do', 'jinja2.ext.with_',
+            SnippetExtension,
+            CkanExtend,
+            CkanInternationalizationExtension,
+            LinkForExtension,
+            ResourceExtension,
+            UrlForStaticExtension,
+            UrlForExtension,
+            AssetExtension]
+
+
 def get_jinja_env_options():
     return dict(
         loader=CkanFileSystemLoader(config['computed_template_paths']),
         autoescape=True,
-        extensions=['jinja2.ext.do', 'jinja2.ext.with_',
-                    SnippetExtension,
-                    CkanExtend,
-                    CkanInternationalizationExtension,
-                    LinkForExtension,
-                    ResourceExtension,
-                    UrlForStaticExtension,
-                    UrlForExtension,
-                    AssetExtension],
+        extensions=_get_extensions(),
     )
 
 


Test patch: