Skip to content

Commit 203fea1

Browse files
CalinouYngwarr
andcommitted
Document built-in plural rules in Localization using spreadsheets
Godot provides built-in plural rules which are automatically used when no plural rules are defined in the CSV file. In most cases, there is no need to have a `?pluralrule` row in the CSV file. Co-authored-by: Yngvarr <k.yngvarr@gmail.com>
1 parent 50cd88b commit 203fea1

4 files changed

Lines changed: 243 additions & 2 deletions

File tree

tutorials/i18n/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Internationalization
1212
localization_using_gettext
1313
locales
1414
pseudolocalization
15+
plural_rules

tutorials/i18n/locales.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Locale code has the following format: ``language_Script_COUNTRY_VARIANT``, where
1212
- ``COUNTRY`` - optional, 2-letter country code, in upper case.
1313
- ``VARIANT`` - optional, language variant, region and, sort order. A variant can have any number of underscored keywords.
1414

15+
.. seealso::
16+
17+
See :ref:`doc_plural_rules` for a list of built-in plural rules.
18+
1519
List of supported language codes
1620
--------------------------------
1721

tutorials/i18n/localization_using_spreadsheets.rst

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,30 @@ This is done by adding a column named ``?plural`` anywhere in the table
8484
(except on the first column, which is reserved for translation keys).
8585
By convention, it's recommended to place it on the second column.
8686
Note that in the example below, the key column is the one that contains English
87-
localization.
87+
localization (``en``).
88+
89+
Godot provides :ref:`built-in plural rules <doc_plural_rules>`
90+
for most languages. In most cases, you don't need to provide a row that
91+
defines custom plural rules:
92+
93+
.. code-block:: none
94+
95+
en,?plural,fr,ru,ja,zh
96+
There is %d apple,There are %d apples,Il y a %d pomme,Есть %d яблоко,リンゴが%d個あります,那里有%d个苹果
97+
,,Il y a %d pommes,Есть %d яблока,,
98+
,,,Есть %d яблок,,
99+
100+
Notice how the above CSV contains empty columns for some languages. This is
101+
because the number of plural forms differs between languages. In the example
102+
above, English has 2 plural forms, French has 2 plural forms, Russian has 3
103+
plural forms, and Japanese and Chinese have no plural forms. The CSV format
104+
allows you to specify only the plural forms that are needed for each language.
105+
106+
If you need to specify a custom plural rule, you can do so by adding a row with
107+
the ``?pluralrule`` key. The value of this key should be the plural rule in the
108+
format used by gettext, for example: ``nplurals=2; plural=(n != 1);``.
109+
Certain languages can have their plural rule omitted to use the built-in plural rule.
110+
The column for the ``?plural`` hint should be left empty in the ``?pluralrule`` row.
88111

89112
.. code-block:: none
90113
@@ -97,7 +120,7 @@ localization.
97120
.. note::
98121

99122
Automatic Control translation is not supported when using plural forms. You must
100-
translate the string manually using :ref:`tr_n()<class_Object_method_tr_n>`.
123+
translate the string manually using :ref:`tr_n() <class_Object_method_tr_n>`.
101124

