Skip to content

Commit 3936efe

Browse files
committed
Minor refactors.
1 parent 6798fa1 commit 3936efe

7 files changed

Lines changed: 46 additions & 23 deletions

File tree

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ Simply pass in a date and coordinates to one of the available chart classes, and
1717

1818
Full documentation is available [here](https://github.com/theriftlab/immanuel-python/tree/v1.2.4/docs/0-contents.md), or follow the Quick Start below to see how to quickly generate a natal chart.
1919

20+
## Translations
21+
22+
Immanuel is currently available in the following locales / languages:
23+
24+
* **en_US:** (default) US English
25+
* **pt_BR:** Brazilian Portuguese
26+
* Coming soon: Spanish translation
27+
28+
See [the documentation](/docs/5-settings.md#locale) on how to switch. Documentation itself is not currently available in other translations.
29+
2030
## Quick Start
2131

2232
You can get started with full natal chart data in minutes. Simply install Immanuel:
@@ -134,7 +144,13 @@ Which will output each of the chart's objects in this format:
134144
},
135145
"sign": {
136146
"number": 10,
137-
"name": "Capricorn"
147+
"name": "Capricorn",
148+
"element": "Earth",
149+
"modality": "Cardinal"
150+
},
151+
"decan": {
152+
"number": 2,
153+
"name": "2nd Decan"
138154
},
139155
"house": {
140156
"index": 2000011,
@@ -251,6 +267,8 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
251267

252268
Immanuel is forever indebted to the pioneering work of Alois Treindl and Dieter Koch at Astrodienst, and to João Ventura for the incredibly detailed [flatlib](https://github.com/flatangle/flatlib) which first inspired the development of this package.
253269

270+
A big thank-you goes to Nathan Octavio who suggested translations, and who translated Immanuel into Brazilian Portuguese.
271+
254272
## Contact
255273

256274
Please post any issues, feature requests, PRs etc. on GitHub. For anything else email robert@theriftlab.com.

docs/5-settings.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ settings.aspect_rules |= {
7272

7373
There are many detailed customizations for chart data, especially for aspect rules. This section will provide you with an overview, but taking a look through the defaults in `setup.py` and the const files will give you a more detailed idea.
7474

75+
### `locale`
76+
77+
A string specifying the locale for all output on any subsequently-generated charts or chart subjects. Available options:
78+
79+
* `pt_BR` - Brazilian Portuguese
80+
81+
Default: `None` (effectively `en_US`)
82+
7583
### `chart_data`
7684

7785
A dict which specifies what top-level data each chart type should contain. The values here are fairly self-explanatory as the constants line up with the chart class property names described in the [Returned Data](4-data.md) section.

immanuel/classes/localize.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,20 @@ def set_locale(lcid: str) -> None:
3434
Localize.lcid = lcid
3535
Localize.translation = translation
3636
locale.setlocale(locale.LC_TIME, lcid)
37+
38+
mappings_path = f'{Localize.localedir}{os.sep}{Localize.lcid}{os.sep}mappings.py'
39+
40+
if os.path.isfile(mappings_path):
41+
with open(mappings_path, 'r') as mappings:
42+
exec(mappings.read(), MAPPINGS)
3743
else:
3844
Localize.reset()
3945

4046
def reset() -> None:
4147
Localize.lcid = None
4248
Localize.translation = None
4349
locale.setlocale(locale.LC_TIME, 'en_US')
50+
MAPPINGS = {}
4451

4552

4653
def _(input: str, context: str = None) -> str:
@@ -58,8 +65,4 @@ def gender(index: int|float) -> str:
5865
if Localize.translation is None:
5966
return None
6067

61-
if not MAPPINGS:
62-
with open(f'{Localize.localedir}{os.sep}{Localize.lcid}{os.sep}mappings.py', 'r') as mappings:
63-
exec(mappings.read(), MAPPINGS)
64-
6568
return MAPPINGS['GENDERS'][index] if index in MAPPINGS['GENDERS'] else genders.AMBIGUOUS

immanuel/classes/wrap.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,20 @@ def __init__(self, object: dict, objects: dict = None, houses: dict = None, is_d
226226
self.score = dignity.score(dignity_state)
227227

228228
def __str__(self) -> str:
229-
if hasattr(self, 'house'):
230-
return _('{name} {longitude} in {sign}, {house}').format(
231-
name=self.name,
232-
longitude=self.sign_longitude,
233-
sign=self.sign,
234-
house=self.house.name,
235-
)
236-
237-
return _('{name} {longitude} in {sign}').format(
229+
formatted = _('{name} {longitude} in {sign}').format(
238230
name=self.name,
239231
longitude=self.sign_longitude,
240232
sign=self.sign,
241233
)
242234

235+
if hasattr(self, 'house'):
236+
formatted += f', {_(self.house)}'
237+
238+
if hasattr(self, 'movement'):
239+
formatted += f', {_(self.movement)}'
240+
241+
return formatted
242+
243243

244244
class ObjectMovement:
245245
def __init__(self, object: dict) -> None:

locales/immanuel.pot

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,6 @@ msgstr ""
539539
msgid "{name} {longitude} in {sign}"
540540
msgstr ""
541541

542-
# For objects in signs and houses, eg. Sun 10°37'26" in Capricorn, 11th House
543-
msgid "{name} {longitude} in {sign}, {house}"
544-
msgstr ""
545-
546542
# For chart subjects, eg. Sat Jan 01 2000 10:00:00 AM PST at 32N43.0, 117W9.0
547543
msgid "{date_time} at {lat}, {lon}"
548544
msgstr ""

locales/pt_BR/LC_MESSAGES/immanuel.po

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,6 @@ msgstr "{type} entre {active} e {passive} dentro de {difference} ({movement}, {c
606606
msgid "{name} {longitude} in {sign}"
607607
msgstr "{name} {longitude} em {sign}"
608608

609-
# For objects in signs and houses, eg. Sun 10°37'26" in Capricorn, 11th House
610-
msgid "{name} {longitude} in {sign}, {house}"
611-
msgstr "{name} {longitude} em {sign}, {house}"
612-
613609
# For chart subjects, eg. Sat Jan 01 2000 10:00:00 AM PST at 32N43.0, 117W9.0
614610
msgid "{date_time} at {lat}, {lon}"
615611
msgstr "{date_time} em {lat}, {lon}"

tests/test_localization.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,9 @@ def test_formatted_aspect(native):
498498
def test_formatted_object(native):
499499
settings.locale = 'pt_BR'
500500
natal = charts.Natal(native)
501-
assert str(natal.objects[chart.SUN]) == 'Sol 10°37\'26" em Capricórnio, Casa 11'
501+
assert str(natal.objects[chart.SUN]) == 'Sol 10°37\'26" em Capricórnio, Casa 11, Direto'
502+
assert str(natal.objects[chart.ASC]) == 'Ascendente 05°36\'38" em Peixes, Casa 1'
503+
assert str(natal.houses[chart.HOUSE2]) == 'Casa 2 17°59\'40" em Áries'
502504

503505

504506
def test_formatted_subject(native):

0 commit comments

Comments
 (0)