Skip to content

Instantly share code, notes, and snippets.

@jmsole
Created April 27, 2026 10:48
Show Gist options
  • Select an option

  • Save jmsole/5174c2ff2c4c924c494cf64febd4c62d to your computer and use it in GitHub Desktop.

Select an option

Save jmsole/5174c2ff2c4c924c494cf64febd4c62d to your computer and use it in GitHub Desktop.
Use Hyperglot to list languages supported by a single font
"""
Use Hyperglot to list languages supported by a single font.
Outputs one line per language as:
iso - Language Name
With validity set to 'preliminary' this includes stricter levels as well
(i.e. also 'verified', matching Hyperglot CLI threshold semantics).
"""
from hyperglot.checker import FontChecker
from hyperglot import LanguageValidity
import click
from langcodes import Language
@click.command()
@click.argument("font", type=click.Path(file_okay=True, dir_okay=False))
def main(font):
"""Print languages supported by FONT filtered to preliminary validity."""
# Query Hyperglot for supported languages, grouped by script, returning Language objects
support_by_script = FontChecker(font).get_supported_languages(
validity=LanguageValidity.PRELIMINARY.value
)
# Flatten to unique languages by ISO; since validity is set to PRELIMINARY
# in the call above, this already includes both 'preliminary' and 'verified'.
languages = {}
for script, iso_map in support_by_script.items():
for iso, lang in iso_map.items():
languages[iso] = lang
# Print total unique language count first (union across scripts)
print("Supported languages: " + str(len(languages)))
# Print languages grouped by script
for script in sorted(support_by_script.keys()):
iso_map = support_by_script[script]
if not iso_map:
continue
print(f"\n{script} ({len(iso_map)}):")
for iso in sorted(iso_map.keys()):
lang = iso_map[iso]
name = getattr(lang, "name", str(lang))
# Normalize language tag to BCP 47 (e.g., 'eng' -> 'en')
try:
tag = Language.get(iso).prefer_macrolanguage().to_tag()
except Exception:
tag = iso
print(f"{tag} - {name}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment