1
- # Contributing to StarletteAdmin
1
+ # Contributing to * starlette-admin *
2
2
3
3
First off, thanks for taking the time to contribute! ❤️
4
4
@@ -22,6 +22,7 @@ community looks forward to your contributions. 🎉
22
22
- [ Reporting Bugs] ( #reporting-bugs )
23
23
- [ Suggesting Enhancements] ( #suggesting-enhancements )
24
24
- [ Your First Code Contribution] ( #your-first-code-contribution )
25
+ - [ Adding support for a new locale] ( #adding-support-for-a-new-locale )
25
26
- [ Improving The Documentation] ( #improving-the-documentation )
26
27
27
28
## Code of Conduct
@@ -104,7 +105,7 @@ Once it's filed:
104
105
105
106
### Suggesting Enhancements
106
107
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
108
109
features and minor improvements to existing functionality** . Following these guidelines will help maintainers and the
109
110
community to understand your suggestion and find related suggestions.
110
111
@@ -133,43 +134,50 @@ Enhancement suggestions are tracked as [GitHub issues](https://github.com/jowilf
133
134
and Windows, and [ this tool] ( https://github.com/colinkeenan/silentcast )
134
135
or [ this tool] ( https://github.com/GNOME/byzanz ) on
135
136
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
137
138
other projects that solved it better and which could serve as inspiration.
138
139
139
-
140
140
### Your First Code Contribution
141
141
142
142
#### Setting up the development environment
143
143
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 ) .
146
147
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.
148
150
149
- Make sure hatch is installed globally :
151
+ For example, you can install Hatch using pip :
150
152
151
153
``` shell
152
154
pip install hatch
153
155
```
154
156
155
- #### Format
157
+ For more detailed installation instructions, refer to the [ Hatch documentation] ( https://hatch.pypa.io/latest/install/ )
158
+
159
+ #### Code Linting & Formatting
156
160
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 ) .
159
164
160
- To clean all your code, run
165
+ Run the following command to format your code:
161
166
162
167
``` shell
163
168
hatch run format
164
169
```
165
170
166
- #### Testing
171
+ To perform linting checks, run:
167
172
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
+ ```
171
176
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:
173
181
174
182
``` shell
175
183
hatch run test:all
@@ -190,17 +198,99 @@ It is natural that your branch might contain multiple commits, so you will need
190
198
Instructions can be
191
199
found [ here] ( https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/managing-commits/squashing-commits )
192
200
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
+
193
281
### Improving The Documentation
194
282
195
283
Please write clear documentation for any new functionality you add. Docstrings will be converted to the API
196
284
documentation, but more human friendly documentation might also be needed.
197
285
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:
199
288
200
289
``` shell
201
- hatch run docs
290
+ hatch run docs:serve
202
291
```
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.
204
294
205
295
## Attribution
206
296
0 commit comments