@@ -4,7 +4,7 @@ Pluralize is a Python library for Internationalization (i18n) and Pluralization.
4
4
5
5
The library assumes a folder (for exaple "translations") that contains files like:
6
6
7
- ```
7
+ ``` sh
8
8
it.json
9
9
it-IT.json
10
10
fr.json
@@ -14,7 +14,7 @@ fr-FR.json
14
14
15
15
Each file has the following structure, for example for Italian (it.json):
16
16
17
- ```
17
+ ``` json
18
18
{"dog" : {"0" : " no cane" , "1" : " un cane" , "2" : " {n} cani" , "10" : " tantissimi cani" }}
19
19
```
20
20
@@ -23,13 +23,13 @@ Different translations correspond to different plural forms of the expression,
23
23
24
24
Here is another example for the word "bed" in Czech
25
25
26
- ```
26
+ ``` json
27
27
{"bed" : {"0" : " no postel" , "1" : " postel" , "2" : " postele" , "5" : " postelí" }}
28
28
```
29
29
30
30
To translate and pluralize a string "dog" one simply wraps the string in the T operator as follows:
31
31
32
- ```
32
+ ``` python
33
33
>> > from pluralize import Translator
34
34
>> > T = Translator(' translations' )
35
35
>> > dog = T(" dog" )
@@ -58,23 +58,23 @@ T.select(s) can parse a string s following the HTTP accept language format.
58
58
## Update the translation files
59
59
60
60
Find all strings wrapped in T(...) in .py, .html, and .js files:
61
- ```
61
+ ``` python
62
62
matches = T.find_matches(' path/to/app/folder' )
63
63
```
64
64
65
65
Add newly discovered entries in all supported languages
66
- ```
66
+ ``` python
67
67
T.update_languages(matches)
68
68
```
69
69
70
70
Add a new supported language (for example german, "de")
71
71
72
- ```
72
+ ``` python
73
73
T.languages[' de' ] = {}
74
74
```
75
75
76
76
Make sure all languages contain the same origin expressions
77
- ```
77
+ ``` python
78
78
known_expressions = set ()
79
79
for language in T.languages.values():
80
80
for expression in language:
@@ -84,6 +84,6 @@ T.update_languages(known_expressions))
84
84
85
85
Finally save the changes:
86
86
87
- ```
87
+ ``` python
88
88
T.save(' translations' )
89
89
```
0 commit comments