{"record":{"id":"bd722046eabd5091","repo":"kataras/iris","slug":"locales-expected-to-be-d-but-d-parsed","errorCode":null,"errorMessage":"locales expected to be %d but %d parsed","messagePattern":"locales expected to be (.+?) but (.+?) parsed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"i18n/loader.go","lineNumber":133,"sourceCode":"\n\t\tfor _, langIndex := range languageIndexes {\n\t\t\tif langIndex == -1 {\n\t\t\t\t// If loader has more languages than defined for use in New function,\n\t\t\t\t// e.g. when New(KV(m), \"en-US\") contains el-GR and en-US but only \"en-US\" passed.\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tkv := keyValuesMulti[langIndex]\n\t\t\terr := cat.Store(langIndex, kv)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\n\t\tif n := len(cat.Locales); n == 0 {\n\t\t\treturn nil, fmt.Errorf(\"locales not found in map\")\n\t\t} else if options.Strict && n < len(m.Languages) {\n\t\t\treturn nil, fmt.Errorf(\"locales expected to be %d but %d parsed\", len(m.Languages), n)\n\t\t}\n\n\t\treturn cat, nil\n\t}\n}\n\n// DefaultLoaderConfig represents the default loader configuration.\nvar DefaultLoaderConfig = LoaderConfig{\n\tLeft:               \"{{\",\n\tRight:              \"}}\",\n\tStrict:             false,\n\tDefaultMessageFunc: nil,\n\tPluralFormDecoder:  internal.DefaultPluralFormDecoder,\n\tFuncs:              nil,\n}\n\n// load accepts a list of filenames (physical or virtual),\n// a function that should return the contents of a specific file","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/i18n/loader.go#L115-L151","documentation":"With LoaderConfig.Strict enabled, the KV loader requires that the number of parsed locales equals the number of languages registered in the Matcher. If fewer locales were stored than m.Languages, it returns \"locales expected to be %d but %d parsed\". It's a completeness check on translations.","triggerScenarios":"Loading with LoaderConfig{Strict: true} via i18n.KV while the langMap covers fewer languages than were registered (e.g. New(KV(m), \"en-US\", \"el-GR\") but the map only contains \"en-US\"), or some map keys failed to parse to a registered language (index -1 skipped).","commonSituations":"Gradually adding translations: new language registered in New but its translations not yet added to the map; Strict enabled for CI to enforce complete translations.","solutions":["Add translation entries for every registered language in the LangMap.","Pass only the languages you actually have translations for to New.","Disable Strict (LoaderConfig{Strict: false}) if partial coverage is intentional.","Check parseLanguageName behavior: ensure map keys parse to registered language tags."],"exampleFix":"// before\ni18n.KV(m, i18n.LoaderConfig{Strict: true}) // m missing el-GR\n// after\nm[\"el-GR\"] = map[string]any{\"hello\": \"Γειά\"} // add missing locale","handlingStrategy":"validation","validationCode":"// check coverage before strict load\nregistered := []string{\"en-US\", \"el-GR\"}\nfor _, lang := range registered {\n    if _, ok := langMap[lang]; !ok {\n        return fmt.Errorf(\"strict mode: missing translations for %s\", lang)\n    }\n}","typeGuard":null,"tryCatchPattern":"localizer, err := loader(matcher)\nif err != nil && strings.Contains(err.Error(), \"locales expected to be\") {\n    return fmt.Errorf(\"incomplete translations: %w\", err) // or log and continue non-strict\n}","preventionTips":["Keep Strict: true in CI but false locally if partial translation is acceptable.","Add a language the moment its translations exist, not before.","Track translation coverage per locale in your build pipeline.","Use one source-of-truth list of supported languages shared by New and the map."],"tags":["i18n","go","loader","strict"],"backgroundTag":"incomplete-translations","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}