Skip to content

Commit ece3798

Browse files
committed
feat/fix/docs: improve examples, add i18n support, refactor project docs gen, improve docs
1 parent 4e28ad6 commit ece3798

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+727
-1803
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
commit 4e28ad68cf51d8c8bfe4f1ee235f8e5586a8caa5
2+
Author: alexeev-prog <[email protected]>
3+
Date: Mon Nov 4 00:41:13 2024 +0700
4+
5+
docs: update docs
6+
17
commit 6a0d6d16a6386a1c22a3a3d497cd5635451d3e38
28
Author: alexeev-prog <[email protected]>
39
Date: Mon Nov 4 00:37:09 2024 +0700

docs/en/i18n_locales.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# pyEchoNext / i18n - localization
2+
3+
---
4+
5+
pyEchoNext since version 0.5.3 supports i18n (so far in its basic form).
6+
7+
i18n is an abbreviation for internationalization process.
8+
9+
Internationalization is the process of developing an application in which its code is independent of any linguistic and cultural characteristics of the region or country. As a result, the application becomes flexible and can easily adapt to different language and cultural settings.
10+
11+
Internationalization implementation usually begins in the early stages of a project to prepare the product for future localization. During this process, they determine what will change for future locales (for example, text, images) and export this data to external files.
12+
13+
The 18 in i18n stands for the number of letters between the first letter i and the last letter n in the word "internationalization".
14+
15+
In pyEchoNext this is implemented like this: a Response is created, if you need to use i18n for localization, use the use_i18n flag:
16+
17+
```python
18+
from pyechonext.response import Request, Response
19+
20+
# create a request...
21+
# request = ...
22+
23+
response = Response(request, body='title', use_i18n=True)
24+
```
25+
26+
This will signal to the application that i18n should be used in this Response. And the application will translate your phrase.
27+
28+
## Creating localizations
29+
You pass the required Settings parameter to the application. It has two fields related to localization:
30+
31+
+ `LOCALE: str = "DEFAULT"`
32+
+ `LOCALE_DIR: str = None`
33+
34+
By default they create the default locale. It looks like this:
35+
36+
```python
37+
DEFAULT_LOCALE = {
38+
"title": "pyEchoNext Example Website",
39+
"description": "This web application is an example of the pyEchonext web framework.",
40+
}
41+
```
42+
43+
That is, if we enter only title or only description in response.body, we will end up with the phrase “pyEchoNext Example Website” or “This web application is an example of the pyEchoNext web framework.”.
44+
45+
But how to create your own locales? It's simple. Create a directory with locale files, we recommend locales, and localization json files in it. Let's say RU_RU.json:
46+
47+
```json
48+
{
49+
"title": "pyEchoNext Web application with locale",
50+
"example one": "example one"
51+
}
52+
```
53+
54+
And already in Settings we specify the following settings:
55+
56+
+ `LOCAL = "RU_RU"`
57+
+ `LOCALE_DIR = "locales"`
58+
59+
Or through the settings loader (in this example, through the python module, you can see [how to use the settings loader](./webapp_creation.md)):
60+
61+
```python
62+
from pyechonext.config import SettingsLoader, SettingsConfigType
63+
64+
config_loader = SettingsLoader(SettingsConfigType.PYMODULE, 'el_config.py')
65+
settings = config_loader.get_settings()
66+
echonext = EchoNext(
67+
__name__,
68+
settings,
69+
middlewares,
70+
urls=url_patterns,
71+
application_type=ApplicationType.HTML,
72+
)
73+
```
74+
75+
el_config.py:
76+
77+
```python
78+
import os
79+
80+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
81+
TEMPLATES_DIR = 'templates'
82+
SECRET_KEY = 'secret-key'
83+
LOCAL = 'RU_RU'
84+
LOCALE_DIR = 'locales'
85+
```
86+
87+
The LOCALE value must be the same as the file name. If RU_RU, then the file should be RU_RU.json.
88+
89+
And now you can introduce internationalization to your application!
90+
91+
> At the time of version 0.5.3 i18n is under development, many features will be added later. The plans include: dividing the site localization into several files, more convenient handling of i18n and the ability to change localization on the fly. We plan to be inspired by [this documentation](https://developer.mozilla.org/ru/docs/Mozilla/Add-ons/WebExtensions/Internationalization), reworking it for our web framework.
92+
93+
---
94+
95+
[Contents](./index.md)

docs/en/index.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
## Content
44

55
1. [Web framework design](./webframework_design.md)
6-
76
2. [Creating a web application](./webapp_creation.md)
8-
97
3. [Creating routes (routes&views)](./routes_and_views.md)
10-
118
4. [Request/Response](./requests_responses.md)
9+
5. [i18n](./i18n_locales.md)
1210

1311
## Additional materials
1412

1513
+ [ASGI Documentation](https://asgi.readthedocs.io/_/downloads/en/stable/pdf/)
16-
1714
+ [PEP 333](https://peps.python.org/pep-0333/#the-application-framework-side)

0 commit comments

Comments
 (0)