plone / Products.CMFPlone

The core of the Plone content management system
https://plone.org
GNU General Public License v2.0
257 stars 193 forks source link

Write better i18n code on login_help.py #2875

Open dbitouze opened 5 years ago

dbitouze commented 5 years ago

In the lines:

https://github.com/plone/Products.CMFPlone/blob/cfa56163281a965c46eebea1ab25951b786fc0cc/Products/CMFPlone/browser/login/login_help.py#L28-L44

aren't missing $ in front of all the {...} variables, e.g. shouldn't Your username for {portal_url} be Your username for ${portal_url}?

vincentfretin commented 5 years ago

Currently the code to send the email is

          translated_template = translate(
              SEND_USERNAME_TEMPLATE,
              context=self.request,
          )

          mail_text = translated_template.format(
              email=userinfo['email'],
              portal_url=portal.absolute_url(),
              fullname=userinfo['title'],
              login=userinfo['login'],
              email_from_name=registry['plone.email_from_name'],
              encoded_mail_sender=self.encoded_mail_sender(),
          )

So the message is translated and then those variables are replaced with .format. This works because those variables doesn't need to be translated but it's not the proper way to internalize messages. The message should indeed use the ${var} syntax and the python code should be:

translated_template = translate(
              SEND_USERNAME_TEMPLATE,
              context=self.request,
              mapping={
                  'email': userinfo['email'],
                  'portal_url': portal.absolute_url(),
                  'fullname': userinfo['title'],
                  'login': userinfo['login'],
                  'email_from_name': registry['plone.email_from_name'],
                  'encoded_mail_sender': self.encoded_mail_sender(),
})

Somebody can propose a PR for Products.CMFPlone and another for plone.app.locales to update all translations to use dollar variables to avoid fuzzy messages. I'm pretty sure nobody will do the changes... so I close the issue, feel free to reopen if somebody want to work on it.

dbitouze commented 5 years ago

Why closing this issue before it is fixed? If somebody wants to work on it, at least (s)he will need to be aware of it :)

vincentfretin commented 5 years ago

Sure if you want, I reopen. I changed the title.