Translations not working

I’m working on a small project where the default locale is Dutch (nl_NL).

I’ve created the corresponding nl_NL.mo and nl_NL.po files from the POT file inside the resources/languages folder. The locale is set to Dutch inside Wordpress.

But the translations are not loaded. Do I need additional configuration for this to work?

I think you also need to call the load_theme_textdomain function, try throwing this somewhere in your codebase?

add_action('after_setup_theme', function () {
    load_theme_textdomain('radicle', resource_path('languages/'));
});

It looks likes this works for the Sage theme. But the language files in Radicale are located in the root. I’ve tried:

add_action('after_setup_theme', function () {
    load_theme_textdomain('radicle', 'resources/languages');
});

and

add_action('after_setup_theme', function () {
    load_theme_textdomain('radicle', ABSPATH . '/resources/languages');
});

But without any luck.

You’re right, that’s my bad — it would be resource_path('languages/')

FWIW, the translate scripts that ship with Radicle are configured for the resources/lang/ directory

I went to test locally with translations for European Spanish (es_ES) and followed these steps:

  1. Run yarn translate:pot
  2. Generate es_ES.mo and es_ES.po files from radicle.pot in resources/lang/
  3. Set WordPress language to Spanish
  4. Added to a mu-plugin called localization.php:
    <?php
    
    add_action('after_setup_theme', function () {
        load_theme_textdomain('radicle', resource_path('lang/'));
    });
    
  5. Translations working as expected :white_check_mark:

Thanks, this works great!

1 Like

Hi @ben, can I PR that instruction on the Radicle official docs? It is possible to PR there?