Skip to content

Commit

Permalink
Merge pull request #382 from plone/issue-379-translate-negotiate
Browse files Browse the repository at this point in the history
Let zope.i18n do language negotiation for our translate function
  • Loading branch information
gforcada committed Aug 20, 2017
2 parents cec0b78 + 03b900e commit 88cc536
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/plone/plone.api/issues/379>`_.
[maurits]


1.8 (2017-08-05)
Expand Down
17 changes: 9 additions & 8 deletions src/plone/api/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 88cc536

Please sign in to comment.