{"record":{"id":"5386069d960fa276","repo":"twigphp/Twig","slug":"spanishinflector-is-not-available","errorCode":null,"errorMessage":"SpanishInflector is not available.","messagePattern":"SpanishInflector is not available\\.","errorType":"exception","errorClass":"Twig\\Error\\RuntimeError","httpStatus":null,"severity":"error","filePath":"extra/string-extra/StringExtension.php","lineNumber":89,"sourceCode":"     * @return array|string\n     */\n    public function singular(string $value, string $locale = 'en', bool $all = false)\n    {\n        if ($all) {\n            return $this->getInflector($locale)->singularize($value);\n        }\n\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":71,"sourceCodeEnd":100,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/string-extra/StringExtension.php#L71-L100","documentation":"StringExtension's plural()/singular() inflects strings using a locale-specific inflector. For Spanish it relies on Symfony's SpanishInflector, which only exists when symfony/string is installed with adequate PHP/polyfill support. The extension guards with class_exists() and throws this RuntimeError when the class is missing, so the user knows to install the required package instead of getting a fatal class-not-found.","triggerScenarios":"Calling StringExtension's plural($word, 'es') or singular($word, 'es') when class_exists(SpanishInflector::class) is false — i.e. symfony/string (or its polyfill providing SpanishInflector) is not installed.","commonSituations":"Projects that installed twig/string-extra without symfony/string satisfying the version constraint; deployments where composer dependencies were pruned or --no-dev removed transitive packages; older symfony/string versions that lacked SpanishInflector (it requires a sufficiently recent symfony/string / symfony/polyfill-php85-backed build).","solutions":["Run composer require symfony/string to install/upgrade the package providing SpanishInflector.","Run composer update symfony/string to move to a version that includes SpanishInflector.","Use locale 'en' or 'fr' instead of 'es' if Spanish inflection is not required.","Wrap the plural()/singular() call in try/catch (RuntimeError) and fall back to the uninflected word."],"exampleFix":"// before (composer.json missing the dependency)\n$ composer show symfony/string # not installed\n// after\n$ composer require symfony/string","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["php","twig","dependency","inflector"],"backgroundTag":"missing-dependency","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"}