From b40302415ba26520d2cec101cfe6c82dfc140266 Mon Sep 17 00:00:00 2001 From: gforcada Date: Sun, 20 Aug 2017 22:29:31 +0200 Subject: [PATCH] [fc] Repository: plone.api Branch: refs/heads/master Date: 2017-08-14T17:05:12+02:00 Author: Maurits van Rees (mauritsvanrees) Commit: https://github.com/plone/plone.api/commit/03b900e6d6cff02bc56baa81339915cc631ae58f Let ``zope.i18n`` do the language negotiation for our ``translate`` function. Our ``get_current_translation`` does not always give the correct one, especially with combined languages: ``nl-be`` (Belgian/Flemish) should fall back to ``nl`` (Dutch). The correct negotiated language can also differ per translation domain, which we do not account for. ``zope.i18n`` does that better. Fixes https://github.com/plone/plone.api/issues/379. Files changed: M CHANGES.rst M src/plone/api/portal.py Repository: plone.api Branch: refs/heads/master Date: 2017-08-20T22:29:31+02:00 Author: Gil Forcada Codinachs (gforcada) Commit: https://github.com/plone/plone.api/commit/88cc536cd82b2dc8c6a91f0e50bfde58d849e92f Merge pull request #382 from plone/issue-379-translate-negotiate Let zope.i18n do language negotiation for our translate function Files changed: M CHANGES.rst M src/plone/api/portal.py --- last_commit.txt | 143 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 120 insertions(+), 23 deletions(-) diff --git a/last_commit.txt b/last_commit.txt index 0ac38bf458..fd80ea4e8c 100644 --- a/last_commit.txt +++ b/last_commit.txt @@ -1,32 +1,129 @@ -Repository: plone.subrequest +Repository: plone.api Branch: refs/heads/master -Date: 2017-08-18T18:16:54+02:00 -Author: Johannes Raggam (thet) -Commit: https://github.com/plone/plone.subrequest/commit/a049a4706a076f07da39138ef1fee30f8c0621f7 +Date: 2017-08-14T17:05:12+02:00 +Author: Maurits van Rees (mauritsvanrees) +Commit: https://github.com/plone/plone.api/commit/03b900e6d6cff02bc56baa81339915cc631ae58f -Revert "Update __init__.py (remove virtual-url-parts from path) (#13)" +Let ``zope.i18n`` do the language negotiation for our ``translate`` function. -This reverts commit 12abd545e9f165256c83bb048c4e705e288fe752. -It broke subrequest calls in virtual hosted environments. -See: https://github.com/plone/plone.subrequest/issues/14 -And: https://github.com/plone/plone.subrequest/pull/13 +Our ``get_current_translation`` does not always give the correct one, especially with combined languages: +``nl-be`` (Belgian/Flemish) should fall back to ``nl`` (Dutch). +The correct negotiated language can also differ per translation domain, which we do not account for. +``zope.i18n`` does that better. + +Fixes https://github.com/plone/plone.api/issues/379. + +Files changed: +M CHANGES.rst +M src/plone/api/portal.py + +diff --git a/CHANGES.rst b/CHANGES.rst +index be30891..581585e 100644 +--- a/CHANGES.rst ++++ b/CHANGES.rst +@@ -14,7 +14,13 @@ New features: + + Bug fixes: + +-- *add item here* ++- Let ``zope.i18n`` do the language negotiation for our ``translate`` function. ++ Our ``get_current_translation`` does not always give the correct one, especially with combined languages: ++ ``nl-be`` (Belgian/Flemish) should fall back to ``nl`` (Dutch). ++ The correct negotiated language can also differ per translation domain, which we do not account for. ++ ``zope.i18n`` does that better. ++ Fixes `issue 379 `_. ++ [maurits] + + + 1.8 (2017-08-05) +diff --git a/src/plone/api/portal.py b/src/plone/api/portal.py +index 5dae7b4..81e86cc 100644 +--- a/src/plone/api/portal.py ++++ b/src/plone/api/portal.py +@@ -445,11 +445,12 @@ def translate(msgid, domain='plone', lang=None): + :Example: :ref:`portal_translate_example` + """ + translation_service = get_tool('translation_service') +- if not lang: +- lang = get_current_language() +- +- return translation_service.utranslate( +- msgid=msgid, +- domain=domain, +- target_language=lang, +- ) ++ query = { ++ 'msgid': msgid, ++ 'domain': domain, ++ 'target_language': lang, ++ } ++ if lang is None: ++ # Pass the request, so zope.i18n.translate can negotiate the language. ++ query['context'] = getRequest() ++ return translation_service.utranslate(**query) + + +Repository: plone.api + + +Branch: refs/heads/master +Date: 2017-08-20T22:29:31+02:00 +Author: Gil Forcada Codinachs (gforcada) +Commit: https://github.com/plone/plone.api/commit/88cc536cd82b2dc8c6a91f0e50bfde58d849e92f + +Merge pull request #382 from plone/issue-379-translate-negotiate + +Let zope.i18n do language negotiation for our translate function Files changed: -M plone/subrequest/__init__.py - -diff --git a/plone/subrequest/__init__.py b/plone/subrequest/__init__.py -index f95f067..1b46f8f 100644 ---- a/plone/subrequest/__init__.py -+++ b/plone/subrequest/__init__.py -@@ -89,7 +89,6 @@ def subrequest(url, root=None, stdout=None, exception_handler=None): - root_path = normpath( - parent_request['PATH_INFO'] - ).rstrip('/')[:-len(path_past_root) or None] -- path = path.replace(vurl_parts[1], '', 1) - if root is None: - path = root_path + path - else: +M CHANGES.rst +M src/plone/api/portal.py + +diff --git a/CHANGES.rst b/CHANGES.rst +index be30891..581585e 100644 +--- a/CHANGES.rst ++++ b/CHANGES.rst +@@ -14,7 +14,13 @@ New features: + + Bug fixes: + +-- *add item here* ++- Let ``zope.i18n`` do the language negotiation for our ``translate`` function. ++ Our ``get_current_translation`` does not always give the correct one, especially with combined languages: ++ ``nl-be`` (Belgian/Flemish) should fall back to ``nl`` (Dutch). ++ The correct negotiated language can also differ per translation domain, which we do not account for. ++ ``zope.i18n`` does that better. ++ Fixes `issue 379 `_. ++ [maurits] + + + 1.8 (2017-08-05) +diff --git a/src/plone/api/portal.py b/src/plone/api/portal.py +index 5dae7b4..81e86cc 100644 +--- a/src/plone/api/portal.py ++++ b/src/plone/api/portal.py +@@ -445,11 +445,12 @@ def translate(msgid, domain='plone', lang=None): + :Example: :ref:`portal_translate_example` + """ + translation_service = get_tool('translation_service') +- if not lang: +- lang = get_current_language() +- +- return translation_service.utranslate( +- msgid=msgid, +- domain=domain, +- target_language=lang, +- ) ++ query = { ++ 'msgid': msgid, ++ 'domain': domain, ++ 'target_language': lang, ++ } ++ if lang is None: ++ # Pass the request, so zope.i18n.translate can negotiate the language. ++ query['context'] = getRequest() ++ return translation_service.utranslate(**query)