Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits: 58402426 by Jonas Meurer at 2019-01-28T22:49:54Z Lookup in-tree templates for each language in search (Fixes #535) * Until now, the in-tree templates were only taken into account after custom templates for all preferred languages were scanned. This is changed now: at the end of each language, a search for in-tree templates for that language is added. This fixes two separate issues: * If the list of preferred languages in a search contained first english (but no custom english templates existed) and then another language with existing custom templates, then the custom template of that second language was picked. But the in-tree english template should have had priority. * If mailman later ships in-tree templates for other languages, they will be taken into account. - - - - - 6ebc546a by Abhilash Raj at 2019-01-29T20:27:16Z Merge branch 'template_search' into 'master' Lookup in-tree templates for each language in search (Fixes #535) Closes #535 See merge request mailman/mailman!442 - - - - - 3 changed files: - src/mailman/docs/NEWS.rst - src/mailman/utilities/i18n.py - src/mailman/utilities/tests/test_templates.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== @@ -47,6 +47,8 @@ Other * A substitution variable ``user_name_or_email`` has been added to ``list:member:regular:header`` and ``list:member:regular:footer`` templates when personalized deliveries are enabled. (Closes #533) +* The template search algorithm was fixed to look for in-tree templates for + each language in the search list. (Closes #535) 3.2.0 -- "La Villa Strangiato" ===================================== src/mailman/utilities/i18n.py ===================================== @@ -61,6 +61,9 @@ def search(resources, template_file, mlist=None, language=None): * The site-wide language directory $template_dir/site/<language> + * The template direcotry within the mailman source tree + * <source_dir>/templates/<language> + The <language> path component is calculated as follows, in this order: * The `language` parameter if given @@ -78,21 +81,25 @@ def search(resources, template_file, mlist=None, language=None): * $template_dir/lists/t...@example.com/it/foo.txt (deprecated) * $template_dir/domains/example.com/it/foo.txt * $template_dir/site/it/foo.txt + * <source_dir>/templates/it/foo.txt * $template_dir/lists/test.example.com/de/foo.txt * $template_dir/lists/t...@example.com/de/foo.txt (deprecated) * $template_dir/domains/example.com/de/foo.txt * $template_dir/site/de/foo.txt + * <source_dir>/templates/de/foo.txt * $template_dir/lists/test.example.com/fr/foo.txt * $template_dir/lists/t...@example.com/fr/foo.txt (deprecated) * $template_dir/domains/example.com/fr/foo.txt * $template_dir/site/fr/foo.txt + * <source_dir>/templates/fr/foo.txt * $template_dir/lists/test.example.com/en/foo.txt * $template_dir/lists/t...@example.com/en/foo.txt (deprecated) * $template_dir/domains/example.com/en/foo.txt * $template_dir/site/en/foo.txt + * <source_dir>/templates/en/foo.txt After all those paths are searched, the final fallback is the English template within the Mailman source tree. @@ -107,7 +114,8 @@ def search(resources, template_file, mlist=None, language=None): languages.append(language) languages.reverse() # The non-language qualified $template_dir paths in search order. - paths = [os.path.join(config.TEMPLATE_DIR, 'site')] + templates_dir = str(resources.enter_context(path('mailman', 'templates'))) + paths = [templates_dir, os.path.join(config.TEMPLATE_DIR, 'site')] if mlist is not None: # Don't forget these are in REVERSE search order! paths.append(os.path.join( @@ -120,7 +128,6 @@ def search(resources, template_file, mlist=None, language=None): for language, search_path in product(languages, paths): yield os.path.join(search_path, language, template_file) # Finally, fallback to the in-tree English template. - templates_dir = str(resources.enter_context(path('mailman', 'templates'))) yield os.path.join(templates_dir, 'en', template_file) ===================================== src/mailman/utilities/tests/test_templates.py ===================================== @@ -88,24 +88,28 @@ class TestSearchOrder(unittest.TestCase): nexteq('/v/templates/lists/l...@example.com/it/foo.txt') nexteq('/v/templates/domains/example.com/it/foo.txt') nexteq('/v/templates/site/it/foo.txt') + nexteq('/m/templates/it/foo.txt') # 2: Use mlist.preferred_language nexteq('/v/templates/lists/l.example.com/de/foo.txt') nexteq('/v/templates/lists/l...@example.com/de/foo.txt') nexteq('/v/templates/domains/example.com/de/foo.txt') nexteq('/v/templates/site/de/foo.txt') + nexteq('/m/templates/de/foo.txt') # 3: Use the site's default language nexteq('/v/templates/lists/l.example.com/fr/foo.txt') nexteq('/v/templates/lists/l...@example.com/fr/foo.txt') nexteq('/v/templates/domains/example.com/fr/foo.txt') nexteq('/v/templates/site/fr/foo.txt') + nexteq('/m/templates/fr/foo.txt') # 4: English nexteq('/v/templates/lists/l.example.com/en/foo.txt') nexteq('/v/templates/lists/l...@example.com/en/foo.txt') nexteq('/v/templates/domains/example.com/en/foo.txt') nexteq('/v/templates/site/en/foo.txt') + nexteq('/m/templates/en/foo.txt') # 5: After all the site-admin override paths have been searched, the - # Mailman in-tree paths are searched. Note that Mailman only ships - # one set of English templates. + # Mailman in-tree english path is searched. Note that Mailman + # currently only ships one set of English templates. nexteq('/m/templates/en/foo.txt') def test_no_language_argument_search_order(self): @@ -118,16 +122,19 @@ class TestSearchOrder(unittest.TestCase): nexteq('/v/templates/lists/l...@example.com/de/foo.txt') nexteq('/v/templates/domains/example.com/de/foo.txt') nexteq('/v/templates/site/de/foo.txt') + nexteq('/m/templates/de/foo.txt') # 2: Use the site's default language nexteq('/v/templates/lists/l.example.com/fr/foo.txt') nexteq('/v/templates/lists/l...@example.com/fr/foo.txt') nexteq('/v/templates/domains/example.com/fr/foo.txt') nexteq('/v/templates/site/fr/foo.txt') + nexteq('/m/templates/fr/foo.txt') # 3: English nexteq('/v/templates/lists/l.example.com/en/foo.txt') nexteq('/v/templates/lists/l...@example.com/en/foo.txt') nexteq('/v/templates/domains/example.com/en/foo.txt') nexteq('/v/templates/site/en/foo.txt') + nexteq('/m/templates/en/foo.txt') # 4: After all the site-admin override paths have been searched, the # Mailman in-tree paths are searched. Note that Mailman only ships # one set of English templates. @@ -140,10 +147,13 @@ class TestSearchOrder(unittest.TestCase): self.assertEqual(next(search_order), path) # 1: Use the given language argument nexteq('/v/templates/site/it/foo.txt') + nexteq('/m/templates/it/foo.txt') # 2: Use the site's default language nexteq('/v/templates/site/fr/foo.txt') + nexteq('/m/templates/fr/foo.txt') # 3: English nexteq('/v/templates/site/en/foo.txt') + nexteq('/m/templates/en/foo.txt') # 4: After all the site-admin override paths have been searched, the # Mailman in-tree paths are searched. Note that Mailman only ships # one set of English templates. @@ -156,8 +166,10 @@ class TestSearchOrder(unittest.TestCase): self.assertEqual(next(search_order), path) # 1: Use the site's default language nexteq('/v/templates/site/fr/foo.txt') + nexteq('/m/templates/fr/foo.txt') # 2: English nexteq('/v/templates/site/en/foo.txt') + nexteq('/m/templates/en/foo.txt') # 3: After all the site-admin override paths have been searched, the # Mailman in-tree paths are searched. Note that Mailman only ships # one set of English templates. View it on GitLab: https://gitlab.com/mailman/mailman/compare/8d9f8055933887570fa93fab44a5cc41a03a700c...6ebc546a772e28eb1c459ac7a28300269af1a50c -- View it on GitLab: https://gitlab.com/mailman/mailman/compare/8d9f8055933887570fa93fab44a5cc41a03a700c...6ebc546a772e28eb1c459ac7a28300269af1a50c You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org