Commit 57ce67d
Fix diff_for_humans crashing for the zh locale
zh/custom.py used a NAMED placeholder in "after"/"before" ("{time}后",
"{time}前") while DifferenceFormatter.format() substitutes positionally
(difference_formatter.py:115,159 call locale.get(key).format(time)).
So the two-datetime form raises KeyError: 'time' for every unit:
a.diff_for_humans(b, locale="zh") -> KeyError: 'time'
All 28 other locales use "{0}". zh is switched to match; no code change.
The relative-to-now form was unaffected because it reads the CLDR
translations table rather than these custom entries, and there was no
tests/localization/test_zh.py at all, so nothing exercised this path.
Adds that test file, covering the relative-to-now form and the
two-datetime form that was crashing.1 parent bd89085 commit 57ce67d
2 files changed
Lines changed: 47 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
0 commit comments