-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathiso639
executable file
·39 lines (33 loc) · 890 Bytes
/
iso639
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
"""
Converts among language names and abbreviations using Python's ISO-639 module.
https://pypi.python.org/pypi/iso-639/0.4.3
> from iso639 import languages as l
> greek = l.get(part1 = 'el')
> pprint(vars(greek))
{'inverted': 'Greek, Modern (1453-)',
'macro': '',
'name': 'Modern Greek (1453-)',
'names': [],
'part1': 'el',
'part2b': 'gre',
'part2t': 'ell',
'part3': 'ell',
'part5': ''}
"""
import sys
import iso639
if len(sys.argv) != 2:
print "Usage: iso639 LANG"
print "where LANG is a language name or abbreviation."
sys.exit(1)
input = sys.argv[1]
if len(input) == 2:
lang = iso639.languages.get(part1 = input)
print lang.name
elif len(input) == 3:
lang = iso639.languages.get(part3 = input)
print lang.name
else:
lang = iso639.languages.get(name = input)
print lang.part1