Skip to content

Map languages to the flag of their country - #1559

Merged
frenck merged 1 commit into
mainfrom
frenck/fix-language-flags
Oct 1, 2026
Merged

frenck merged 1 commit into
mainfrom
frenck/fix-language-flags

Conversation

@frenck

@frenck frenck commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Breaking change

Language.favicon now returns a different URL for some languages, and None for languages without one obvious country (like Arabic or Catalan). Those previously returned a wrong flag, see below.

Proposed change

Language.favicon put the ISO 639 language code straight into a flagcdn.com URL, which expects an ISO 3166 country code. For some languages that happens to work (nl, de, fr), others return a 404 (en, ja, zh, el, ko), and a few silently return the wrong flag:

Language Code Flag it returned
Arabic ar Argentina
Swedish sv El Salvador
Serbian sr Suriname
Catalan ca Canada
Nepali ne Niger
Slovenian sl Sierra Leone
Malayalam ml Mali
Bosnian bs Bahamas

Home Assistant uses this as the thumbnail in the media browser.

A new LANGUAGE_FLAGS mapping in const.py links 51 languages to the country they belong to (English to gb). Languages without one obvious country are left out on purpose and get no favicon; no flag beats the wrong one. All mapped flags were checked to exist on flagcdn.com.

Type of change

  • Dependency or tooling upgrade
  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Deprecation (replaces or removes a feature, with a migration path)
  • Breaking change (a fix or feature that changes existing behavior)
  • Code quality, refactor, or test-only change
  • Documentation only

Additional information

  • This PR fixes or closes issue: fixes # None
  • This PR is related to: None
  • Link to a separate documentation pull request: None

Checklist

  • I fully understand the code in this pull request and can explain every line, including any AI-assisted changes.
  • The change is covered by tests, and poetry run pytest passes locally. A pull request cannot be merged unless CI is green.
  • poetry run prek run --all-files passes (lint, format, and type checks).
  • No commented-out or dead code is left in the pull request.

Language.favicon used the language code as a country code. That gave a
404 for English and Japanese, and the wrong flag for others: Arabic got
Argentina, Swedish got El Salvador. Map languages to their country, and
give languages without one obvious country no flag at all.
@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementers. label Oct 1, 2026
@frenck
frenck merged commit b9475bf into main Oct 1, 2026
31 checks passed
@frenck
frenck deleted the frenck/fix-language-flags branch October 1, 2026 08:02
@lumileaf-automation

Copy link
Copy Markdown

Great to see this fixed! Especially the language flag mismatches I noticed with Bosnian (bs 🇧🇸 – Bahamas) and Bashkir (ba 🇧🇦 – Bosnia and Herzegovina).

Thanks, Frenck, for your work on this project. Really appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants