Skip to content

@@plone_portal_state/language override for mockup translations - #5

Open
petschki wants to merge 3 commits into
codesyntax:masterfrom
petschki:portal-state-override
Open

@@plone_portal_state/language override for mockup translations#5
petschki wants to merge 3 commits into
codesyntax:masterfrom
petschki:portal-state-override

Conversation

@petschki

Copy link
Copy Markdown
Contributor

Just gave this a quick try to fix #3

@petschki

Copy link
Copy Markdown
Contributor Author

@erral @mauritsvanrees

@petschki petschki changed the title POC: plone_portal_state override for mockup translations @@plone_portal_state/language override for mockup translations Jan 23, 2025

@mauritsvanrees mauritsvanrees left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @petschki !
Sorry, I did not have time to review this.

I added two minor comments, but I tested it and it works.

But this patch seems too broad. I don't think I want to get English reported as language everywhere. I am not sure where it could go wrong, but I don't trust it.

Ah, I have an example. The site where I want to use it is https://sfia-online.org. This site has been translated into 13 languages. Let's take this German page:

https://sfia-online.org/de/sfia-8/sfia-8.

This is the SFIA framework version 8. On the left you see "Das aktuelle Framework ist Version 9". So in English: "The current framework is version 9." The link is to the German version: de/sfia-9.
Now locally if I try your branch and am logged in as Manager, the link on the German page points to the English version: en/sfia-9. That is wrong.
This is in custom code, and I could change how this link is calculated, but I expect there are more places where this would be a problem.

So I now make a change in the main_template.pt that I was already customising in this project. In the html tag I make this change:

         tal:attributes="
-          lang lang;
+          lang context/@@editor-language;
         "

And then I define this view:

  <browser:page
      name="editor-language"
      for="*"
      class=".views.EditorLanguage"
      permission="zope.Public"
      />

and the class:

class EditorLanguage(BrowserView):
    def __call__(self):
        try:
            language = get_editor_language(self.request)
            if language:
                return language
        except Exception as e:
            # Some defensive programming here
            logger.error("Admin language force patch failed")
            logger.exception(e)
        return api.content.get_view(
            name="plone_portal_state", context=self.context, request=self.request
        ).language()

That works for me.

This cannot be done in this add-on. Well, I could make a PR to add this view, if someone wants.

Anyway, summary: let's close this PR, as it makes a too large change.

Comment thread .meta.toml
"qa",
"test",
"coverage",
"dependencies",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simply add the two missing dependencies to setup.py: Acquisition and plone.app.layout.
Actually, Acquisition would not be needed if we call super; see my next comment.

Comment on lines +19 to +23
return (
self.request.get("LANGUAGE", None)
or aq_inner(self.context).Language()
or self.default_language()
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just call the super method:

Suggested change
return (
self.request.get("LANGUAGE", None)
or aq_inner(self.context).Language()
or self.default_language()
)
return super().language()

And then we can remove the Acquisition import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Folder contents does not use admin language

2 participants