Skip to content

Commit af6c135

Browse files
authored
Improve the translation process and add instructions for new language support in the Contribution Guide (#331)
* Added Locale Names in Comments for Supported Locales * Update the datatables english translation file * Update the datatables french translation file * Add a script to auto download datatable,flatpickr and flatpickr localization file * Recompile the POT files * Adding Instructions for New Language Support in the Contribution Guide * Fix typo
1 parent 855a71c commit af6c135

File tree

10 files changed

+474
-117
lines changed

10 files changed

+474
-117
lines changed

CONTRIBUTING.md

+110-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to StarletteAdmin
1+
# Contributing to *starlette-admin*
22

33
First off, thanks for taking the time to contribute! ❤️
44

@@ -22,6 +22,7 @@ community looks forward to your contributions. 🎉
2222
- [Reporting Bugs](#reporting-bugs)
2323
- [Suggesting Enhancements](#suggesting-enhancements)
2424
- [Your First Code Contribution](#your-first-code-contribution)
25+
- [Adding support for a new locale](#adding-support-for-a-new-locale)
2526
- [Improving The Documentation](#improving-the-documentation)
2627

2728
## Code of Conduct
@@ -104,7 +105,7 @@ Once it's filed:
104105

105106
### Suggesting Enhancements
106107

107-
This section guides you through submitting an enhancement suggestion for StarletteAdmin, **including completely new
108+
This section guides you through submitting an enhancement suggestion for *starlette-admin*, **including completely new
108109
features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the
109110
community to understand your suggestion and find related suggestions.
110111

@@ -133,43 +134,50 @@ Enhancement suggestions are tracked as [GitHub issues](https://github.com/jowilf
133134
and Windows, and [this tool](https://github.com/colinkeenan/silentcast)
134135
or [this tool](https://github.com/GNOME/byzanz) on
135136
Linux.
136-
- **Explain why this enhancement would be useful** to most StarletteAdmin users. You may also want to point out the
137+
- **Explain why this enhancement would be useful** to most *starlette-admin* users. You may also want to point out the
137138
other projects that solved it better and which could serve as inspiration.
138139

139-
140140
### Your First Code Contribution
141141

142142
#### Setting up the development environment
143143

144-
We assume you are familiar with the general forking and pull request workflow for submitting to open-source projects. A
145-
complete guides is available [here](https://docs.github.com/en/get-started/quickstart/contributing-to-projects).
144+
Before you start contributing to *starlette-admin*, ensure you have a proper development environment set up. Familiarize
145+
yourself with the open-source contribution workflow by following the guidelines
146+
available [here](https://docs.github.com/en/get-started/quickstart/contributing-to-projects).
146147

147-
StarletteAdmin uses [hatch](https://hatch.pypa.io/) to manage dependencies and packaging.
148+
To manage dependencies and packaging for *starlette-admin*, we use [hatch](https://hatch.pypa.io/). Please make sure to
149+
install it globally.
148150

149-
Make sure hatch is installed globally:
151+
For example, you can install Hatch using pip:
150152

151153
```shell
152154
pip install hatch
153155
```
154156

155-
#### Format
157+
For more detailed installation instructions, refer to the [Hatch documentation](https://hatch.pypa.io/latest/install/)
158+
159+
#### Code Linting & Formatting
156160

157-
To ensure code consistency StarletteAdmin uses [black](https://github.com/psf/black)
158-
and [ruff](https://github.com/charliermarsh/ruff)
161+
To maintain code consistency, ensure proper code formatting, and enforce type safety, *starlette-admin*
162+
uses [black](https://github.com/psf/black), [mypy](https://mypy-lang.org/)
163+
and [ruff](https://github.com/charliermarsh/ruff).
159164

160-
To clean all your code, run
165+
Run the following command to format your code:
161166

162167
```shell
163168
hatch run format
164169
```
165170

166-
#### Testing
171+
To perform linting checks, run:
167172

168-
StarletteAdmin uses [pytest](https://docs.pytest.org) for unit testing. To ensure the stability of StarletteAdmin, each
169-
added feature
170-
must be tested in a separate unit test.
173+
```shell
174+
hatch run test:lint
175+
```
171176

172-
To run the test suite
177+
#### Testing
178+
179+
We use [pytest](https://docs.pytest.org) for unit testing. To ensure the stability of *starlette-admin*,
180+
every new feature must be tested in a separate unit test. Run the test suite to validate your changes:
173181

174182
```shell
175183
hatch run test:all
@@ -190,17 +198,99 @@ It is natural that your branch might contain multiple commits, so you will need
190198
Instructions can be
191199
found [here](https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/managing-commits/squashing-commits)
192200

201+
### Adding support for a new locale
202+
203+
*starlette-admin* relies on [babel](https://babel.pocoo.org/) for internationalization
204+
and localization.
205+
206+
#### Current supported locales
207+
208+
The `SUPPORTED_LOCALES` variable in the [i18n.py](./starlette_admin/i18n.py) module contains the list of locales
209+
currently supported.
210+
211+
#### Step-By-Step Guide
212+
213+
##### Step 1: Initialize the new locale
214+
215+
To add support for a new locale, the first thing to do is to run the initialization script:
216+
217+
```shell
218+
# replace <locale> by the new locale
219+
hatch run i18n:init --locale <locale>
220+
221+
# use --help to see all available options
222+
```
223+
224+
##### Step 2: Translate Messages
225+
226+
* Update all the `msgstr` keys in the POT file located
227+
at `./starlette_admin/translations/<locale>/LC_MESSAGES/admin.po`.
228+
Translate these messages to your target language.
229+
230+
Example (French):
231+
232+
```po
233+
msgid "Are you sure you want to delete selected items?"
234+
msgstr "Êtes-vous sûr de vouloir supprimer ces éléments?"
235+
```
236+
237+
* Check and update the generated JSON file for datatables located at `./starlette_admin/statics/i18n/dt/<locale>.json`.
238+
Most of
239+
the time, you will only need to update the `starlette-admin` key, which is internal to *starlette-admin*
240+
241+
Example (French):
242+
243+
```json5
244+
{
245+
// ...
246+
"starlette-admin": {
247+
"buttons": {
248+
"export": "Export"
249+
},
250+
"conditions": {
251+
"false": "Faux",
252+
"true": "Vrai",
253+
"empty": "Vide",
254+
"notEmpty": "Non vide"
255+
}
256+
},
257+
// ...
258+
}
259+
```
260+
261+
##### Step 3: Update the supported locales
262+
263+
Make sure to update the `SUPPORTED_LOCALES` variable in the [i18n.py](./starlette_admin/i18n.py) module to
264+
include the new locale.
265+
266+
#### Step 4: Compile the new message catalogs
267+
268+
After translating the messages, compile the POT file into a binary MO file using the following command:
269+
270+
```shell
271+
# replace <locale> by the new locale
272+
hatch run i18n:compile -l <locale>
273+
```
274+
275+
#### Step 5: Test the New Locale
276+
277+
To ensure that your new locale can be fully loaded by *starlette-admin*, include the new locale in
278+
the `test_default_locale`
279+
unit test in the [test_i18n](./tests/test_i18n.py) module.
280+
193281
### Improving The Documentation
194282

195283
Please write clear documentation for any new functionality you add. Docstrings will be converted to the API
196284
documentation, but more human friendly documentation might also be needed.
197285

198-
The documentation is generated using [mkdocs](https://www.mkdocs.org/). To see a preview of any edits you make you can run:
286+
The documentation is generated using [mkdocs](https://www.mkdocs.org/).
287+
To preview your documentation locally, run:
199288

200289
```shell
201-
hatch run docs
290+
hatch run docs:serve
202291
```
203-
and visit the printed address (usually localhost:8080) in your browser
292+
293+
and visit http://localhost:8080 in your browser to see a live preview of your documentation.
204294

205295
## Attribution
206296

i18n/init.sh

-4
This file was deleted.

0 commit comments

Comments
 (0)