Skip to content

Commit a2006ea

Browse files
Use Turkish numeric separators (#465)
1 parent b5ba01b commit a2006ea

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,17 @@ How to change locale at runtime:
216216
'3 seconds ago'
217217
```
218218

219+
Number formatting also uses the locale's configured numeric separators:
220+
221+
```pycon
222+
>>> _t = humanize.i18n.activate("tr_TR")
223+
>>> humanize.intcomma(1_234_567.89)
224+
'1.234.567,89'
225+
>>> humanize.intword(1_200_000)
226+
'1,2 milyon'
227+
>>> humanize.i18n.deactivate()
228+
```
229+
219230
You can pass additional parameter `path` to `activate` to specify a path to search
220231
locales in.
221232

‎src/humanize/i18n.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"pt_BR": ".",
2727
"hu_HU": " ",
2828
"lv": " ",
29+
"tr_TR": ".",
2930
}
3031

3132
# Mapping of locale to decimal separator
@@ -36,6 +37,7 @@
3637
"pt_BR": ",",
3738
"hu_HU": ",",
3839
"lv": ",",
40+
"tr_TR": ",",
3941
}
4042

4143

‎tests/test_i18n.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ def test_intcomma() -> None:
149149
humanize.i18n.activate("pt_BR")
150150
assert humanize.intcomma(number) == "10.000.000"
151151

152+
humanize.i18n.activate("tr_TR")
153+
assert humanize.intcomma(number) == "10.000.000"
154+
assert humanize.intcomma(1_234_567.89) == "1.234.567,89"
155+
assert humanize.intcomma("1234567,89") == "1.234.567,89"
156+
assert humanize.intcomma("1.234.567,89") == "1.234.567,89"
157+
152158
except FileNotFoundError:
153159
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
154160

@@ -184,6 +190,9 @@ def test_naturaldelta() -> None:
184190
("it_IT", 1_200_000, "1,2 milioni"),
185191
("it_IT", 1_000_000_000, "1,0 miliardo"),
186192
("it_IT", 3_500_000_000, "3,5 miliardi"),
193+
# Turkish uses comma as decimal separator
194+
("tr_TR", 1_000_000, "1,0 milyon"),
195+
("tr_TR", 1_200_000, "1,2 milyon"),
187196
# Sinhala uses borrowed scale words with a dot decimal separator
188197
("si_LK", 1_000_000, "1.0 මිලියන"),
189198
("si_LK", 1_200_000, "1.2 මිලියන"),

0 commit comments

Comments
 (0)