phalcon/cphalcon · error · Phalcon\Translate\Exceptions\MissingGettextExtension
This class requires the gettext extension for PHP
Error message
This class requires the gettext extension for PHP
What it means
The Gettext adapter proxies to PHP's gettext functions; its constructor first checks function_exists('gettext') and throws Phalcon\Translate\Exceptions\MissingGettextExtension when ext-gettext is not loaded (phalcon/Translate/Adapter/Gettext.zep:74). The check runs before any option validation, so it fires even with valid options.
Source
Thrown at phalcon/Translate/Adapter/Gettext.zep:74
* @var false|string
*/
protected var locale;
/**
* Gettext constructor.
*
* @phpstan-param translate_gettext_options $options
*
* @throws Exception
* @throws MissingGettextExtension
* @throws MissingRequiredParameter
*/
public function __construct(
<InterpolatorFactory> interpolator,
array options
) {
if unlikely !this->phpFunctionExists("gettext") {
throw new MissingGettextExtension();
}
parent::__construct(interpolator, options);
this->prepareOptions(options);
}
/**
* Check whether is defined a translation key in the internal array
*
* @deprecated
*/
public function exists(string index) -> bool
{
return this->has(index);
}
public function getCategory() -> intView on GitHub (pinned to b7419de9cd)
Solutions
- Install and enable ext-gettext (apt install php-gettext / docker-php-ext-install gettext / enable php_gettext.dll), restart FPM and CLI, verify with extension_loaded('gettext').
- If the extension cannot be installed, use the NativeArray or Csv adapter instead.
- Guard adapter selection: if (!extension_loaded('gettext')) fall back to a non-gettext adapter for that environment.
Example fix
// before
$t = new Gettext($factory, [...]); // throws MissingGettextExtension
// after
$t = extension_loaded('gettext')
? new Gettext($factory, [...])
: new NativeArray($factory, ['content' => require 'messages/en.php']); Defensive patterns
Strategy: validation
Validate before calling
if (!extension_loaded('gettext')) {
throw new RuntimeException('ext-gettext is required for the Gettext translate adapter');
}
$t = new Gettext($factory, $options); Prevention
- Add a composer requirement (ext-gettext) or a bootstrap extension check so environments fail loudly and early.
- Verify all environments (dev, CI, prod images) with php -m | grep gettext.
- Provide a NativeArray/Csv fallback for environments where the extension cannot be installed.
When it happens
Trigger: new Gettext($interpolatorFactory, [...]) on a PHP build compiled without ext-gettext: Alpine images, distro minimal-cli packages, many shared hosts, default Windows builds, or where the extension is installed but not enabled in the SAPI in use.
Common situations: See trigger scenarios.
Related errors
- Parameter 'locale' is required
- Parameter 'directory' is required
- Yaml extension is not loaded
- This class requires the openssl extension for PHP
- YamlLoader requires the "yaml" PHP extension (pecl/yaml)
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/4c14caed83a28fb9.
Report an issue: GitHub.