{"record":{"id":"0f4833b42bb0eecb","repo":"apache/answer","slug":"i18n-file-parsing-failed-s","errorCode":null,"errorMessage":"i18n file parsing failed: %s","messagePattern":"i18n file parsing failed: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/base/translator/provider.go","lineNumber":121,"sourceCode":"\t\tif err = myTran.AddTranslator(content, file.Name()); err != nil {\n\t\t\tlog.Debugf(\"add translator failed: %s %s\", file.Name(), err)\n\t\t\treportTranslatorFormatError(file.Name(), buf)\n\t\t\tcontinue\n\t\t}\n\t}\n\tGlobalTrans = myTran.GlobalTrans\n\n\ti18nFile, err := os.ReadFile(filepath.Join(c.BundleDir, \"i18n.yaml\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read i18n file failed: %s\", err)\n\t}\n\n\ts := struct {\n\t\tLangOption []*LangOption `yaml:\"language_options\"`\n\t}{}\n\terr = yaml.Unmarshal(i18nFile, &s)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"i18n file parsing failed: %s\", err)\n\t}\n\tLanguageOptions = s.LangOption\n\tfor _, option := range LanguageOptions {\n\t\toption.Label = fmt.Sprintf(\"%s (%d%%)\", option.Label, option.Progress)\n\t}\n\treturn GlobalTrans, err\n}\n\n// CheckLanguageIsValid check user input language is valid\nfunc CheckLanguageIsValid(lang string) bool {\n\tif lang == DefaultLangOption {\n\t\treturn true\n\t}\n\tfor _, option := range LanguageOptions {\n\t\tif option.Value == lang {\n\t\t\treturn true\n\t\t}\n\t}","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/base/translator/provider.go#L103-L139","documentation":"After reading i18n.yaml, NewTranslator unmarshals it to extract language_options; if yaml.Unmarshal fails it returns 'i18n file parsing failed: <err>'. The file exists but is not valid YAML or has an unexpected structure.","triggerScenarios":"i18n.yaml containing syntax errors (bad indentation, tabs, unquoted special chars) or missing/renamed top-level `language_options` key that breaks the expected struct.","commonSituations":"Hand-edited translation manifests, merge conflicts left markers (<<<<<<<) in the yaml, custom translations contributed with wrong schema, or tooling rewriting the file incorrectly.","solutions":["Run the i18n.yaml through a YAML linter/parser to find the syntax error at the reported line.","Restore the original i18n.yaml from the upstream repository and re-apply custom changes carefully.","Ensure the top-level key `language_options` with proper list structure exists.","Check for merge-conflict markers or tabs (YAML forbids tabs for indentation)."],"exampleFix":"// before\nlanguage_options:\n\t- label: English\n// after\nlanguage_options:\n  - label: English\n    value: en-US","handlingStrategy":"try-catch","validationCode":"node -e \"const y=require('js-yaml');y.load(require('fs').readFileSync('i18n.yaml','utf8'));console.log('ok')\"","typeGuard":null,"tryCatchPattern":"tr, err := translator.NewTranslator(cfg)\nif err != nil {\n  if strings.HasPrefix(err.Error(), \"i18n file parsing failed:\") {\n    log.Fatalf(\"i18n.yaml invalid YAML: %v\", err)\n  }\n  return err\n}","preventionTips":["Lint i18n.yaml in CI (yamllint) before packaging","Never use tabs for YAML indentation","Guard custom translations against upstream merges (check for conflict markers)","Keep the language_options schema documented for contributors"],"tags":["i18n","yaml","parsing","go"],"backgroundTag":"yaml-parse-error","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}