Skip to content

Commit

Permalink
Merge branch 'master' into issue_312
Browse files Browse the repository at this point in the history
  • Loading branch information
gogobd committed Feb 21, 2024
2 parents cc70400 + 44c9006 commit 0b0984d
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 22 deletions.
27 changes: 27 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@ Changelog
.. towncrier release notes start
2.0.9 (2024-02-12)
------------------

Internal:


- Improved efficiency of view retrieval by deferring availability checks to error handling. @samriddhi99 (#479)


2.0.8 (2023-12-14)
------------------

Bug fixes:


- Fix `api.portal.translate` usage with country-specific language codes [@ericof] (#524)


2.0.7 (2023-11-30)
------------------

Documentation:


- Use the preferred `git switch -c` command. See https://www.infoq.com/news/2019/08/git-2-23-switch-restore/. @stevepiercy (#520)


2.0.6 (2023-11-03)
------------------

Expand Down
1 change: 0 additions & 1 deletion news/520.documentation

This file was deleted.

18 changes: 17 additions & 1 deletion requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
docutils<0.17,>=0.15 # sphinx-book-theme 0.2.0 has requirement docutils<0.17,>=0.15
Sphinx<5,>=3 # sphinx-book-theme 0.3.3 has requirement sphinx<5,>=3
sphinx-book-theme<=0.3.99
lesscpy
linkify-it-py
myst-parser
sphinx-autobuild
pydata-sphinx-theme<=0.8.99
sphinx-book-theme==0.3.3
sphinx-copybutton
sphinx-sitemap
sphinx-togglebutton
sphinxcontrib-spelling
sphinxext-opengraph
sphinxcontrib-applehelp==1.0.4 # https://github.com/plone/documentation/issues/1604
sphinxcontrib-devhelp==1.0.2 # https://github.com/plone/documentation/issues/1604
sphinxcontrib-htmlhelp==2.0.1 # https://github.com/plone/documentation/issues/1604
sphinxcontrib-qthelp==1.0.3 # https://github.com/plone/documentation/issues/1604
sphinxcontrib-serializinghtml==1.1.5 # https://github.com/plone/documentation/issues/1604
sphinxcontrib-video
vale==2.30.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def read(*rnames):
read("README.md") + "\n\n" + read("CHANGES.rst") + "\n\n" + read("LICENSE")
)

version = "2.0.7.dev0"
version = "2.0.10.dev0"

setup(
name="plone.api",
Expand Down
42 changes: 23 additions & 19 deletions src/plone/api/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from plone.uuid.interfaces import IUUID
from Products.CMFCore.DynamicType import DynamicType
from Products.CMFCore.WorkflowCore import WorkflowException
from zope.component import ComponentLookupError
from zope.component import getMultiAdapter
from zope.component import getSiteManager
from zope.container.interfaces import INameChooser
Expand Down Expand Up @@ -523,26 +524,29 @@ def get_view(name=None, context=None, request=None):
# available, because the __init__ of said view will contain
# errors in client code.

# Get all available views...
sm = getSiteManager()
available_views = sm.adapters.lookupAll(
required=(providedBy(context), providedBy(request)),
provided=Interface,
)
# and get their names.
available_view_names = [view[0] for view in available_views]

# Raise an error if the requested view is not available.
if name not in available_view_names:
raise InvalidParameterError(
"Cannot find a view with name '{name}'.\n"
"Available views are:\n"
"{views}".format(
name=name,
views="\n".join(sorted(available_view_names)),
),
try:
return getMultiAdapter((context, request), name=name)
except ComponentLookupError:
# Getting all available views
sm = getSiteManager()
available_views = sm.adapters.lookupAll(
required=(providedBy(context), providedBy(request)),
provided=Interface,
)
return getMultiAdapter((context, request), name=name)

# Check if the requested view is available
# by getting the names of all available views
available_view_names = [view[0] for view in available_views]
if name not in available_view_names:
# Raise an error if the requested view is not available.
raise InvalidParameterError(
"Cannot find a view with name '{name}'.\n"
"Available views are:\n"
"{views}".format(
name=name,
views="\n".join(sorted(available_view_names)),
),
)


@required_parameters("obj")
Expand Down
3 changes: 3 additions & 0 deletions src/plone/api/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from zope.interface.interfaces import IInterface

import datetime as dtime
import re


logger = getLogger("plone.api.portal")
Expand Down Expand Up @@ -419,6 +420,8 @@ def translate(msgid, domain="plone", lang=None):
:Example: :ref:`portal-translate-example`
"""
translation_service = get_tool("translation_service")
if lang and re.match(r"\D{2}-\D{2}", lang):
lang = f"{lang[:2]}_{lang[-2:].upper()}"
query = {
"msgid": msgid,
"domain": domain,
Expand Down
17 changes: 17 additions & 0 deletions src/plone/api/tests/test_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,20 @@ def test_translate(self):
),
"Avril",
)

def test_translate_with_country_codes(self):
"""Test translation."""
self.assertEqual(
portal.translate(
"Page",
lang="pt-br",
),
"Página",
)
self.assertEqual(
portal.translate(
"Page",
lang="pt_BR",
),
"Página",
)

0 comments on commit 0b0984d

Please sign in to comment.