Skip to content

Commit 282e5d7

Browse files
committed
Rename to ICU and pymathics.icu...
Add $Language
1 parent 03b3d82 commit 282e5d7

File tree

8 files changed

+101
-27
lines changed

8 files changed

+101
-27
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Example Session
66
::
77

88
$ mathicsscript
9-
In[1]:= LoadModule["pymathics.language"]
10-
Out[1]= pymathics.language
9+
In[1]:= LoadModule["pymathics.icu"]
10+
Out[1]= pymathics.icu
1111
In[2]= Alphabet["Croatian"]
1212
Out[2]= {['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'z', 'ć', 'č', 'đ', 'š', 'ž', 'dž', 'lj', 'nj']}

admin-tools/make-dist.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717

1818
cd ..
19-
source pymathics/language/version.py
19+
source pymathics/icu/version.py
2020
echo $__version__
2121

2222
pyversion=3.13

pymathics/icu/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
ICU — International Components for Unicode
3+
4+
Functions which provide information from the Python ICU library <url>:icu:https://pypi.org/project/pyicu/</url> library.
5+
6+
Examples:
7+
8+
Load in Mathics3 Module:
9+
>> LoadModule["pymathics.icu"]
10+
= pymathics.natlang
11+
12+
Show the language in effect:
13+
>> $Language
14+
= "English"
15+
16+
Get the alphabet for that language:
17+
>> Alphabet[]
18+
= {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z}
19+
20+
Get the alphabet for that locale "es" (Spanish):
21+
>> Alphabet["es"]
22+
= {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, á, é, í, ñ, ó, ú, ü}
23+
24+
You can also specify an alphabet using a name:
25+
>> Alphabet["Ukrainian"]
26+
= {ʼ, а, б, в, г, д, е, ж, з, и, й, к, л, м, н, о, п, р, с, т, у, ф, х, ц, ч, ш, щ, ь, ю, я, є, і, ї, ґ}
27+
"""
28+
29+
from pymathics.icu.__main__ import Alphabet, Language
30+
from pymathics.icu.version import __version__
31+
32+
pymathics_version_data = {
33+
"author": "The Mathics3 Team",
34+
"version": __version__,
35+
"name": "icu",
36+
"requires": ["PyICU"],
37+
}
38+
39+
__all__ = ["Alphabet", "Language", "pymathics_version_data", "__version__"]

pymathics/language/__main__.py renamed to pymathics/icu/__main__.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
"""
4-
Languages & Translations
4+
Languages - Human-Language Alphabets and Locales via PyICU.
55
"""
66

77
# PYTHON MODULES USED IN HERE
@@ -13,15 +13,18 @@
1313

1414
from icu import Locale, LocaleData
1515
from mathics.core.atoms import String
16-
from mathics.core.builtin import Builtin
16+
from mathics.core.builtin import Builtin, Predefined
1717
from mathics.core.convert.expression import to_mathics_list
18+
from mathics.core.evaluation import Evaluation
1819

1920
availableLocales = Locale.getAvailableLocales()
2021
language2locale = {
2122
availableLocale.getDisplayLanguage(): locale_name
2223
for locale_name, availableLocale in availableLocales.items()
2324
}
2425

26+
# The current value of $Language
27+
LANGUAGE = "English"
2528

2629
def eval_alphabet(language_name: String) -> Optional[List[String]]:
2730

@@ -38,7 +41,7 @@ class Alphabet(Builtin):
3841
Basic lowercase alphabet via <url>:Unicode: https://home.unicode.org/</url> and <url>:PyICU: https://pypi.org/project/PyICU/</url>
3942
<dl>
4043
<dt>'Alphabet'[]
41-
<dd>gives the list of lowercase letters a-z in the English alphabet .
44+
<dd>gives the list of lowercase letters a-z in the English alphabet.
4245
4346
<dt>'Alphabet[$type$]'
4447
<dd> gives the alphabet for the language or class $type$.
@@ -65,7 +68,7 @@ class Alphabet(Builtin):
6568
}
6669

6770
rules = {
68-
"Alphabet[]": """Alphabet["English"]""",
71+
"Alphabet[]": """Alphabet[Pymathics`$Language]""",
6972
}
7073

7174
summary_text = "lowercase letters in an alphabet"
@@ -77,3 +80,52 @@ def eval(self, alpha: String, evaluation):
7780
evaluation.message("Alphabet", "nalph", alpha)
7881
return
7982
return alphabet_list
83+
84+
## FIXME: move to mathics-core. Will have to change references to Pymathics`$Language to $Language
85+
class Language(Predefined):
86+
"""
87+
<url>
88+
:WMA link:
89+
https://reference.wolfram.com/language/ref/\\$Language.html</url>
90+
91+
<dl>
92+
<dt>'\\$Language'
93+
<dd>is a settable global variable for the default language used in Mathics3.
94+
</dl>
95+
96+
See the language in effect used for functions like 'Alphabet[]':
97+
98+
>> old_language = $Language
99+
= ...
100+
101+
By setting its value, The letters of 'Alphabet[]' are changed:
102+
103+
>> $Language = "German"; Alphabet[]
104+
= ...
105+
106+
#> $Language = old_language;
107+
108+
See also <url>
109+
:Alphabet:
110+
/doc/mathics3-modules/icu-international-components-for-unicode/languages-human-language-alphabets-and-locales-via-pyicu/alphabet/</url>.
111+
"""
112+
113+
name = "$Language"
114+
messages = {
115+
"notstr": "`1` is not a string. Only strings can be set as the value of $Language.",
116+
}
117+
118+
summary_text = "settable global variable giving the default language"
119+
value = f'"{LANGUAGE}"'
120+
# Rules has to come after "value"
121+
rules = {
122+
"Pymathics`$Language": value,
123+
}
124+
125+
def eval_set(self, value, evaluation: Evaluation):
126+
"""Set[Pymathics`$Language, value_]"""
127+
if isinstance(value, String):
128+
evaluation.definitions.set_ownvalue("$Language", value)
129+
else:
130+
evaluation.message("Pymathics`$Language", "notstr", value)
131+
return value
File renamed without changes.

pymathics/language/__init__.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ dev = [
4949

5050
[tool.setuptools]
5151
packages = [
52-
"pymathics.language",
52+
"pymathics.icu",
5353
]
5454

5555
[tool.setuptools.dynamic]
56-
version = {attr = "pymathics.language.__version__"}
56+
version = {attr = "pymathics.icu.__version__"}

test/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def check_evaluation(str_expr: str, expected: str, assert_message=""):
2020

2121

2222
def test_language():
23-
session.evaluate('LoadModule["pymathics.language"]') == "pymathics.language"
23+
session.evaluate('LoadModule["pymathics.icu"]') == "pymathics.icu"
2424
check_evaluation(
2525
'Alphabet["es"]',
2626
(

0 commit comments

Comments
 (0)