iso-langcodes 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iso_langcodes-1.0.0/LICENSE +21 -0
- iso_langcodes-1.0.0/PKG-INFO +167 -0
- iso_langcodes-1.0.0/README.md +142 -0
- iso_langcodes-1.0.0/iso_langcodes/__init__.py +16 -0
- iso_langcodes-1.0.0/iso_langcodes/cli/__init__.py +1 -0
- iso_langcodes-1.0.0/iso_langcodes/cli/iso639.py +68 -0
- iso_langcodes-1.0.0/iso_langcodes/cli/langglottolog.py +58 -0
- iso_langcodes-1.0.0/iso_langcodes/cli/langgroup.py +96 -0
- iso_langcodes-1.0.0/iso_langcodes/cli/langscript.py +135 -0
- iso_langcodes-1.0.0/iso_langcodes/data/__init__.py +1 -0
- iso_langcodes-1.0.0/iso_langcodes/data/iso15924_data.py +9446 -0
- iso_langcodes-1.0.0/iso_langcodes/data/iso639_3_data.py +17380 -0
- iso_langcodes-1.0.0/iso_langcodes/data/iso639_5_data.py +6343 -0
- iso_langcodes-1.0.0/iso_langcodes/iso15924.py +521 -0
- iso_langcodes-1.0.0/iso_langcodes/iso639_3.py +148 -0
- iso_langcodes-1.0.0/iso_langcodes/iso639_5.py +79 -0
- iso_langcodes-1.0.0/iso_langcodes.egg-info/PKG-INFO +167 -0
- iso_langcodes-1.0.0/iso_langcodes.egg-info/SOURCES.txt +21 -0
- iso_langcodes-1.0.0/iso_langcodes.egg-info/dependency_links.txt +1 -0
- iso_langcodes-1.0.0/iso_langcodes.egg-info/entry_points.txt +5 -0
- iso_langcodes-1.0.0/iso_langcodes.egg-info/top_level.txt +1 -0
- iso_langcodes-1.0.0/pyproject.toml +45 -0
- iso_langcodes-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Joerg Tiedemann
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iso-langcodes
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python modules for working with language codes, language groups and language scripts
|
|
5
|
+
Author-email: Joerg Tiedemann <tiedemann@cpan.org>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/tiedemann/LanguageCodes
|
|
8
|
+
Project-URL: Repository, https://github.com/tiedemann/LanguageCodes
|
|
9
|
+
Keywords: language,codes,ISO,639,15924,linguistics
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# iso-langcodes
|
|
27
|
+
|
|
28
|
+
Python modules for working with language codes, language groups and language scripts.
|
|
29
|
+
|
|
30
|
+
Currently, there are 3 modules in this package:
|
|
31
|
+
|
|
32
|
+
- `iso_langcodes.iso639_3` - conversion between ISO language codes
|
|
33
|
+
- `iso_langcodes.iso639_5` - language groups and families according to ISO 639-5
|
|
34
|
+
- `iso_langcodes.iso15924` - language scripts and their connection to languages
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install iso-langcodes
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or install from source:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install .
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
### ISO 639-3
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from iso_langcodes import iso639_3
|
|
54
|
+
|
|
55
|
+
print(iso639_3.convert_iso639('iso639-1', 'fra'))
|
|
56
|
+
print(iso639_3.convert_iso639('iso639-3', 'de'))
|
|
57
|
+
print(iso639_3.convert_iso639('name', 'fa'))
|
|
58
|
+
|
|
59
|
+
print(iso639_3.get_iso639_1('deu'))
|
|
60
|
+
print(iso639_3.get_iso639_3('de'))
|
|
61
|
+
print(iso639_3.get_language_name('de'))
|
|
62
|
+
print(iso639_3.get_language_name('eng'))
|
|
63
|
+
print(iso639_3.get_macro_language('yue'))
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### ISO 639-5
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from iso_langcodes import iso639_5
|
|
70
|
+
|
|
71
|
+
print(' '.join(iso639_5.language_group('gmw')))
|
|
72
|
+
print(' '.join(iso639_5.language_group('gem')))
|
|
73
|
+
print(' '.join(iso639_5.language_group_children('gem')))
|
|
74
|
+
print(iso639_5.language_parent('afr'))
|
|
75
|
+
print(iso639_5.language_parent('gmw'))
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### ISO 15924
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from iso_langcodes import iso15924
|
|
82
|
+
|
|
83
|
+
script = iso15924.script_of_string('То је моја мачка.', 'srp')
|
|
84
|
+
script = iso15924.script_of_string('你是我妈妈。')
|
|
85
|
+
scripts = iso15924.script_of_string('То је моја мачка. Ti si moja majka.', allow_non_standard=True)
|
|
86
|
+
|
|
87
|
+
region = iso15924.default_territory('por')
|
|
88
|
+
script = iso15924.default_script('tur')
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Command Line Tools
|
|
92
|
+
|
|
93
|
+
The package provides three command-line tools:
|
|
94
|
+
|
|
95
|
+
### iso639
|
|
96
|
+
|
|
97
|
+
Convert between language codes:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
iso639 fra de eng
|
|
101
|
+
iso639 -2 fra deu
|
|
102
|
+
iso639 -3 de
|
|
103
|
+
iso639 -m yue
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### langgroup
|
|
107
|
+
|
|
108
|
+
Print language groups according to ISO 639-5:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
langgroup gem
|
|
112
|
+
langgroup -c gem
|
|
113
|
+
langgroup -p afr gmw
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### langscript
|
|
117
|
+
|
|
118
|
+
Detect characters from various scripts:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
echo "То је моја мачка." | langscript -l srp
|
|
122
|
+
echo "你是我妈妈。" | langscript
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### langglottolog
|
|
126
|
+
|
|
127
|
+
Convert between ISO 639-5 codes and Glottolog codes:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
langglottolog aav afa alg
|
|
131
|
+
langglottolog -g aust1305 afro1255
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
This software is Copyright (c) 2020 by Joerg Tiedemann.
|
|
137
|
+
|
|
138
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
139
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
140
|
+
in the Software without restriction, including without limitation the rights
|
|
141
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
142
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
143
|
+
furnished to do so, subject to the following conditions:
|
|
144
|
+
|
|
145
|
+
The above copyright notice and this permission notice shall be included in all
|
|
146
|
+
copies or substantial portions of the Software.
|
|
147
|
+
|
|
148
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
149
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
150
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
151
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
152
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
153
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
154
|
+
SOFTWARE.
|
|
155
|
+
|
|
156
|
+
## Acknowledgements
|
|
157
|
+
|
|
158
|
+
The language codes are taken from SIL International <https://iso639-3.sil.org>.
|
|
159
|
+
Please, check the terms of use listed at <https://iso639-3.sil.org/code_tables/download_tables>.
|
|
160
|
+
The current version uses the UTF-8 tables distributed in "iso-639-3_Code_Tables_20200130.zip"
|
|
161
|
+
from that website. This module adds some non-standard codes that are not specified
|
|
162
|
+
in the original tables to be compatible with some ad-hoc solutions in some resources
|
|
163
|
+
and tools.
|
|
164
|
+
|
|
165
|
+
The official ISO 15924 code list is taken from Unicode <https://www.unicode.org/iso15924/iso15924.txt.zip>
|
|
166
|
+
and the additional information about connections between languages, scripts and territories
|
|
167
|
+
is extracted from the Unicode CLDR project at <http://cldr.unicode.org>.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# iso-langcodes
|
|
2
|
+
|
|
3
|
+
Python modules for working with language codes, language groups and language scripts.
|
|
4
|
+
|
|
5
|
+
Currently, there are 3 modules in this package:
|
|
6
|
+
|
|
7
|
+
- `iso_langcodes.iso639_3` - conversion between ISO language codes
|
|
8
|
+
- `iso_langcodes.iso639_5` - language groups and families according to ISO 639-5
|
|
9
|
+
- `iso_langcodes.iso15924` - language scripts and their connection to languages
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install iso-langcodes
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or install from source:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install .
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### ISO 639-3
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from iso_langcodes import iso639_3
|
|
29
|
+
|
|
30
|
+
print(iso639_3.convert_iso639('iso639-1', 'fra'))
|
|
31
|
+
print(iso639_3.convert_iso639('iso639-3', 'de'))
|
|
32
|
+
print(iso639_3.convert_iso639('name', 'fa'))
|
|
33
|
+
|
|
34
|
+
print(iso639_3.get_iso639_1('deu'))
|
|
35
|
+
print(iso639_3.get_iso639_3('de'))
|
|
36
|
+
print(iso639_3.get_language_name('de'))
|
|
37
|
+
print(iso639_3.get_language_name('eng'))
|
|
38
|
+
print(iso639_3.get_macro_language('yue'))
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### ISO 639-5
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from iso_langcodes import iso639_5
|
|
45
|
+
|
|
46
|
+
print(' '.join(iso639_5.language_group('gmw')))
|
|
47
|
+
print(' '.join(iso639_5.language_group('gem')))
|
|
48
|
+
print(' '.join(iso639_5.language_group_children('gem')))
|
|
49
|
+
print(iso639_5.language_parent('afr'))
|
|
50
|
+
print(iso639_5.language_parent('gmw'))
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### ISO 15924
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from iso_langcodes import iso15924
|
|
57
|
+
|
|
58
|
+
script = iso15924.script_of_string('То је моја мачка.', 'srp')
|
|
59
|
+
script = iso15924.script_of_string('你是我妈妈。')
|
|
60
|
+
scripts = iso15924.script_of_string('То је моја мачка. Ti si moja majka.', allow_non_standard=True)
|
|
61
|
+
|
|
62
|
+
region = iso15924.default_territory('por')
|
|
63
|
+
script = iso15924.default_script('tur')
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Command Line Tools
|
|
67
|
+
|
|
68
|
+
The package provides three command-line tools:
|
|
69
|
+
|
|
70
|
+
### iso639
|
|
71
|
+
|
|
72
|
+
Convert between language codes:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
iso639 fra de eng
|
|
76
|
+
iso639 -2 fra deu
|
|
77
|
+
iso639 -3 de
|
|
78
|
+
iso639 -m yue
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### langgroup
|
|
82
|
+
|
|
83
|
+
Print language groups according to ISO 639-5:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
langgroup gem
|
|
87
|
+
langgroup -c gem
|
|
88
|
+
langgroup -p afr gmw
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### langscript
|
|
92
|
+
|
|
93
|
+
Detect characters from various scripts:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
echo "То је моја мачка." | langscript -l srp
|
|
97
|
+
echo "你是我妈妈。" | langscript
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### langglottolog
|
|
101
|
+
|
|
102
|
+
Convert between ISO 639-5 codes and Glottolog codes:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
langglottolog aav afa alg
|
|
106
|
+
langglottolog -g aust1305 afro1255
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
This software is Copyright (c) 2020 by Joerg Tiedemann.
|
|
112
|
+
|
|
113
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
114
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
115
|
+
in the Software without restriction, including without limitation the rights
|
|
116
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
117
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
118
|
+
furnished to do so, subject to the following conditions:
|
|
119
|
+
|
|
120
|
+
The above copyright notice and this permission notice shall be included in all
|
|
121
|
+
copies or substantial portions of the Software.
|
|
122
|
+
|
|
123
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
124
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
125
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
126
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
127
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
128
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
129
|
+
SOFTWARE.
|
|
130
|
+
|
|
131
|
+
## Acknowledgements
|
|
132
|
+
|
|
133
|
+
The language codes are taken from SIL International <https://iso639-3.sil.org>.
|
|
134
|
+
Please, check the terms of use listed at <https://iso639-3.sil.org/code_tables/download_tables>.
|
|
135
|
+
The current version uses the UTF-8 tables distributed in "iso-639-3_Code_Tables_20200130.zip"
|
|
136
|
+
from that website. This module adds some non-standard codes that are not specified
|
|
137
|
+
in the original tables to be compatible with some ad-hoc solutions in some resources
|
|
138
|
+
and tools.
|
|
139
|
+
|
|
140
|
+
The official ISO 15924 code list is taken from Unicode <https://www.unicode.org/iso15924/iso15924.txt.zip>
|
|
141
|
+
and the additional information about connections between languages, scripts and territories
|
|
142
|
+
is extracted from the Unicode CLDR project at <http://cldr.unicode.org>.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""
|
|
2
|
+
langcodes - Python modules for working with language codes, language groups and language scripts.
|
|
3
|
+
|
|
4
|
+
This package provides:
|
|
5
|
+
- ISO 639-3: conversion between ISO language codes
|
|
6
|
+
- ISO 639-5: language groups and families according to ISO 639-5
|
|
7
|
+
- ISO 15924: language scripts and their connection to languages
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from . import iso639_3
|
|
11
|
+
from . import iso639_5
|
|
12
|
+
from . import iso15924
|
|
13
|
+
|
|
14
|
+
__version__ = "1.0.0"
|
|
15
|
+
__author__ = "Joerg Tiedemann"
|
|
16
|
+
__all__ = ["iso639_3", "iso639_5", "iso15924"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""CLI package for langcodes."""
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
iso639 - a simple script to convert language codes.
|
|
4
|
+
|
|
5
|
+
Usage: iso639 [-2|-3|-m|-n|-k] [langcode]*
|
|
6
|
+
|
|
7
|
+
Convert to 3-letter-code if 2-letter code is given and vice versa.
|
|
8
|
+
-2 ... print 2-letter code (even if the input is a 2-letter code)
|
|
9
|
+
-3 ... print 3-letter code (even if the input is a 3-letter code)
|
|
10
|
+
-m ... print macro language instead of local language variants
|
|
11
|
+
-n ... don't print a final new-line
|
|
12
|
+
-k ... keep original code if no mapping is found
|
|
13
|
+
-p ... convert language pairs
|
|
14
|
+
-P ... convert language pairs and sort alphabetically
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
import sys
|
|
19
|
+
|
|
20
|
+
from .. import iso639_3
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def convert_pairs(type_, langs, sorted_, keep):
|
|
24
|
+
"""Convert language pairs instead of single language codes."""
|
|
25
|
+
converted = [iso639_3.convert_iso639(type_, lang, keep) for lang in langs.split('-')]
|
|
26
|
+
if sorted_:
|
|
27
|
+
converted = sorted(converted)
|
|
28
|
+
return '-'.join(converted)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def main():
|
|
32
|
+
parser = argparse.ArgumentParser(description='Convert language codes')
|
|
33
|
+
parser.add_argument('-2', '--iso639-1', action='store_true', help='convert to two-letter code (ISO 639-1)')
|
|
34
|
+
parser.add_argument('-3', '--iso639-3', action='store_true', help='convert to three-letter code (ISO 639-3)')
|
|
35
|
+
parser.add_argument('-m', '--macro', action='store_true', help='convert to macro language')
|
|
36
|
+
parser.add_argument('-n', '--no-newline', action='store_true', help="don't print a final new line")
|
|
37
|
+
parser.add_argument('-k', '--keep', action='store_true', help='keep original code if no mapping is found')
|
|
38
|
+
parser.add_argument('-p', '--pairs', action='store_true', help='convert language pairs')
|
|
39
|
+
parser.add_argument('-P', '--pairs-sorted', action='store_true', help='convert language pairs and sort alphabetically')
|
|
40
|
+
parser.add_argument('langcodes', nargs='*', help='language codes to convert')
|
|
41
|
+
|
|
42
|
+
args = parser.parse_args()
|
|
43
|
+
|
|
44
|
+
if args.iso639_1:
|
|
45
|
+
type_ = 'iso639-1'
|
|
46
|
+
elif args.iso639_3:
|
|
47
|
+
type_ = 'iso639-3'
|
|
48
|
+
elif args.macro:
|
|
49
|
+
type_ = 'macro'
|
|
50
|
+
else:
|
|
51
|
+
type_ = 'name'
|
|
52
|
+
|
|
53
|
+
if args.pairs or args.pairs_sorted:
|
|
54
|
+
converted = [convert_pairs(type_, lang, args.pairs_sorted, args.keep) for lang in args.langcodes]
|
|
55
|
+
else:
|
|
56
|
+
converted = [iso639_3.convert_iso639(type_, lang, args.keep) for lang in args.langcodes]
|
|
57
|
+
|
|
58
|
+
if type_ == 'name' and converted:
|
|
59
|
+
print('"' + '" "'.join(converted) + '"', end='')
|
|
60
|
+
else:
|
|
61
|
+
print(' '.join(converted), end='')
|
|
62
|
+
|
|
63
|
+
if not args.no_newline:
|
|
64
|
+
print()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == '__main__':
|
|
68
|
+
main()
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
langglottolog - convert between ISO 639-5 codes and Glottolog codes.
|
|
4
|
+
|
|
5
|
+
Usage: langglottolog [OPTIONS] CODE*
|
|
6
|
+
|
|
7
|
+
Options:
|
|
8
|
+
-h: help
|
|
9
|
+
-i: convert from ISO to Glottolog (default)
|
|
10
|
+
-g: convert from Glottolog to ISO
|
|
11
|
+
-n: don't print final newline
|
|
12
|
+
-v: verbose output
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
from .. import iso639_5
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def main():
|
|
22
|
+
parser = argparse.ArgumentParser(description='Convert between ISO 639-5 codes and Glottolog codes')
|
|
23
|
+
parser.add_argument('-i', '--iso2glottolog', action='store_true', help='convert from ISO to Glottolog (default)')
|
|
24
|
+
parser.add_argument('-g', '--glottolog2iso', action='store_true', help='convert from Glottolog to ISO')
|
|
25
|
+
parser.add_argument('-n', '--no-newline', action='store_true', help="don't print final newline")
|
|
26
|
+
parser.add_argument('-v', '--verbose', action='store_true', help='verbose output')
|
|
27
|
+
parser.add_argument('codes', nargs='*', help='codes to convert')
|
|
28
|
+
|
|
29
|
+
args = parser.parse_args()
|
|
30
|
+
|
|
31
|
+
if args.verbose:
|
|
32
|
+
iso639_5.VERBOSE = 1
|
|
33
|
+
|
|
34
|
+
# Read from STDIN or take codes from command line args
|
|
35
|
+
if args.codes:
|
|
36
|
+
codes = args.codes
|
|
37
|
+
else:
|
|
38
|
+
codes = sys.stdin.read().split()
|
|
39
|
+
|
|
40
|
+
# Default to ISO to Glottolog if neither flag is set
|
|
41
|
+
if not args.glottolog2iso:
|
|
42
|
+
args.iso2glottolog = True
|
|
43
|
+
|
|
44
|
+
converted = []
|
|
45
|
+
for code in codes:
|
|
46
|
+
if args.glottolog2iso:
|
|
47
|
+
result = iso639_5.glottolog2iso(code)
|
|
48
|
+
else:
|
|
49
|
+
result = iso639_5.iso2glottolog(code)
|
|
50
|
+
converted.append(result if result else 'unknown')
|
|
51
|
+
|
|
52
|
+
print(' '.join(converted), end='')
|
|
53
|
+
if not args.no_newline:
|
|
54
|
+
print()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if __name__ == '__main__':
|
|
58
|
+
main()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
langgroup - print language groups according to ISO639-5.
|
|
4
|
+
|
|
5
|
+
Usage: langgroup [OPTIONS] LANGCODE*
|
|
6
|
+
|
|
7
|
+
Options:
|
|
8
|
+
-h: help
|
|
9
|
+
-c: group children
|
|
10
|
+
-g: group languages
|
|
11
|
+
-G: group by grandparent
|
|
12
|
+
-n: don't print final newline
|
|
13
|
+
-p: print parent code of each given language code
|
|
14
|
+
-P: print parents all the way up the language tree
|
|
15
|
+
-v: verbose output
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
from .. import iso639_5
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def main():
|
|
25
|
+
parser = argparse.ArgumentParser(description='Print language groups according to ISO639-5')
|
|
26
|
+
parser.add_argument('-c', '--children', action='store_true', help='group children')
|
|
27
|
+
parser.add_argument('-g', '--group', action='store_true', help='group languages')
|
|
28
|
+
parser.add_argument('-G', '--grandparent', action='store_true', help='group by grandparent')
|
|
29
|
+
parser.add_argument('-n', '--no-newline', action='store_true', help="don't print final newline")
|
|
30
|
+
parser.add_argument('-p', '--parent', action='store_true', help='print parent code of each given language code')
|
|
31
|
+
parser.add_argument('-P', '--parents', action='store_true', help='print parents all the way up the language tree')
|
|
32
|
+
parser.add_argument('-v', '--verbose', action='store_true', help='verbose output')
|
|
33
|
+
parser.add_argument('langcodes', nargs='*', help='language codes')
|
|
34
|
+
|
|
35
|
+
args = parser.parse_args()
|
|
36
|
+
|
|
37
|
+
if args.verbose:
|
|
38
|
+
iso639_5.VERBOSE = 1
|
|
39
|
+
|
|
40
|
+
# Read from STDIN or take codes from command line args
|
|
41
|
+
if args.langcodes:
|
|
42
|
+
codes = args.langcodes
|
|
43
|
+
else:
|
|
44
|
+
codes = sys.stdin.read().split()
|
|
45
|
+
|
|
46
|
+
if args.parent:
|
|
47
|
+
converted = [iso639_5.language_parent(code) for code in codes]
|
|
48
|
+
print(' '.join(str(c) for c in converted), end='')
|
|
49
|
+
if not args.no_newline:
|
|
50
|
+
print()
|
|
51
|
+
elif args.parents:
|
|
52
|
+
trees = []
|
|
53
|
+
for lang in codes:
|
|
54
|
+
parents = []
|
|
55
|
+
while True:
|
|
56
|
+
p = iso639_5.language_parent(lang)
|
|
57
|
+
if not p:
|
|
58
|
+
break
|
|
59
|
+
parents.append(p)
|
|
60
|
+
lang = p
|
|
61
|
+
if p == 'mul':
|
|
62
|
+
break
|
|
63
|
+
if parents:
|
|
64
|
+
trees.append(':'.join(parents))
|
|
65
|
+
else:
|
|
66
|
+
trees.append('none')
|
|
67
|
+
print(' '.join(trees), end='')
|
|
68
|
+
if not args.no_newline:
|
|
69
|
+
print()
|
|
70
|
+
elif args.group or args.grandparent:
|
|
71
|
+
groups = {}
|
|
72
|
+
for code in codes:
|
|
73
|
+
parent = iso639_5.language_parent(code) or code
|
|
74
|
+
if args.grandparent:
|
|
75
|
+
parent = iso639_5.language_parent(parent) or parent
|
|
76
|
+
if parent not in groups:
|
|
77
|
+
groups[parent] = set()
|
|
78
|
+
groups[parent].add(code)
|
|
79
|
+
for key in sorted(groups.keys()):
|
|
80
|
+
if args.no_newline:
|
|
81
|
+
print('+'.join(sorted(groups[key])), end=' ')
|
|
82
|
+
else:
|
|
83
|
+
print(key, end='\t')
|
|
84
|
+
print(' '.join(sorted(groups[key])))
|
|
85
|
+
else:
|
|
86
|
+
for code in codes:
|
|
87
|
+
if args.children:
|
|
88
|
+
print(' '.join(iso639_5.language_group_children(code)), end='')
|
|
89
|
+
else:
|
|
90
|
+
print(' '.join(iso639_5.language_group(code)), end='')
|
|
91
|
+
if not args.no_newline:
|
|
92
|
+
print()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == '__main__':
|
|
96
|
+
main()
|