arduino/Arduino · error · RuntimeError

No language code %s

Error message

No language code %s

What it means

canonical_lang raises this RuntimeError when no language in the project's language list has a base code matching the requested one. It indicates the requested language does not exist in the Transifex project.

Source

Thrown at arduino-core/src/processing/app/i18n/python/transifex.py:35

    r.raise_for_status()
    d = r.json()
    self.languages_ = set(lang['code'] for lang in d['available_languages'])

  def canonical_lang(self, lang):
    lang = lang.lower()

    for l in self.languages_:
      if l.lower() == lang:
        return l

    match = []
    for l in self.languages_:
      if l.split('_', 1)[0].lower() == lang:
        match.append(l)
    if len(match) > 1:
      raise RuntimeError('Two or more candidates for %s: %s' % (lang, ' '.join(match)))
    if len(match) == 0:
      raise RuntimeError('No language code %s' % lang)
    return match[0]

  def translation(self, lang):
    r = requests.get(
      'https://www.transifex.com/api/2/project/arduino-ide-15/resource/ide-15/translation/%s/?file' % lang,
      auth=self.auth_
    )
    r.raise_for_status()
    r.encoding = 'utf-8'  # workaround for a Transifex issue.
    return r.text

  def pull(self, lang, fname):
    new = self.translation(lang).encode('utf-8')
    new = map(lambda a: a + '\n', new.split('\n'))
    new = update.read_po(new)

    update.dump(new, fname)

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Check the exact RuntimeError message to see which code was requested and compare with the project's available languages.
  2. Fetch the current language list from the Transifex project API and request only codes present in it.
  3. Fix typos and use the canonical code used by the project (e.g. 'nb' vs 'no').
  4. Guard the call: skip languages not in the project's list instead of letting the script abort.

Example fix

// before
canonical_lang('gr')  # typo, no such code
# after
canonical_lang('el')  # or skip if lang not in project.languages_
Defensive patterns

Strategy: validation

Validate before calling

if not any(l.split('_', 1)[0].lower() == lang for l in project.languages_):
    raise ValueError('language %s not in project' % lang)

Try / catch

try:
    code = tx.canonical_lang(lang)
except RuntimeError:
    print('skipping unavailable language', lang)
    return

Prevention

When it happens

Trigger: Calling canonical_lang(lang) with a code (after lowercasing and splitting on '_') that matches none of self.languages_, e.g. 'de' when the project only has 'en', 'it', etc.

Common situations: Typo in the language code; requesting a language the project never had; project language list fetched before new languages were added; case/format mismatches the split('_')[0].lower() normalization does not cover.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06). Data as JSON: /api/errors/7324face19bf4ec8. Report an issue: GitHub.