Troubleshooting
I18n package issues and fixes.
Translation Not Working
Translations not loading
Problem: Text shows English despite having .mo files.
Cause: Translation files not loaded or wrong path.
Fix: Verify load path and timing:
// Load in init, not too early
$hooks->wpAction('init', function () use ($context) {
load_plugin_textdomain(
$context->textDomain(),
false,
dirname(plugin_basename($context->file())) . '/languages'
);
});
Text domain mismatch
Problem: Translator uses wrong text domain.
Cause: Context has different textDomain than .mo files.
Fix: Ensure .mo filename matches context textDomain:
$context = PluginContext::create([
'textDomain' => 'my-plugin', // Must match .mo filename
]);
// File should be: languages/my-plugin-de_DE.mo
POT Generation Issues
Strings not extracted
Problem: wp i18n make-pot doesn't find strings.
Cause: Using Translator class instead of WP functions.
Fix: POT generators expect __() format. Either:
- Use placeholder that gets replaced:
// In template (extracted)
__('Hello', 'TEXTDOMAIN_PLACEHOLDER');
- Or maintain a
.potmanually with all strings.
Wrong domain in POT
Problem: POT file has hardcoded domain.
Cause: Generator uses filename or header.
Fix: Set domain in extraction:
wp i18n make-pot . languages/my-plugin.pot --domain=my-plugin
Plural Issues
Wrong plural form
Problem: "1 items" instead of "1 item".
Cause: Using __() instead of _n().
Fix: Use plural function:
// Bad: No plural support
echo $translator->__('1 item');
// Good: Proper plurals
echo $translator->_n('%d item', '%d items', $count);