-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add emoji flags to languages #30
Comments
Reference: in Unicode the characters used to display flags are the code point for the capital letter, plus 127397. [source] So >>> chr(ord("G") + 127397) + chr(ord("B") + 127397)
'🇬🇧'
>>> chr(ord("F") + 127397) + chr(ord("R") + 127397)
'🇫🇷' The >>> import ety
>>> fr = ety.Language("fra")
>>> fr.emoji
'🇫🇷' {
"name": "French",
"type": "living",
"scope": "individual",
"iso6393": "fra",
"iso6392B": "fre",
"iso6392T": "fra",
"iso6391": "fr"
} |
Adding 127397 to each code letter is a neat trick (I'd never seen it before!), but there's a bit of a problem here. ISO 3166-1 alpha-2 is for countries, and is the code used for mapping flags. ISO 639 is for languages. It's fine for many, like French, but there are a few which don't have the same code in each ISO. And it's a bit tricky to choose a flag for a language, as some countries use many languages, and some languages are used by many countries. (This is also a problem in UX, see for example http://www.flagsarenotlanguages.com/blog/why-flags-do-not-represent-language/) Demo
import pycountry
...
class Language(object):
...
@property
def emoji(self):
try:
alpha_2 = pycountry.languages.get(alpha_3=self.iso).alpha_2.upper()
print(alpha_2)
return chr(ord(alpha_2[0]) + 127397) + chr(ord(alpha_2[1]) + 127397)
except AttributeError:
return None Then running this: import ety
from ety.data import langs
for code in langs:
lang = ety.Language(code)
if lang.emoji is not None:
print(lang.emoji, lang) Gives:
Some clear mismatches:
|
Are you sure they're mismatches? A few of those just look like they country code is derived from their native languages - I come from Devon, UK (next to Cornwall) so the first thing I noticed was that Cornish for 'Cornwall' is 'Kernow', which probably explains its Looking further into it, these seem to all be the two-char so tl;dr: your code looks good to me! feel free to PR it with a CLI arg to enable it! |
Oops sorry my mistake, you're right - for some reason I'm seeing different things on different devices: Chrome on my laptop displays letters that seem to map to ISO 639-1s and on Chrome on my phone I can see the wrong flags you mentioned 🤔 Maybe there's a free dataset somewhere mapping ISO 639-3 codes to flag emojis we could use? |
As mentioned on #25
Command line interface could have an
-e
flag for displaying relevant emojis alongside languages and maybe wordsVery low priority feature, but might be fun to implement and use
The text was updated successfully, but these errors were encountered: