Problem creating a new addon localization

I have created localization files for language Khmer(km) for the following custom addon. I have followed all recommended settings for declaration of l18n namespace and marked the strings with '_'.

However the localization strings are not picked up when you request for the translated language Khmer (km).

Using the debug shell I tried to see if the language strings are translated:

>>> site = app.plone
>>> site
<PloneSite at /plone>
>>> translation_service = site.translation_service
>>> translation_service.translate("A Person", domain="popolo.contenttypes", target_language="km")
'A Person'

Wonder if someone could tell me what am I missing?

References

@erral Do you spot anything that I am doing wrong? The documentation on L10N is quite sparse right now.

Hi @arky – does the translation work if you choose a different language? I'm missing some context here: are you creating a new translation or are you trying to add translation capability to your add-on, or both? If both, maybe try to test one before you test both?

I could load other translations such German locale of Plone core and also addons with German, Dutch, Finnish from collective addons. Only the language localization Khmer(km) from my custom addon does not load.

My guess is that 'zope_i18n_compile_mo_files true' is not building and loading the localization strings.

Adding my extended_buildout.cfg for reference:


[sources]

politikus.contenttypes = git https://github.com/Sinar/politikus.contenttypes
popolo.contenttypes = git https://github.com/Sinar/popolo.contenttypes
ocds.contenttypes = git https://github.com/Sinar/ocds.contenttypes
politikus.bods = git https://github.com/Sinar/politikus.bods
politikus.theme = git https://github.com/Sinar/politikus.theme
collective.vocabularies.iso = git https://github.com/Sinar/collective.vocabularies.iso
politikus.extractives = git https://github.com/Sinar/politikus.extractives branch=main
politikus.naturalresource = git https://github.com/Sinar/politikus.naturalresource branch=main
odm.naturalresources = git https://github.com/Sinar/odm.naturalresources branch=main

[buildout]

extends = buildout.cfg 

extensions = mr.developer
always-checkout = force
auto-checkout = *

eggs += 
    eea.facetednavigation
    politikus.contenttypes
    popolo.contenttypes
    politikus.bods
    ocds.contenttypes
    politikus.theme
    plone.app.imagecropping
    politikus.extractives
    odm.naturalresources
    politikus.naturalresource
    collective.vocabularies.iso
    Products.PloneHotfix20210518
    collective.relationhelpers

languages = en km 

environment-vars =
    zope_i18n_compile_mo_files true

    
[versions]
Products.PloneHotfix20210518 = 1.2
eea.faceted.vocabularies = 7.0
eea.facetednavigation = 14.6
eea.jquery = 11.2
plone.app.imagecropping = 2.2.2
plone.app.jquery = 1.11.2
politikus.contenttypes==1.0a1
popolo.contenttypes==1.0a1
collective.dexteritytextindexer = 2.4.0
politikus.theme==1.0a1
collective.themefragments = 2.12
plone.app.themingplugins = 1.1
plone.app.z3cform = 4.0.0a1
collective.relationhelpers = 1.5


parts +=
    i18ndude
   
[i18ndude]
unzip = true
recipe = zc.recipe.egg
eggs = i18ndude  

IIRC the domain of those XML files is always "plone" and "i18n:domain" is ignored. This is especially true for all which is rendered in the toolbar menu using the plone.app.contentmenu template (plone.app.contentmenu/contentmenu.pt at master · plone/plone.app.contentmenu · GitHub).

To solves this you need to add a plone.po with the few entries needed for the values in the types/**.xml

2 Likes

So what worked for me so far is adding 'precompile' step to the buildout to load the custom localizations. There might be simpler way to load locales, if so please let me know.

Also adding a custom 'plone.pot' file to translate the strings in XML files solved the problem of untranslated string in toolbar (Thanks @jensens)

[precompile]
recipe = plone.recipe.precompiler
eggs =
    ${instance:eggs}
    plone.app.locales
compile-mo-files = true

Overall I think plone L10N documentation could be improved to make life easier for anyone who are trying to add new localization to their addons.

Plone Foundation Code of Conduct