ihub-aether-lang-pack 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.
- ihub_aether_lang_pack-1.0.0/PKG-INFO +90 -0
- ihub_aether_lang_pack-1.0.0/README.md +75 -0
- ihub_aether_lang_pack-1.0.0/pyproject.toml +30 -0
- ihub_aether_lang_pack-1.0.0/setup.cfg +4 -0
- ihub_aether_lang_pack-1.0.0/src/ihub_aether_lang_pack.egg-info/PKG-INFO +90 -0
- ihub_aether_lang_pack-1.0.0/src/ihub_aether_lang_pack.egg-info/SOURCES.txt +9 -0
- ihub_aether_lang_pack-1.0.0/src/ihub_aether_lang_pack.egg-info/dependency_links.txt +1 -0
- ihub_aether_lang_pack-1.0.0/src/ihub_aether_lang_pack.egg-info/top_level.txt +1 -0
- ihub_aether_lang_pack-1.0.0/src/langpack/__init__.py +148 -0
- ihub_aether_lang_pack-1.0.0/src/langpack/__main__.py +31 -0
- ihub_aether_lang_pack-1.0.0/src/langpack/_data/languages.json +98815 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ihub-aether-lang-pack
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Complete ISO 639 language registry: all 7,927 registered languages with official English and French names, CLDR native names, status, scope, macrolanguage links, legacy aliases, and a defined fallback chain for every code.
|
|
5
|
+
Author: iHub Aether
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://4m1wp03rd34yk.aiforce.cloud/app/app_17e3evgsy6q
|
|
8
|
+
Keywords: iso639,language,i18n,locale,langpack,iso-639-3,internationalization
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Internationalization
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# iHub Aether Lang Pack
|
|
17
|
+
|
|
18
|
+
The complete ISO 639 language registry as a zero-dependency Python package.
|
|
19
|
+
|
|
20
|
+
Every registered language code (ISO 639-1 / 639-2 / 639-3) with:
|
|
21
|
+
|
|
22
|
+
- official English and French names (ISO / IANA)
|
|
23
|
+
- native names from Unicode CLDR where they exist
|
|
24
|
+
- status: living / extinct / historical / constructed / special
|
|
25
|
+
- scope: individual / macrolanguage / special
|
|
26
|
+
- macrolanguage links (e.g. `cmn` -> `zh`)
|
|
27
|
+
- legacy aliases (e.g. `iw` -> `he`, `in` -> `id`, `sh` -> `sr`)
|
|
28
|
+
- a defined fallback chain on **every** code, so no lookup ever breaks
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install ihub-aether-lang-pack
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from langpack import langpack
|
|
40
|
+
|
|
41
|
+
len(langpack) # 7927 registered languages
|
|
42
|
+
langpack.counts["living"] # 7082 spoken (living) tongues
|
|
43
|
+
|
|
44
|
+
langpack.get("zh")
|
|
45
|
+
# {'iso6393': 'zho', 'iso6391': 'zh', 'name': 'Chinese', 'native': '中文', ...}
|
|
46
|
+
|
|
47
|
+
langpack.resolve("iw") # 'he' (legacy alias -> canonical)
|
|
48
|
+
langpack.resolve("zh-Hans") # 'zh' (BCP-47 tag -> base code)
|
|
49
|
+
|
|
50
|
+
langpack.fallback_chain("yue") # ['yue', 'zh', 'en']
|
|
51
|
+
langpack.fallback("cmn") # 'zh'
|
|
52
|
+
|
|
53
|
+
langpack.search("cantonese") # [{... 'yue' ...}]
|
|
54
|
+
langpack.native_name("ja") # '日本語'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Command line:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python -m langpack # summary
|
|
61
|
+
python -m langpack chinese # search
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Fallback rule
|
|
65
|
+
|
|
66
|
+
- non-living codes -> `en`
|
|
67
|
+
- macrolanguages -> `en`
|
|
68
|
+
- individual under a macrolanguage -> that macrolanguage -> `en`
|
|
69
|
+
- everything else -> `en`
|
|
70
|
+
|
|
71
|
+
The chain is always `[code, fallback, en]` (deduplicated).
|
|
72
|
+
|
|
73
|
+
## Coverage and dialects
|
|
74
|
+
|
|
75
|
+
The registry contains all **7,927 codes registered by ISO 639**, which includes
|
|
76
|
+
the local varieties that have official codes: Chinese "dialects" (Mandarin,
|
|
77
|
+
Cantonese, Wu, Hakka, Min Nan...), Arabic regional varieties, German dialects
|
|
78
|
+
and so on. Sub-dialects that ISO does not register cannot be in any real pack;
|
|
79
|
+
script variants (zh-Hans / zh-Hant) are handled on top via BCP-47 tags, which
|
|
80
|
+
`resolve()` already accepts.
|
|
81
|
+
|
|
82
|
+
## Data sources
|
|
83
|
+
|
|
84
|
+
- ISO 639-3 official code tables (SIL International)
|
|
85
|
+
- IANA Language Subtag Registry
|
|
86
|
+
- Unicode CLDR language names
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT (code). Data compiled from the public ISO 639 / IANA / CLDR registries.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# iHub Aether Lang Pack
|
|
2
|
+
|
|
3
|
+
The complete ISO 639 language registry as a zero-dependency Python package.
|
|
4
|
+
|
|
5
|
+
Every registered language code (ISO 639-1 / 639-2 / 639-3) with:
|
|
6
|
+
|
|
7
|
+
- official English and French names (ISO / IANA)
|
|
8
|
+
- native names from Unicode CLDR where they exist
|
|
9
|
+
- status: living / extinct / historical / constructed / special
|
|
10
|
+
- scope: individual / macrolanguage / special
|
|
11
|
+
- macrolanguage links (e.g. `cmn` -> `zh`)
|
|
12
|
+
- legacy aliases (e.g. `iw` -> `he`, `in` -> `id`, `sh` -> `sr`)
|
|
13
|
+
- a defined fallback chain on **every** code, so no lookup ever breaks
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install ihub-aether-lang-pack
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from langpack import langpack
|
|
25
|
+
|
|
26
|
+
len(langpack) # 7927 registered languages
|
|
27
|
+
langpack.counts["living"] # 7082 spoken (living) tongues
|
|
28
|
+
|
|
29
|
+
langpack.get("zh")
|
|
30
|
+
# {'iso6393': 'zho', 'iso6391': 'zh', 'name': 'Chinese', 'native': '中文', ...}
|
|
31
|
+
|
|
32
|
+
langpack.resolve("iw") # 'he' (legacy alias -> canonical)
|
|
33
|
+
langpack.resolve("zh-Hans") # 'zh' (BCP-47 tag -> base code)
|
|
34
|
+
|
|
35
|
+
langpack.fallback_chain("yue") # ['yue', 'zh', 'en']
|
|
36
|
+
langpack.fallback("cmn") # 'zh'
|
|
37
|
+
|
|
38
|
+
langpack.search("cantonese") # [{... 'yue' ...}]
|
|
39
|
+
langpack.native_name("ja") # '日本語'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Command line:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m langpack # summary
|
|
46
|
+
python -m langpack chinese # search
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Fallback rule
|
|
50
|
+
|
|
51
|
+
- non-living codes -> `en`
|
|
52
|
+
- macrolanguages -> `en`
|
|
53
|
+
- individual under a macrolanguage -> that macrolanguage -> `en`
|
|
54
|
+
- everything else -> `en`
|
|
55
|
+
|
|
56
|
+
The chain is always `[code, fallback, en]` (deduplicated).
|
|
57
|
+
|
|
58
|
+
## Coverage and dialects
|
|
59
|
+
|
|
60
|
+
The registry contains all **7,927 codes registered by ISO 639**, which includes
|
|
61
|
+
the local varieties that have official codes: Chinese "dialects" (Mandarin,
|
|
62
|
+
Cantonese, Wu, Hakka, Min Nan...), Arabic regional varieties, German dialects
|
|
63
|
+
and so on. Sub-dialects that ISO does not register cannot be in any real pack;
|
|
64
|
+
script variants (zh-Hans / zh-Hant) are handled on top via BCP-47 tags, which
|
|
65
|
+
`resolve()` already accepts.
|
|
66
|
+
|
|
67
|
+
## Data sources
|
|
68
|
+
|
|
69
|
+
- ISO 639-3 official code tables (SIL International)
|
|
70
|
+
- IANA Language Subtag Registry
|
|
71
|
+
- Unicode CLDR language names
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT (code). Data compiled from the public ISO 639 / IANA / CLDR registries.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ihub-aether-lang-pack"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Complete ISO 639 language registry: all 7,927 registered languages with official English and French names, CLDR native names, status, scope, macrolanguage links, legacy aliases, and a defined fallback chain for every code."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "iHub Aether" }]
|
|
13
|
+
keywords = ["iso639", "language", "i18n", "locale", "langpack", "iso-639-3", "internationalization"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 5 - Production/Stable",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Topic :: Software Development :: Internationalization",
|
|
19
|
+
]
|
|
20
|
+
dependencies = []
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://4m1wp03rd34yk.aiforce.cloud/app/app_17e3evgsy6q"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools]
|
|
26
|
+
package-dir = { "" = "src" }
|
|
27
|
+
packages = ["langpack", "langpack._data"]
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.package-data]
|
|
30
|
+
langpack = ["_data/languages.json"]
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ihub-aether-lang-pack
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Complete ISO 639 language registry: all 7,927 registered languages with official English and French names, CLDR native names, status, scope, macrolanguage links, legacy aliases, and a defined fallback chain for every code.
|
|
5
|
+
Author: iHub Aether
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://4m1wp03rd34yk.aiforce.cloud/app/app_17e3evgsy6q
|
|
8
|
+
Keywords: iso639,language,i18n,locale,langpack,iso-639-3,internationalization
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Internationalization
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# iHub Aether Lang Pack
|
|
17
|
+
|
|
18
|
+
The complete ISO 639 language registry as a zero-dependency Python package.
|
|
19
|
+
|
|
20
|
+
Every registered language code (ISO 639-1 / 639-2 / 639-3) with:
|
|
21
|
+
|
|
22
|
+
- official English and French names (ISO / IANA)
|
|
23
|
+
- native names from Unicode CLDR where they exist
|
|
24
|
+
- status: living / extinct / historical / constructed / special
|
|
25
|
+
- scope: individual / macrolanguage / special
|
|
26
|
+
- macrolanguage links (e.g. `cmn` -> `zh`)
|
|
27
|
+
- legacy aliases (e.g. `iw` -> `he`, `in` -> `id`, `sh` -> `sr`)
|
|
28
|
+
- a defined fallback chain on **every** code, so no lookup ever breaks
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install ihub-aether-lang-pack
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from langpack import langpack
|
|
40
|
+
|
|
41
|
+
len(langpack) # 7927 registered languages
|
|
42
|
+
langpack.counts["living"] # 7082 spoken (living) tongues
|
|
43
|
+
|
|
44
|
+
langpack.get("zh")
|
|
45
|
+
# {'iso6393': 'zho', 'iso6391': 'zh', 'name': 'Chinese', 'native': '中文', ...}
|
|
46
|
+
|
|
47
|
+
langpack.resolve("iw") # 'he' (legacy alias -> canonical)
|
|
48
|
+
langpack.resolve("zh-Hans") # 'zh' (BCP-47 tag -> base code)
|
|
49
|
+
|
|
50
|
+
langpack.fallback_chain("yue") # ['yue', 'zh', 'en']
|
|
51
|
+
langpack.fallback("cmn") # 'zh'
|
|
52
|
+
|
|
53
|
+
langpack.search("cantonese") # [{... 'yue' ...}]
|
|
54
|
+
langpack.native_name("ja") # '日本語'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Command line:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python -m langpack # summary
|
|
61
|
+
python -m langpack chinese # search
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Fallback rule
|
|
65
|
+
|
|
66
|
+
- non-living codes -> `en`
|
|
67
|
+
- macrolanguages -> `en`
|
|
68
|
+
- individual under a macrolanguage -> that macrolanguage -> `en`
|
|
69
|
+
- everything else -> `en`
|
|
70
|
+
|
|
71
|
+
The chain is always `[code, fallback, en]` (deduplicated).
|
|
72
|
+
|
|
73
|
+
## Coverage and dialects
|
|
74
|
+
|
|
75
|
+
The registry contains all **7,927 codes registered by ISO 639**, which includes
|
|
76
|
+
the local varieties that have official codes: Chinese "dialects" (Mandarin,
|
|
77
|
+
Cantonese, Wu, Hakka, Min Nan...), Arabic regional varieties, German dialects
|
|
78
|
+
and so on. Sub-dialects that ISO does not register cannot be in any real pack;
|
|
79
|
+
script variants (zh-Hans / zh-Hant) are handled on top via BCP-47 tags, which
|
|
80
|
+
`resolve()` already accepts.
|
|
81
|
+
|
|
82
|
+
## Data sources
|
|
83
|
+
|
|
84
|
+
- ISO 639-3 official code tables (SIL International)
|
|
85
|
+
- IANA Language Subtag Registry
|
|
86
|
+
- Unicode CLDR language names
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT (code). Data compiled from the public ISO 639 / IANA / CLDR registries.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/ihub_aether_lang_pack.egg-info/PKG-INFO
|
|
4
|
+
src/ihub_aether_lang_pack.egg-info/SOURCES.txt
|
|
5
|
+
src/ihub_aether_lang_pack.egg-info/dependency_links.txt
|
|
6
|
+
src/ihub_aether_lang_pack.egg-info/top_level.txt
|
|
7
|
+
src/langpack/__init__.py
|
|
8
|
+
src/langpack/__main__.py
|
|
9
|
+
src/langpack/_data/languages.json
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
langpack
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""iHub Aether Lang Pack - complete ISO 639 language registry.
|
|
2
|
+
|
|
3
|
+
Every ISO 639-1/2/3 registered code, with official English and French names,
|
|
4
|
+
Unicode CLDR native names, status, scope, macrolanguage links, legacy aliases,
|
|
5
|
+
and a defined fallback chain so no language lookup ever breaks.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from importlib import resources
|
|
12
|
+
from typing import Dict, Iterator, List, Optional
|
|
13
|
+
|
|
14
|
+
FORMAT = "ihub-aether-lang-pack"
|
|
15
|
+
FORMAT_VERSION = 1
|
|
16
|
+
VERSION = "1.0.0"
|
|
17
|
+
DEFAULT_FALLBACK = "en"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _load_pack() -> Dict:
|
|
21
|
+
raw = (resources.files("langpack") / "_data" / "languages.json").read_bytes()
|
|
22
|
+
return json.loads(raw.decode("utf-8"))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class LanguagePack:
|
|
26
|
+
"""Read-only view over the full ISO 639 registry with alias resolution
|
|
27
|
+
and per-code fallback chains."""
|
|
28
|
+
|
|
29
|
+
def __init__(self) -> None:
|
|
30
|
+
self._pack = _load_pack()
|
|
31
|
+
self._langs = self._pack["languages"]
|
|
32
|
+
self._aliases = self._pack["aliases"]
|
|
33
|
+
|
|
34
|
+
# -- metadata -----------------------------------------------------
|
|
35
|
+
@property
|
|
36
|
+
def counts(self) -> Dict:
|
|
37
|
+
return dict(self._pack["counts"])
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def aliases(self) -> Dict:
|
|
41
|
+
return dict(self._aliases)
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def sources(self) -> List[str]:
|
|
45
|
+
return list(self._pack["sources"])
|
|
46
|
+
|
|
47
|
+
# -- lookup -------------------------------------------------------
|
|
48
|
+
def resolve(self, code: str) -> Optional[str]:
|
|
49
|
+
"""Return the canonical registry code for any input.
|
|
50
|
+
|
|
51
|
+
Accepts exact codes, legacy aliases (iw -> he, sh -> sr, ...),
|
|
52
|
+
and BCP-47 tags (zh-Hans -> zh, en-US -> en). Returns None when
|
|
53
|
+
the code is not registered.
|
|
54
|
+
"""
|
|
55
|
+
c = str(code).strip().lower()
|
|
56
|
+
base = c.split("-")[0]
|
|
57
|
+
base = self._aliases.get(base, base)
|
|
58
|
+
if base in self._langs:
|
|
59
|
+
return base
|
|
60
|
+
if c in self._langs:
|
|
61
|
+
return c
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
def get(self, code: str) -> Optional[Dict]:
|
|
65
|
+
"""Return the full entry for a code, or None when not registered."""
|
|
66
|
+
canonical = self.resolve(code)
|
|
67
|
+
if canonical is None:
|
|
68
|
+
return None
|
|
69
|
+
return dict(self._langs[canonical])
|
|
70
|
+
|
|
71
|
+
def __contains__(self, code: str) -> bool:
|
|
72
|
+
return self.resolve(code) is not None
|
|
73
|
+
|
|
74
|
+
def __getitem__(self, code: str) -> Dict:
|
|
75
|
+
entry = self.get(code)
|
|
76
|
+
if entry is None:
|
|
77
|
+
raise KeyError(code)
|
|
78
|
+
return entry
|
|
79
|
+
|
|
80
|
+
def __iter__(self) -> Iterator[str]:
|
|
81
|
+
return iter(self._langs)
|
|
82
|
+
|
|
83
|
+
def __len__(self) -> int:
|
|
84
|
+
return len(self._langs)
|
|
85
|
+
|
|
86
|
+
# -- names ---------------------------------------------------------
|
|
87
|
+
def name(self, code: str, field: str = "name") -> Optional[str]:
|
|
88
|
+
"""English name by default; pass 'native' or 'nameFr' for those."""
|
|
89
|
+
entry = self.get(code)
|
|
90
|
+
if entry is None:
|
|
91
|
+
return None
|
|
92
|
+
return entry.get(field) or entry.get("name")
|
|
93
|
+
|
|
94
|
+
def native_name(self, code: str) -> Optional[str]:
|
|
95
|
+
return self.name(code, "native")
|
|
96
|
+
|
|
97
|
+
def french_name(self, code: str) -> Optional[str]:
|
|
98
|
+
return self.name(code, "nameFr")
|
|
99
|
+
|
|
100
|
+
# -- fallback ------------------------------------------------------
|
|
101
|
+
def fallback_chain(self, code: str) -> List[str]:
|
|
102
|
+
"""Defined fallback chain, always ending in 'en'."""
|
|
103
|
+
canonical = self.resolve(code)
|
|
104
|
+
if canonical is None:
|
|
105
|
+
return [DEFAULT_FALLBACK]
|
|
106
|
+
return list(
|
|
107
|
+
self._langs[canonical].get("fallbackChain")
|
|
108
|
+
or [canonical, DEFAULT_FALLBACK]
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
def fallback(self, code: str) -> str:
|
|
112
|
+
chain = self.fallback_chain(code)
|
|
113
|
+
return chain[1] if len(chain) > 1 else chain[0]
|
|
114
|
+
|
|
115
|
+
# -- iteration / search -------------------------------------------
|
|
116
|
+
def all(self) -> List[Dict]:
|
|
117
|
+
return [dict(e) for e in self._langs.values()]
|
|
118
|
+
|
|
119
|
+
def living(self) -> List[Dict]:
|
|
120
|
+
return [dict(e) for e in self._langs.values() if e.get("spoken")]
|
|
121
|
+
|
|
122
|
+
def search(self, query: str, limit: int = 50) -> List[Dict]:
|
|
123
|
+
q = str(query).strip().lower()
|
|
124
|
+
if not q:
|
|
125
|
+
return []
|
|
126
|
+
out = []
|
|
127
|
+
for code, e in self._langs.items():
|
|
128
|
+
hay = " ".join(
|
|
129
|
+
str(e.get(k) or "")
|
|
130
|
+
for k in ("iso6393", "iso6391", "name", "nameFr", "native", "macro", "fallback")
|
|
131
|
+
).lower()
|
|
132
|
+
if q in code or q in hay:
|
|
133
|
+
out.append(dict(e))
|
|
134
|
+
if len(out) >= limit:
|
|
135
|
+
break
|
|
136
|
+
return out
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
langpack = LanguagePack()
|
|
140
|
+
|
|
141
|
+
__all__ = [
|
|
142
|
+
"LanguagePack",
|
|
143
|
+
"langpack",
|
|
144
|
+
"FORMAT",
|
|
145
|
+
"FORMAT_VERSION",
|
|
146
|
+
"VERSION",
|
|
147
|
+
"DEFAULT_FALLBACK",
|
|
148
|
+
]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Command line interface: python -m langpack [query]"""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from langpack import langpack
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main(argv):
|
|
9
|
+
if not argv:
|
|
10
|
+
c = langpack.counts
|
|
11
|
+
print("iHub Aether Lang Pack - %d registered languages" % c["total"])
|
|
12
|
+
print(
|
|
13
|
+
"spoken: %d | native names: %d | aliases: %d"
|
|
14
|
+
% (c["living"], c["withNativeName"], c["aliases"])
|
|
15
|
+
)
|
|
16
|
+
return 0
|
|
17
|
+
q = argv[0]
|
|
18
|
+
res = langpack.search(q, limit=20)
|
|
19
|
+
if not res:
|
|
20
|
+
print("no match for %r" % q)
|
|
21
|
+
return 1
|
|
22
|
+
for e in res:
|
|
23
|
+
print(
|
|
24
|
+
"%-6s %-4s %-14s %s"
|
|
25
|
+
% (e.get("iso6393", ""), e.get("iso6391", "") or "", e.get("name", ""), e.get("native", "") or "")
|
|
26
|
+
)
|
|
27
|
+
return 0
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
sys.exit(main(sys.argv[1:]))
|