From 082b7ecd913c72974fd88537b8dd443e07f8ccaf Mon Sep 17 00:00:00 2001 From: grdddj Date: Tue, 26 Oct 2021 12:19:56 +0200 Subject: [PATCH] feat(core): plural function supports "key/keys" string Previously function did not work for words ending with "y" and vowel before that --- core/src/trezor/strings.py | 3 ++- core/tests/test_trezor.strings.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/trezor/strings.py b/core/src/trezor/strings.py index de83372c4..fa1fc7839 100644 --- a/core/src/trezor/strings.py +++ b/core/src/trezor/strings.py @@ -39,7 +39,8 @@ def format_plural(string: str, count: int, plural: str) -> str: raise ValueError if count == 0 or count > 1: - if plural[-1] == "y": + # candy -> candies, but key -> keys + if plural[-1] == "y" and plural[-2] not in "aeiouy": plural = plural[:-1] + "ies" elif plural[-1] in "hsxz": plural = plural + "es" diff --git a/core/tests/test_trezor.strings.py b/core/tests/test_trezor.strings.py index 4ac14e158..266b4b37b 100644 --- a/core/tests/test_trezor.strings.py +++ b/core/tests/test_trezor.strings.py @@ -17,10 +17,12 @@ class TestStrings(unittest.TestCase): def test_format_plural(self): VECTORS = [ - ("We need {count} more {plural}", 3, "share", "We need 3 more shares"), ("We need {count} more {plural}", 1, "share", "We need 1 more share"), + ("We need {count} more {plural}", 3, "share", "We need 3 more shares"), ("We need {count} more {plural}", 1, "candy", "We need 1 more candy"), ("We need {count} more {plural}", 7, "candy", "We need 7 more candies"), + ("We need {count} more {plural}", 1, "key", "We need 1 more key"), + ("We need {count} more {plural}", 5, "key", "We need 5 more keys"), ("We need {count} more {plural}", 1, "hash", "We need 1 more hash"), ("We need {count} more {plural}", 2, "hash", "We need 2 more hashes"), ("We need {count} more {plural}", 1, "fuzz", "We need 1 more fuzz"),