apache/answer · error
i18n file parsing failed: %s
Error message
i18n file parsing failed: %s
What it means
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.
Source
Thrown at internal/base/translator/provider.go:121
if err = myTran.AddTranslator(content, file.Name()); err != nil {
log.Debugf("add translator failed: %s %s", file.Name(), err)
reportTranslatorFormatError(file.Name(), buf)
continue
}
}
GlobalTrans = myTran.GlobalTrans
i18nFile, err := os.ReadFile(filepath.Join(c.BundleDir, "i18n.yaml"))
if err != nil {
return nil, fmt.Errorf("read i18n file failed: %s", err)
}
s := struct {
LangOption []*LangOption `yaml:"language_options"`
}{}
err = yaml.Unmarshal(i18nFile, &s)
if err != nil {
return nil, fmt.Errorf("i18n file parsing failed: %s", err)
}
LanguageOptions = s.LangOption
for _, option := range LanguageOptions {
option.Label = fmt.Sprintf("%s (%d%%)", option.Label, option.Progress)
}
return GlobalTrans, err
}
// CheckLanguageIsValid check user input language is valid
func CheckLanguageIsValid(lang string) bool {
if lang == DefaultLangOption {
return true
}
for _, option := range LanguageOptions {
if option.Value == lang {
return true
}
}View on GitHub (pinned to 3b9f137061)
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).
Example fix
// before
language_options:
- label: English
// after
language_options:
- label: English
value: en-US Defensive patterns
Strategy: try-catch
Validate before calling
node -e "const y=require('js-yaml');y.load(require('fs').readFileSync('i18n.yaml','utf8'));console.log('ok')" Try / catch
tr, err := translator.NewTranslator(cfg)
if err != nil {
if strings.HasPrefix(err.Error(), "i18n file parsing failed:") {
log.Fatalf("i18n.yaml invalid YAML: %v", err)
}
return err
} Prevention
- 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
When it happens
Trigger: i18n.yaml containing syntax errors (bad indentation, tabs, unquoted special chars) or missing/renamed top-level `language_options` key that breaks the expected struct.
Common situations: Hand-edited translation manifests, merge conflicts left markers (<<<<<<<) in the yaml, custom translations contributed with wrong schema, or tooling rewriting the file incorrectly.
Related errors
- error.password.space_invalid
- read file failed: %s %s
- read i18n file failed: %s
- validate check exception
- base.request_format_error
AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05).
Data as JSON: /api/errors/0f4833b42bb0eecb.
Report an issue: GitHub.