{"record":{"id":"ef21dab61cbbebae","repo":"arduino/Arduino","slug":"two-or-more-candidates-for-s-s","errorCode":null,"errorMessage":"Two or more candidates for %s: %s","messagePattern":"Two or more candidates for (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"arduino-core/src/processing/app/i18n/python/transifex.py","lineNumber":33,"sourceCode":"      auth=self.auth_\n    )\n    r.raise_for_status()\n    d = r.json()\n    self.languages_ = set(lang['code'] for lang in d['available_languages'])\n\n  def canonical_lang(self, lang):\n    lang = lang.lower()\n\n    for l in self.languages_:\n      if l.lower() == lang:\n        return l\n\n    match = []\n    for l in self.languages_:\n      if l.split('_', 1)[0].lower() == lang:\n        match.append(l)\n    if len(match) > 1:\n      raise RuntimeError('Two or more candidates for %s: %s' % (lang, ' '.join(match)))\n    if len(match) == 0:\n      raise RuntimeError('No language code %s' % lang)\n    return match[0]\n\n  def translation(self, lang):\n    r = requests.get(\n      'https://www.transifex.com/api/2/project/arduino-ide-15/resource/ide-15/translation/%s/?file' % lang,\n      auth=self.auth_\n    )\n    r.raise_for_status()\n    r.encoding = 'utf-8'  # workaround for a Transifex issue.\n    return r.text\n\n  def pull(self, lang, fname):\n    new = self.translation(lang).encode('utf-8')\n    new = map(lambda a: a + '\\n', new.split('\\n'))\n    new = update.read_po(new)\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/processing/app/i18n/python/transifex.py#L15-L51","documentation":"canonical_lang maps a base language code (e.g. 'en') to an exact entry in the Transifex project language list. If more than one entry shares the same base prefix before '_', the mapping is ambiguous and a RuntimeError is raised listing all candidates.","triggerScenarios":"Calling canonical_lang(lang) when self.languages_ contains two or more codes with the same base, e.g. ['pt_BR', 'pt_PT'] and lang='pt'; also 'zh_CN'/'zh_TW' with 'zh'.","commonSituations":"Projects containing multiple regional variants of the same language (pt_BR/pt_PT, zh_CN/zh_TW, es_ES/es_MX); automation scripts that resolve base codes for all project languages.","solutions":["Request the full language code including the region (e.g. 'pt_BR') so the split('_')[0] prefix still matches but you disambiguate after via exact match or explicit choice.","Inspect the RuntimeError message to see the candidates and pick one explicitly in your script.","Adjust the project's language list in Transifex to avoid duplicate base codes, or filter self.languages_ before calling.","Prefer a candidate deterministically (e.g. sorted(match)[0]) only if arbitrary choice is acceptable."],"exampleFix":"// before\ncanonical_lang('pt')  # ambiguous: pt_BR vs pt_PT\n# after\ncanonical_lang('pt_BR')","handlingStrategy":"validation","validationCode":"candidates = [l for l in project.languages_ if l.split('_', 1)[0].lower() == lang]\nif len(candidates) != 1:\n    raise ValueError('ambiguous or missing language: %s -> %r' % (lang, candidates))","typeGuard":null,"tryCatchPattern":"try:\n    code = tx.canonical_lang(lang)\nexcept RuntimeError as e:\n    code = sorted_candidates[0]  # or skip language","preventionTips":["Always request full locale codes (pt_BR not pt)","Check the project language list before resolving","Keep Transifex project free of duplicate base codes"],"tags":["python","i18n","transifex","localization"],"backgroundTag":"ambiguous-identifier","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}