From 3204211dbe269379b5b9ec4cbbe345e52fd5efa2 Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Thu, 12 Sep 2024 10:30:41 +1000 Subject: [PATCH] fix: plural regex --- ts/util/i18n/localizedString.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ts/util/i18n/localizedString.ts b/ts/util/i18n/localizedString.ts index 759ded8fb..f6f1508f9 100644 --- a/ts/util/i18n/localizedString.ts +++ b/ts/util/i18n/localizedString.ts @@ -89,13 +89,13 @@ export type StringArgsRecord = Record, string | // Above is testing stuff function getPluralKey(string: PluralString): R { - const match = /{(\w+), plural, one \[.+\] other \[.+\]}/g.exec(string); + const match = /{(\w+), plural, (zero|one|two|few|many|other) \[.+\]}/g.exec(string); return match?.[1] as R; } // TODO This regex is only going to work for the one/other case what about other langs where we can have one/two/other for example const isPluralForm = (localizedString: string): localizedString is PluralString => - /{\w+, plural, one \[.+\] other \[.+\]}/g.test(localizedString); + /{(\w+), plural, (zero|one|two|few|many|other) \[.+\]}/g.test(localizedString); /** * Checks if a string contains a dynamic variable.