How to get a specific content type in Plone automatically translated while querying?

I have a view method and I want to it to return different content based on the context you're on and this content is stored in /en/module/document how do I make a query that returns the same selected content based on the current language? The same translated document will also be in /it/moduli/documento . I know how to query based on the location of the cotnent but that would be hardcoding it for every language.

 def getModuleContent(self):
   if self.context == "projects":
       document1 = api.content.find(portal_type='Document', context=?) #document1, return based on current language
   if self.context == "home":
       document2 = api.content.find(portal_type='Document', context=?) #document2, return based on current languag
        <div class="moduleLink">
            <tal:block tal:define="module view/getModuleContent">
            </tal:block>
        </div>

if your contents are linked as translations with p.a.multilingual, you can query the one in english (you know its path), and then return its translation using the translation getting helper methods.

Yes, they are linked. Do you have a like to show me how this is done in the view code?

Yup. It would be something like this:

from plone import api
from plone.app.multilingual.api import get_translation_manager

path = '/Plone/en/module/document'
document1 = api.content.get(path=path)
current_language = api.portal.get_current_language()

if document1 is not None:
    manager = get_translation_manager(document1)
    if manager is not None:
        translation = manager.get_translation(current_language)

2 Likes

Thanks it worked :slight_smile: