{"record":{"id":"ea4b163a36e5a8d0","repo":"twigphp/Twig","slug":"locale-s-is-not-supported","errorCode":null,"errorMessage":"Locale \"%s\" is not supported.","messagePattern":"Locale \"(.+?)\" is not supported\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"extra/string-extra/StringExtension.php","lineNumber":96,"sourceCode":"\n        return $this->getInflector($locale)->singularize($value)[0];\n    }\n\n    private function getInflector(string $locale): InflectorInterface\n    {\n        switch ($locale) {\n            case 'en':\n                return $this->englishInflector ?? $this->englishInflector = new EnglishInflector();\n            case 'es':\n                if (!class_exists(SpanishInflector::class)) {\n                    throw new RuntimeError('SpanishInflector is not available.');\n                }\n\n                return $this->spanishInflector ?? $this->spanishInflector = new SpanishInflector();\n            case 'fr':\n                return $this->frenchInflector ?? $this->frenchInflector = new FrenchInflector();\n            default:\n                throw new \\InvalidArgumentException(\\sprintf('Locale \"%s\" is not supported.', $locale));\n        }\n    }\n}\n","sourceCodeStart":78,"sourceCodeEnd":100,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/string-extra/StringExtension.php#L78-L100","documentation":"StringExtension::getInflector() maps a locale to a doctrine/inflector implementation (English, Spanish, French, ...). When the locale has no case in its switch, it throws an InvalidArgumentException. The plural/singular filters accept a locale argument, and only a fixed set of languages is supported.","triggerScenarios":"Calling the plural or singular Twig filters with an unsupported locale argument, e.g. {{ 'cats'|plural('de') }} or {{ 'chats'|singular('it') }}, where 'de'/'it' are not handled by getInflector's switch.","commonSituations":"Passing the app's locale straight into the filter (apps commonly run de_DE, it_IT, pt_BR); locale strings like 'pt_BR' or with charset suffix 'fr_FR.UTF-8' that don't match bare case labels like 'fr'; assuming all ICU locales are supported.","solutions":["Use a supported locale: 'en', 'es', 'fr' (check the extension's switch for the exact set).","Normalize the locale to its primary subtag and default to 'en' when unsupported, e.g. explode('_', $locale)[0] with a fallback.","For other languages, subclass StringExtension and override getInflector() to plug in your own doctrine/inflector rules."],"exampleFix":"// before\n{{ word|plural(app.request.locale) }}  {# locale = \"de_DE\" #}\n// after\n{% set loc = app.request.locale|split('_')[0] %}\n{{ word|plural(loc in ['en','es','fr'] ? loc : 'en') }}","handlingStrategy":"validation","validationCode":"$supported = ['en', 'es', 'fr'];\n$loc = explode('_', $locale)[0];\nif (!in_array($loc, $supported, true)) {\n    $loc = 'en'; // or skip the filter\n}","typeGuard":null,"tryCatchPattern":"try {\n    $out = $twig->render($tpl, ['word' => $word, 'locale' => $loc]);\n} catch (\\InvalidArgumentException $e) {\n    // unsupported locale; fall back to default inflection\n}","preventionTips":["Never pass raw BCP47/POSIX locale strings (de_DE, fr_FR.UTF-8) into plural/singular; normalize to the primary subtag first.","Whitelist locales in application code before using inflection filters.","If you need other languages, extend StringExtension and override getInflector() with custom doctrine/inflector rules."],"tags":["php","twig","i18n","locale","invalid-argument"],"backgroundTag":"unsupported-enum-value","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}