{"record":{"id":"790ab1768adcf570","repo":"doctrine/inflector","slug":"language-s-is-not-supported","errorCode":null,"errorMessage":"Language \"%s\" is not supported.","messagePattern":"Language \"(.+?)\" is not supported\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/InflectorFactory.php","lineNumber":54,"sourceCode":"                return new French\\InflectorFactory();\n\n            case Language::ITALIAN:\n                return new Italian\\InflectorFactory();\n\n            case Language::NORWEGIAN_BOKMAL:\n                return new NorwegianBokmal\\InflectorFactory();\n\n            case Language::PORTUGUESE:\n                return new Portuguese\\InflectorFactory();\n\n            case Language::SPANISH:\n                return new Spanish\\InflectorFactory();\n\n            case Language::TURKISH:\n                return new Turkish\\InflectorFactory();\n\n            default:\n                throw new InvalidArgumentException(sprintf(\n                    'Language \"%s\" is not supported.',\n                    $language\n                ));\n        }\n    }\n}\n","sourceCodeStart":36,"sourceCodeEnd":61,"githubUrl":"https://github.com/doctrine/inflector/blob/288d99b85cac099b2db56b52a9bf62652ff66f61/src/InflectorFactory.php#L36-L61","documentation":"InflectorFactory::createForLanguage() (src/InflectorFactory.php:26) accepts only the exact lowercase constants defined in Doctrine\\Inflector\\Language: 'english', 'esperanto', 'french', 'italian', 'norwegian-bokmal', 'portuguese', 'spanish', 'turkish'. Any other string falls through the switch to the default arm and throws InvalidArgumentException (src/InflectorFactory.php:53). The error is a strict allow-list mismatch: different casing, locale codes, and unsupported languages are all rejected.","triggerScenarios":"Calling InflectorFactory::createForLanguage($language) with a string that is not byte-for-byte a Language constant: 'English' (wrong case), 'en' or 'en_US' (locale code, not a language name), 'norwegian' (the constant is 'norwegian-bokmal'), 'german'/'russian' (no rules package shipped), or a raw value from .env/YAML/API input passed through without mapping.","commonSituations":"Language configured via .env or a framework bundle where the developer assumed IETF locale codes ('en', 'pt-BR') work; user-facing APIs that accept a language parameter and forward it verbatim; typos and casing mismatches in hand-written config; migrations from doctrine/inflector 1.x where language handling differed. Usually fails on first call at runtime rather than at configuration load, which is why it surprises people.","solutions":["Pass a Language constant instead of a literal string: InflectorFactory::createForLanguage(Language::ENGLISH).","If the value is dynamic, map it explicitly before the call: 'en' => Language::ENGLISH, 'pt'/'pt-BR' => Language::PORTUGUESE, 'nb' => Language::NORWEGIAN_BOKMAL, and so on.","Whitelist the eight supported constants and validate the setting at boot so a bad value fails fast with a clear configuration error.","If the requested language has no rules package, decide deliberately: fall back to InflectorFactory::create() (English) or reject the request — never forward the raw string."],"exampleFix":"// before\n$inflector = InflectorFactory::createForLanguage('EN')->build(); // throws InvalidArgumentException\n\n// after\nuse Doctrine\\Inflector\\Language;\n\n$inflector = InflectorFactory::createForLanguage(Language::ENGLISH)->build();","handlingStrategy":"validation","validationCode":"use Doctrine\\Inflector\\InflectorFactory;\nuse Doctrine\\Inflector\\Language;\nuse InvalidArgumentException;\n\n$supported = [\n    Language::ENGLISH,\n    Language::ESPERANTO,\n    Language::FRENCH,\n    Language::ITALIAN,\n    Language::NORWEGIAN_BOKMAL,\n    Language::PORTUGUESE,\n    Language::SPANISH,\n    Language::TURKISH,\n];\n\n$language = strtolower(trim($configLanguage));\n\nif (! in_array($language, $supported, true)) {\n    throw new InvalidArgumentException('Unsupported inflector language: ' . $configLanguage);\n}\n\n$inflector = InflectorFactory::createForLanguage($language)->build();","typeGuard":"use Doctrine\\Inflector\\Language;\n\nfunction isSupportedInflectorLanguage(string $language): bool\n{\n    static $supported = [\n        Language::ENGLISH,\n        Language::ESPERANTO,\n        Language::FRENCH,\n        Language::ITALIAN,\n        Language::NORWEGIAN_BOKMAL,\n        Language::PORTUGUESE,\n        Language::SPANISH,\n        Language::TURKISH,\n    ];\n\n    return in_array($language, $supported, true);\n}","tryCatchPattern":"use Doctrine\\Inflector\\InflectorFactory;\nuse InvalidArgumentException;\n\ntry {\n    $inflector = InflectorFactory::createForLanguage($language)->build();\n} catch (InvalidArgumentException $e) {\n    // deliberate fallback: English rules instead of a hard failure\n    $inflector = InflectorFactory::create()->build();\n}","preventionTips":["Reference Language::* constants instead of hand-typed strings.","Map user-supplied locale codes (en, pt-BR, nb) to supported constants at the edge of the application.","Validate the language setting when configuration loads so failures surface at boot, not at first use.","Keep the locale-to-language mapping in one place and test it whenever you add a language."],"tags":["php","inflector","configuration","language","factory"],"backgroundTag":"unsupported-language-code","analyzedSha":"288d99b85cac099b2db56b52a9bf62652ff66f61","analyzedAt":"2026-08-21T02:11:51.985Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}