{"record":{"id":"2ed04d68bde5350a","repo":"Humanizr/Humanizer","slug":"locale-declaredlocale-must-match-file-locale","errorCode":null,"errorMessage":"Locale '{declaredLocale}' must match file locale '{localeCode}'.","messagePattern":"Locale '(.+?)' must match file locale '(.+?)'\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Humanizer.SourceGenerators/Common/CanonicalLocaleAuthoring.cs","lineNumber":83,"sourceCode":"\n        internal static CanonicalLocaleDocument Parse(string localeCode, string fileText)\n        {\n            var root = SimpleYamlParser.Parse(fileText);\n\n            foreach (var property in root.Values.Keys.Where(static property => !SupportedTopLevelNames.Contains(property, StringComparer.Ordinal)))\n            {\n                throw new InvalidOperationException(\n                    $\"Locale '{localeCode}' defines unsupported top-level property '{property}'. \" +\n                    $\"Supported properties: {string.Join(\", \", SupportedTopLevelNames)}.\");\n            }\n\n            var declaredLocale = root.GetScalar(\"locale\")\n                ?? throw new InvalidOperationException(\n                    $\"Locale '{localeCode}' must define required top-level property 'locale'.\");\n\n            if (!string.Equals(localeCode, declaredLocale, StringComparison.Ordinal))\n            {\n                throw new InvalidOperationException(\n                    $\"Locale '{declaredLocale}' must match file locale '{localeCode}'.\");\n            }\n\n            var variantOf = root.GetScalar(\"variantOf\");\n\n            SimpleYamlMapping surfaces;\n            if (!root.TryGetValue(\"surfaces\", out var surfacesValue))\n            {\n                if (string.IsNullOrWhiteSpace(variantOf))\n                {\n                    throw new InvalidOperationException(\n                        $\"Locale '{localeCode}' must define required top-level property 'surfaces'.\");\n                }\n\n                surfaces = new SimpleYamlMapping(\n                    ImmutableDictionary<string, SimpleYamlValue>.Empty.WithComparers(StringComparer.Ordinal));\n            }\n            else","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer.SourceGenerators/Common/CanonicalLocaleAuthoring.cs#L65-L101","documentation":"The value of `locale:` must equal the locale code the generator associates with the file (CanonicalLocaleAuthoring.cs:81-85), which is derived from the filename/registry. A mismatch would silently bind the wrong culture, so the generator fails fast.","triggerScenarios":"Copying fr.yml to fr-CA.yml but leaving `locale: \"fr\"`; renaming a file without updating the scalar; casing differences (en-gb vs en-GB) since the comparison is ordinal.","commonSituations":"Creating a regional variant by duplicating a base locale; locale code renamed in CI but YAML not updated.","solutions":["Set `locale:` to exactly the filename's locale code.","Match case and separators (use the same BCP-47 form as the filename).","Re-run the build to confirm the values agree."],"exampleFix":"# file: src/Humanizer/Locales/fr-CA.yml\n# before\nlocale: \"fr\"\n# after\nlocale: \"fr-CA\"","handlingStrategy":"validation","validationCode":"import os, sys, yaml\npath = sys.argv[1]\nexpected = os.path.splitext(os.path.basename(path))[0]\ndoc = yaml.safe_load(open(path, encoding='utf-8'))\nassert doc.get('locale') == expected, f\"locale: must be {expected}, got {doc.get('locale')!r}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Author locales against the canonical schema; the error message lists the exact allowed names.","Run `dotnet build src/Humanizer/Humanizer.csproj` locally so the generator reports locale errors before push.","Copy an existing compliant locale file as your template rather than writing YAML from scratch."],"tags":["locale-authoring","yaml","source-generator","build","localization"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}