{"record":{"id":"12ec2c63e8c9da46","repo":"languagetool-org/languagetool","slug":"not-supported-fromlang-tolang","errorCode":null,"errorMessage":"Not supported: \" + fromLang + \" -> \" + toLang","messagePattern":"Not supported: \" \\+ fromLang \\+ \" -> \" \\+ toLang","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-language-modules/en/src/main/java/org/languagetool/rules/en/translation/BeoLingusTranslator.java","lineNumber":183,"sourceCode":"        mergedList.add(item);\n        merging = true;\n      } else {\n        mergedList.add(item);\n      }\n      mergeListPos++;\n    }\n    return mergedList;\n  }\n\n  @Override\n  public List<TranslationEntry> translate(String term, String fromLang, String toLang) {\n    Map<String, List<TranslationEntry>> map;\n    if (fromLang.equals(\"de\") && toLang.equals(\"en\")) {\n      map = this.de2en;\n    } else if (fromLang.equals(\"en\") && toLang.equals(\"de\")) {\n      map = this.en2de;\n    } else {\n      throw new RuntimeException(\"Not supported: \" + fromLang + \" -> \" + toLang);\n    }\n    List<TranslationEntry> entries = map.get(term.toLowerCase());\n    Set<TranslationEntry> entriesSet = new HashSet<>();\n    if (entries != null) {\n      entriesSet.addAll(entries);\n    }\n    List<TranslationEntry> translationsForBaseforms = getTranslationsForBaseforms(term, map);\n    for (TranslationEntry trans : translationsForBaseforms) {\n      if (entries != null) {\n        Optional<TranslationEntry> first = entries.stream().filter(k -> k.getL1().equals(trans.getL1())).findFirst();\n        if (first.isPresent() && first.get().getL1().equals(trans.getL1())) {\n          // skip duplicates\n        } else {\n          entriesSet.add(trans);\n        }\n      } else {\n        entriesSet.add(trans);\n      }","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-language-modules/en/src/main/java/org/languagetool/rules/en/translation/BeoLingusTranslator.java#L165-L201","documentation":"BeoLingusTranslator.translate only supports German->English and English->German lookups against its two in-memory maps. Any other language pair passed in fromLang/toLang throws a RuntimeException naming the unsupported direction.","triggerScenarios":"Calling translate(term, \"fr\", \"en\") or any language pair other than (\"de\",\"en\") and (\"en\",\"de\") on a BeoLingusTranslator instance.","commonSituations":"Reusing the translator in code that handles multiple language pairs; passing language codes in the wrong case or wrong variable; assuming the class supports the file's other translation directions (en2de is loaded but noted as not populated).","solutions":["Only call translate with fromLang/toLang equal to \"de\"->\"en\" or \"en\"->\"de\".","Validate the language pair before calling and route other pairs to a different translation component.","If another direction is required, extend the translator to populate and consult an additional map."],"exampleFix":"// before\ntranslator.translate(term, \"fr\", \"en\");\n// after\nif (fromLang.equals(\"de\") && toLang.equals(\"en\")) {\n  translator.translate(term, \"de\", \"en\");\n}","handlingStrategy":"validation","validationCode":"Set<List<String>> supported = Set.of(List.of(\"de\",\"en\"), List.of(\"en\",\"de\"));\nif (!supported.contains(List.of(fromLang, toLang))) {\n  throw new UnsupportedOperationException(\"Pair not supported: \" + fromLang + \"->\" + toLang);\n}","typeGuard":null,"tryCatchPattern":"try {\n  translator.translate(term, fromLang, toLang);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Not supported:\")) { /* fall back to another translator */ }\n}","preventionTips":["Only use BeoLingusTranslator for de<->en pairs","Centralize language-pair routing before calling translate","Check direction support before adding the translator to a pipeline"],"tags":["languagetool","translation","unsupported-operation","language-pair"],"backgroundTag":"unsupported-operation","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}