Overriding plone.app.locales

Hello there,

What is the canonical way (if there is any) of overriding some entries for translations in plone.app.locales?

I have a policy package, with a locales folder, and I tried to add an updated plonelocales.po there, but it seems the version on plone.app.locales always wins.

Ensure your package is loaded in zcml before plone.app.locales:

  1. in your configure.zcml load your policies locales as first: <i18n:registerTranslations directory="locales" />
  2. in buildout.cfg instance eggs and esp. in zcml section your package is the only or at least first one (esp. no Plone/Products.CMFPlone)
  3. try to avoid z3c.autoinlcude features
1 Like

See alternative instructions here:

You can add a locales folder in your buildout folder
There you place po files with same name as the file you want overwrite

1 Like

After doing that, you may need to add the following line in your configure.zcml just after the i18n:registerTranslations directive:

<include package="Products.CMFPlone" />

We were just biten by this.

3 Likes

To override the image type names in TinyMCE image insert dialog I

  • added a locales folder in buildout directory
  • added widgets.po with domain 'widgets' (copy of original widgets.po with msgids removed but the ones we need
  • <include package="Products.CMFPlone" />

No effect. As it is part of the TinyMCE stuff. Do I need to recompile resources? Or what do I miss?

Two things:

  • In a locales dir in buildout you still need the proper structure. I just saw a project with a file locales/plone.po which did not work. In your case for English it would need to be: locales/en/LC_MESSAGES/widgets.po.
  • Since this is TinyMCE, these translations may come from javascript. These translations are cached in the browser for a day, in localStorage. So open the developer tools of your browser, check if widgets-en is in localStorage and remove it.
1 Like

Removing widget-de from LocalStorage helped to see the modified translation. Thank you @maurits!

The suggestion from Maurits worked for me too - except for the content of the Favorites menu in the RelatedItemsFieldWidget:

"Current Content" and "Start Page" are in the plone domain (plone.po), but adding these to my overrides have no effect. (Other overrides in the same .po file does have an effect).
I assume they are also buried deep down in some compiled javascript - any tricks for these ones?

Best,
Sune

you can override this with your widgets directive, see mockup/src/pat/relateditems at master · plone/mockup · GitHub

If needed, you can use a function to return the correct values...

directives.widget(
    'related_image',
    RelatedItemsFieldWidget,
    pattern_options = {
        'recentlyUsed': True,
        'basePath'    : default_base_path,
        'mode'        : 'auto',
        'favorites'   : default_pattern_options,
        'folderTypes': ['Folder', 'LIF', 'LRF'],
        'selectableTypes' : ['Image'],
    }
)

Great! I will try it out. Thank you @mtrebron

Hi!

I'm trying to override a translation of z3c.form in my local package. I've downloaded a copy for z3c.form.po in my local package locales/it/LC_MESSAGES/z3c.form.po, keep the headers, removed all the translations but the one I want to change. I've also this in configure.zcml:

  <i18n:registerTranslations directory="locales" />
  <include package="Products.CMFPlone" />

but I can't see my translation, the z3c.form wins. This is the header:

# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
msgid ""
msgstr ""
"Project-Id-Version: Meaningless\n"
"POT-Creation-Date: Mon Sep 17 15:11:41 2012\n"
"PO-Revision-Date: 2012-11-18 23:26+0001\n"
"Last-Translator: Giorgio Borelli <giorgio@giorgioborelli.it>\n"
"Language-Team: Plone italian translation project <plone-italian-translation-discussion@lists.coactivate.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: zope/app/locales/extract.py\n"
"Plural-Forms: nplurals=2; plural=n!=1\n"
"Language-Code: it\n"
"Language-Name: Italiano\n"
"X-Is-Fallback-For: it-ch it-it\n"
"Language: it\n"

EDIT: I've tested with plone.po and it does not override the translation I've copied.

Try adding <include package="z3c.form" /> in your ZCML before you register your package's translations, to make sure they load in the right order. I'm not sure if this will solve it, but it might.

I forgot to add that I tried it too but didn't worked.

@erral do the overrides works for you in a plain 6.0.13 Plone installation? I tried with buildout.coredev, copying the custom z3c.form in src/plone.app.locales, then adding the zcml = plone.app.locales in buildout.cfg and it worked (no need to add <include package="Products.CMFPlone" /> in configure.zcml). But in a Plone 6.0.13 buildout installation with a custom product, no way.

The order of loading packages in ZCML is important:

Your ZCML needs to be included before the one from plone.app.locales. The first translation of a msgid wins. To manage this, you can include the ZCML in the buildout:

In your case, your translation should be included before z3c.form's.

Have you tried checking that?

It worked. What I was doing wrong is that I had an empty zcml = below in my buildout.cfg, overriding the one with my local product. This was then used in the instance base template. Following the docs carefully lead me to find the problem.

Sorry for the noise, and thanks all for the support.

1 Like

We can say that the documented procedure works in Plone 6?

1 Like

Absolutely yes.

I don't like it much because loading zcml first is about the whole package and not only about translations, and seems a little obscure but works.

1 Like