Last updated: November 26, 2026.
If your PHP application emits UTF-8, explicitly configure gettext to return translations in UTF-8 for the domain the application uses. Querying a fresh domain can return false because it has no explicit codeset override. That result alone does not tell you that a catalog is missing.
<?php
$domain = 'storefront';
$before = bind_textdomain_codeset($domain, null);
if (bind_textdomain_codeset($domain, 'UTF-8') !== 'UTF-8') {
throw new RuntimeException('Could not set the gettext codeset');
}
var_export([
'previous_override' => $before,
'current_override' => bind_textdomain_codeset($domain, null),
]);Separate output encoding from catalog lookup
The codeset decides how gettext returns translated text for one domain. It does not pick the language, locate a message catalog or change the encoding declaration inside a catalog. Set up the locale and catalog directory as you normally would, then use the same domain in the binding and in the translation call. A domain passed explicitly to dgettext() need not be the domain currently selected by textdomain().
Run the diagnostic in a fresh CLI process with the gettext extension enabled. An unset domain can show false on the first lookup and UTF-8 after the assignment. Passing null queries the binding. An explicit encoding sets it. PHP maintains this information per process, so set it in application initialization instead of assuming a worker starts with a blank binding on each request.
Verify with a translated string
The diagnostic checks the configuration. To check delivery, translate a known message with a non-ASCII translation in an installed locale. Confirm that the message is actually translated, that its bytes are valid UTF-8 and that the HTTP response declares UTF-8. If the message returns unchanged, first check the locale, domain and compiled catalog location. If the bytes are valid but the browser displays garbled text, compare the response header with the page encoding before adding another conversion.