Skip to content

Commit 3abaf89

Browse files
committed
fix: use Turkish numeric separators
1 parent 785e5dc commit 3abaf89

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
@@ -124,6 +124,12 @@ def test_intcomma() -> None:
124124
humanize.i18n.activate("pt_BR")
125125
assert humanize.intcomma(number) == "10.000.000"
126126

127+
humanize.i18n.activate("tr_TR")
128+
assert humanize.intcomma(number) == "10.000.000"
129+
assert humanize.intcomma(1_234_567.89) == "1.234.567,89"
130+
assert humanize.intcomma("1234567,89") == "1.234.567,89"
131+
assert humanize.intcomma("1.234.567,89") == "1.234.567,89"
132+
127133
except FileNotFoundError:
128134
pytest.skip("Generate .mo with scripts/generate-translation-binaries.sh")
129135

@@ -159,6 +165,9 @@ def test_naturaldelta() -> None:
159165
("it_IT", 1_200_000, "1,2 milioni"),
160166
("it_IT", 1_000_000_000, "1,0 miliardo"),
161167
("it_IT", 3_500_000_000, "3,5 miliardi"),
168+
# Turkish uses comma as decimal separator
169+
("tr_TR", 1_000_000, "1,0 milyon"),
170+
("tr_TR", 1_200_000, "1,2 milyon"),
162171
# Sinhala uses borrowed scale words with a dot decimal separator
163172
("si_LK", 1_000_000, "1.0 මිලියන"),
164173
("si_LK", 1_200_000, "1.2 මිලියන"),

0 commit comments

Comments
 (0)