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?
ben
December 7, 2023, 5:12pm
2
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.
ben
December 8, 2023, 3:24pm
4
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:
Run yarn translate:pot
Generate es_ES.mo
and es_ES.po
files from radicle.pot
in resources/lang/
Set WordPress language to Spanish
Added to a mu-plugin
called localization.php
:<?php
add_action('after_setup_theme', function () {
load_theme_textdomain('radicle', resource_path('lang/'));
});
Translations working as expected
Thanks, this works great!
1 Like
Hi @ben , can I PR that instruction on the Radicle official docs? It is possible to PR there?