{"record":{"id":"4c14caed83a28fb9","repo":"phalcon/cphalcon","slug":"this-class-requires-the-gettext-extension-for-php","errorCode":null,"errorMessage":"This class requires the gettext extension for PHP","messagePattern":"This class requires the gettext extension for PHP","errorType":"exception","errorClass":"Phalcon\\Translate\\Exceptions\\MissingGettextExtension","httpStatus":null,"severity":"error","filePath":"phalcon/Translate/Adapter/Gettext.zep","lineNumber":74,"sourceCode":"     * @var false|string\n     */\n    protected var locale;\n\n    /**\n     * Gettext constructor.\n     *\n     * @phpstan-param translate_gettext_options $options\n     *\n     * @throws Exception\n     * @throws MissingGettextExtension\n     * @throws MissingRequiredParameter\n     */\n    public function __construct(\n        <InterpolatorFactory> interpolator,\n        array options\n    ) {\n        if unlikely !this->phpFunctionExists(\"gettext\") {\n            throw new MissingGettextExtension();\n        }\n\n        parent::__construct(interpolator, options);\n\n        this->prepareOptions(options);\n    }\n\n    /**\n     * Check whether is defined a translation key in the internal array\n     *\n     * @deprecated\n     */\n    public function exists(string index) -> bool\n    {\n        return this->has(index);\n    }\n\n    public function getCategory() -> int","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Translate/Adapter/Gettext.zep#L56-L92","documentation":"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.","triggerScenarios":"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.","commonSituations":"See trigger scenarios.","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."],"exampleFix":"// before\n$t = new Gettext($factory, [...]); // throws MissingGettextExtension\n\n// after\n$t = extension_loaded('gettext')\n    ? new Gettext($factory, [...])\n    : new NativeArray($factory, ['content' => require 'messages/en.php']);","handlingStrategy":"validation","validationCode":"if (!extension_loaded('gettext')) {\n    throw new RuntimeException('ext-gettext is required for the Gettext translate adapter');\n}\n$t = new Gettext($factory, $options);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["phalcon","translate","gettext","php-extension","environment","i18n"],"backgroundTag":"missing-php-extension","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}