{"record":{"id":"a6b4608a3c4e01e5","repo":"phalcon/cphalcon","slug":"cannot-find-translation-key-key","errorCode":null,"errorMessage":"Cannot find translation key: {key}","messagePattern":"Cannot find translation key: (.+?)","errorType":"exception","errorClass":"Phalcon\\Translate\\Exceptions\\KeyNotFound","httpStatus":null,"severity":"error","filePath":"phalcon/Translate/Adapter/AbstractAdapter.zep","lineNumber":75,"sourceCode":"    /**\n     * Returns the translation string of the given key (alias of method 't')\n     *\n     * @phpstan-param translate_placeholders $placeholders\n     */\n    public function _(string translateKey, array placeholders = []) -> string\n    {\n        return this->query(translateKey, placeholders);\n    }\n\n    /**\n     * Whenever a key is not found this method will be called\n     *\n     * @throws KeyNotFound\n     */\n    public function notFound( string index) -> string\n    {\n        if unlikely (true === this->triggerError) {\n            throw new KeyNotFound(index);\n        }\n\n        return index;\n    }\n\n    /**\n     * Check whether a translation key exists\n     */\n    public function offsetExists(var offset) -> bool\n    {\n        return this->has(offset);\n    }\n\n    /**\n     * Returns the translation related to the given key\n     *\n     * @param string $offset\n     *","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Translate/Adapter/AbstractAdapter.zep#L57-L93","documentation":"Every Phalcon translate adapter funnels missing keys through AbstractAdapter::notFound(). By default it returns the key string itself; if the adapter was constructed with the option ['triggerError' => true], notFound() instead throws Phalcon\\Translate\\Exceptions\\KeyNotFound with the missing key (phalcon/Translate/Adapter/AbstractAdapter.zep:75). This turns absent dictionary entries into hard failures on query()/t()/_()/offsetGet().","triggerScenarios":"$t->_('missing.key'), $t->t('missing.key'), or $t['missing.key'] on any adapter built with 'triggerError' => true whose dictionary lacks that key.","commonSituations":"Enabling triggerError in production for strictness while a template still references a typo'd or undeclared key; locale files out of sync (key present in en.csv, missing in de.csv); CSV comment rows or wrong delimiter silently dropping keys so lookups miss.","solutions":["Check existence first: if ($t->has('key')) ... or isset($t['key']) before querying.","Add the missing key to the dictionary (NativeArray content, CSV file, or gettext catalog) and keep all locales in sync.","Catch Phalcon\\Translate\\Exceptions\\KeyNotFound at render boundaries when unknown keys are acceptable.","Remove 'triggerError' => true from the adapter options to get the default fallback (key echoed back)."],"exampleFix":"// before\necho $t->_('welcome.back'); // adapter built with triggerError => true\n\n// after\necho $t->has('welcome.back') ? $t->_('welcome.back') : 'Welcome back';","handlingStrategy":"validation","validationCode":"$key = 'welcome.back';\nif (!$t->has($key)) {\n    $logger->notice(\"Missing translation key: {$key} for {$locale}\");\n}\necho $t->has($key) ? $t->_($key) : $fallbackText;","typeGuard":null,"tryCatchPattern":"use Phalcon\\Translate\\Exceptions\\KeyNotFound;\n\ntry {\n    echo $t->_($key);\n} catch (KeyNotFound $e) {\n    echo $fallbackText; // degrade instead of a 500 when triggerError is on\n}","preventionTips":["Only enable 'triggerError' in development; run a key-coverage script comparing template keys against all locale files before release.","Prefer has()/offsetExists() checks when rendering user-visible pages with partial dictionaries.","Keep locale files generated from a single source (CSV/CSV per locale) so keys stay in sync."],"tags":["phalcon","translate","i18n","missing-key","adapter"],"backgroundTag":"missing-translation-key","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}