Using langcodes package, how do I obtain the exact language object from the display name? For example,
langcodes.find("English (United Kingdom)")
returns Language.make(language='en')
instead of returning Language.make(language='en', territory='GB')
which is returned by langcodes.get("en-GB")
I want to use this to check, for example if "English (United Kingdom)"
== en-GB
Sadly, it doesn't look like the package supports that functionality. From the docs: [T]his method currently ignores the parenthetical expressions that come from
.display_name()
. This means thatfind
would not be able to return the territory from expressions like "English (United States)" or "English (United Kingdom)".If you absolutely must use this package, the best option I can see is doing some sort of reverse-engineering of the
Language.display_name
method found here.