102125
Specifying translation contexts
103126
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tutorials/i18n/plural_rules.rst

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
.. _doc_plural_rules:
2+
3+
Plural rules
4+
~~~~~~~~~~~~
5+
6+
.. Note: This list should be synced with core/string/locales.h in the engine.
7+
8+
This is the full list of built-in plural rules available in Godot in human-readable form.
9+
See the `source code <https://github.com/godotengine/godot/blob/4.6.3-stable/core/string/locales.h#L1819-L1855>`__
10+
for their original gettext format form.
11+
12+
These plural rules are automatically used when no plural rule is specified in
13+
:ref:`CSV localization <doc_localization_using_spreadsheets>`. Plural forms are
14+
spelled out in the order they should be specified in the CSV file (from top to
15+
bottom).
16+
17+
.. tip::
18+
19+
Use your browser's search function (:kbd:`Ctrl + F` or :kbd:`Cmd + F`) to
20+
quickly find a specific language according to its
21+
:ref:`locale code <doc_locales>`.
22+
23+
Plural rules
24+
------------
25+
26+
- Languages with no plural forms (``bm bo dz hnj id ig ii in ja jbo jv jw kde kea km ko lkt lo ms my nqo osa root sah ses sg su th to tpi vi wo yo yue zh``):
27+
28+
- First form for all numbers.
29+
30+
- Languages with the same rules as English (``af an asa ast az bal bem bez bg brx ca ce cgg chr ckb da de dv ee el en eo es et eu fi fo fur fy gl gsw ha haw he hu ia io it jgo ji jmc ka kaj kcg kk kkj kl ks ksb ku ky lb lg lij mas mgo ml mn mr nah nb nd ne nl nn nnh no nr ny nyn om or os pap ps pt rm rof rwk saq sc sd sdh seh sn so sq ss ssy st sv sw syr ta te teo tig tk tn tr ts ug ur uz ve vo vun wae xh xog yi``):
31+
32+
- First form for 1.
33+
- Second form for 0, and for 2 and above.
34+
35+
- Languages with the same rules as French (``ak bho csw ff fr guw hy kab ln mg nso pa pt_BR si ti wa``):
36+
37+
- First form for 0 and 1.
38+
- Second form for 2 and above.
39+
40+
- Icelandic, Macedonian (``is mk``):
41+
42+
- First form when the last digit is 1 but the number is not 11.
43+
- Second form for all other numbers.
44+
45+
- Central Atlas Tamazight (``tzm``):
46+
47+
- First form for 0, 1, and all numbers from 11 to 99.
48+
- Second form for 2-10, and for 100 and above.
49+
50+
- Amharic, Assamese, Bengali, Dogri, Persian, Gujarati, Hindi, Kannada, Nigerian Pidgin, Zulu (``am as bn doi fa gu hi kn pcm zu``):
51+
52+
- First form for 2 and above.
53+
- Second form for 0 and 1.
54+
55+
- Cebuano, Filipino, Tagalog (``ceb fil tl``):
56+
57+
- First form for 1, 2, and 3, and for any number that does not end in 4, 6, or 9.
58+
- Second form for numbers ending in 4, 6, or 9.
59+
60+
- Prussian (``prg``):
61+
62+
- First form for numbers ending in 0 and for numbers 11-19.
63+
- Second form for numbers ending in 1, except 11.
64+
- Third form for all remaining numbers.
65+
66+
- Latvian (``lv``):
67+
68+
- First form for numbers ending in 1, except 11.
69+
- Second form for all non-zero numbers (including 11).
70+
- Third form for 0.
71+
72+
- Lithuanian (``lt``):
73+
74+
- First form for numbers ending in 1, except 11.
75+
- Second form for numbers ending in 2-9, excluding the teens (12-19).
76+
- Third form for 0, for the teens (10-19), and for numbers ending in 0.
77+
78+
- Belarusian, Croatian, Russian, Serbian, Ukrainian (``be hr ru sr uk``):
79+
80+
- First form for numbers ending in 1, except 11.
81+
- Second form for numbers ending in 2-4, except the teens (12-14).
82+
- Third form for everything else.
83+
84+
- Bosnian, Serbo-Croatian (``bs sh``):
85+
86+
- First form for numbers ending in 1, except 11.
87+
- Second form for numbers ending in 2-4, except 12-14.
88+
- Third form for everything else.
89+
90+
- Langi (``lag``):
91+
92+
- First form for 0.
93+
- Second form for 1.
94+
- Third form for 2 and above.
95+
96+
- Anii, Colognian (``blo ksh``):
97+
98+
- First form for 0.
99+
- Second form for 1.
100+
- Third form for 2 and above.
101+
102+
- Tachelhit (``shi``):
103+
104+
- First form for 0 and 1.
105+
- Second form for 2-10.
106+
- Third form for 11 and above.
107+
108+
- Polish (``pl``):
109+
110+
- First form for 1.
111+
- Second form for numbers ending in 2-4, except the teens (12-14).
112+
- Third form for everything else.
113+
114+
- Moldavian (``mo``):
115+
116+
- First form for 1.
117+
- Second form for 0 and for numbers whose last two digits are 01-19 (except when the number itself is exactly 1).
118+
- Third form for numbers whose last two digits are 00 or 20-99.
119+
120+
- Inuktitut, Hebrew, Nama, Northern Sami, Sami, Southern Sami, Lule Sami, Inari Sami, Santali, Skolt Sami (``iu iw naq sat se sma smi smj smn sms``):
121+
122+
- First form for 1.
123+
- Second form for 2.
124+
- Third form for everything else.
125+
126+
- Czech, Slovak (``cs sk``):
127+
128+
- First form for 1.
129+
- Second form for 2-4.
130+
- Third form for 0 and 5 and above.
131+
132+
- Romanian (``ro``):
133+
134+
- First form for 1.
135+
- Second form for 0 and for numbers whose last two digits are 01-19.
136+
- Third form for numbers whose last two digits are 00 or 20-99.
137+
138+
- Irish (``ga``):
139+
140+
- First form for 1.
141+
- Second form for 2.
142+
- Third form for everything else.
143+
144+
- Slovenian (``sl``):
145+
146+
- First form for numbers ending in 01.
147+
- Second form for numbers ending in 02.
148+
- Third form for numbers ending in 03 or 04.
149+
- Fourth form for everything else.
150+
151+
- Lower Sorbian, Upper Sorbian (``dsb hsb``):
152+
153+
- First form for numbers ending in 01.
154+
- Second form for numbers ending in 02.
155+
- Third form for numbers ending in 03 or 04.
156+
- Fourth form for everything else.
157+
158+
- Manx (``gv``):
159+
160+
- First form for numbers ending in 1.
161+
- Second form for numbers ending in 2.
162+
- Third form for numbers ending in 00, 20, 40, 60, or 80.
163+
- Fourth form for everything else.
164+
165+
- Scottish Gaelic (``gd``):
166+
167+
- First form for 1 and 11.
168+
- Second form for 2 and 12.
169+
- Third form for 3-10 and 13-19.
170+
- Fourth form for everything else (0 and 20+).
171+
172+
- Breton (``br``):
173+
174+
- First form for numbers ending in 1, except 11, 71, and 91.
175+
- Second form for numbers ending in 2, except 12, 72, and 92.
176+
- Third form for numbers ending in 3, 4, or 9, except those in the ranges 13-19, 73-79, and 93-99.
177+
- Fourth form for non-zero multiples of 1,000,000.
178+
- Fifth form for everything else.
179+
180+
- Maltese (``mt``):
181+
182+
- First form for 1.
183+
- Second form for 2.
184+
- Third form for 0 and for numbers ending in 03-10.
185+
- Fourth form for numbers ending in 11-19.
186+
- Fifth form for everything else.
187+
188+
- Cornish (``kw``):
189+
190+
- First form for 0.
191+
- Second form for 1.
192+
- Third form for numbers ending in 02, 22, 42, 62, or 82, and for certain round numbers.
193+
- Fourth form for numbers ending in 03, 23, 43, 63, or 83.
194+
- Fifth form for numbers ending in 01, 21, 41, 61, or 81 (except 1 itself).
195+
- Sixth form for everything else.
196+
197+
- Arabic, Najdi Arabic (``ar ars``):
198+
199+
- First form for 0.
200+
- Second form for 1.
201+
- Third form for 2.
202+
- Fourth form for numbers ending in 03-10.
203+
- Fifth form for numbers ending in 11-99.
204+
- Sixth form for numbers ending in 00, 01, or 02 (i.e., 100, 101, 102, 200, etc.).
205+
206+
- Welsh (``cy``):
207+
208+
- First form for 0.
209+
- Second form for 1.
210+
- Third form for 2.
211+
- Fourth form for 3.
212+
- Fifth form for 6.
213+
- Sixth form for everything else.

0 commit comments

Comments
 (0)