From 7c8dec4b2104834dec5fe79676034e436a50b1ac Mon Sep 17 00:00:00 2001 From: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com> Date: Tue, 13 Jun 2023 12:08:18 -0700 Subject: [PATCH] Add noOneChoice icu rule and fix broken string --- _locales/en/messages.json | 2 +- build/intl-linter/linter.ts | 23 ++++++++++++++++++----- build/intl-linter/rules/noOneChoice.ts | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 build/intl-linter/rules/noOneChoice.ts diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 17993bb8adec..2dd1f1c74882 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -5083,7 +5083,7 @@ "description": "aria-label for reaction emoji when one person reacts with an emoji" }, "icu:Message__reaction-emoji-label--many": { - "messageformat": "{count, plural, other {# people}} reacted with {emoji}", + "messageformat": "{count, number} people reacted with {emoji}", "description": "Used as an aria-label for when many people react to a message. Count is always greater than 1" }, "icu:Message__role-description": { diff --git a/build/intl-linter/linter.ts b/build/intl-linter/linter.ts index 58c8e0a1fbbe..7f6355a56ddc 100644 --- a/build/intl-linter/linter.ts +++ b/build/intl-linter/linter.ts @@ -18,6 +18,7 @@ import onePlural from './rules/onePlural'; import noLegacyVariables from './rules/noLegacyVariables'; import noNestedChoice from './rules/noNestedChoice'; import noOffset from './rules/noOffset'; +import noOneChoice from './rules/noOneChoice'; import noOrdinal from './rules/noOrdinal'; import pluralPound from './rules/pluralPound'; @@ -26,6 +27,7 @@ const RULES = [ noLegacyVariables, noNestedChoice, noOffset, + noOneChoice, noOrdinal, onePlural, pluralPound, @@ -38,23 +40,34 @@ type Test = { const tests: Record = { 'icu:err1': { - messageformat: '{a, plural, other {a}} {b, plural, other {b}}', + messageformat: + '{a, plural, one {a} other {as}} {b, plural, one {b} other {bs}}', expectErrors: ['onePlural'], }, 'icu:err2': { - messageformat: '{a, plural, other {{b, plural, other {b}}}}', + messageformat: + '{a, plural, one {a} other {{b, plural, one {b} other {bs}}}}', expectErrors: ['noNestedChoice', 'onePlural'], }, 'icu:err3': { - messageformat: '{a, select, other {{b, select, other {b}}}}', + messageformat: + '{a, select, one {a} other {{b, select, one {b} other {bs}}}}', expectErrors: ['noNestedChoice'], }, 'icu:err4': { - messageformat: '{a, plural, offset:1 other {a}}', + messageformat: '{a, plural, offset:1 one {a} other {as}}', expectErrors: ['noOffset'], }, + 'icu:noOneChoice:1': { + messageformat: '{a, plural, other {a}}', + expectErrors: ['noOneChoice'], + }, + 'icu:noOneChoice:2': { + messageformat: '{a, plural}', + expectErrors: ['noOneChoice'], + }, 'icu:err5': { - messageformat: '{a, selectordinal, other {a}}', + messageformat: '{a, selectordinal, one {a} other {as}}', expectErrors: ['noOrdinal'], }, 'icu:err6': { diff --git a/build/intl-linter/rules/noOneChoice.ts b/build/intl-linter/rules/noOneChoice.ts new file mode 100644 index 000000000000..a4d5faa97a8f --- /dev/null +++ b/build/intl-linter/rules/noOneChoice.ts @@ -0,0 +1,17 @@ +// Copyright 2022 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import { rule } from '../utils/rule'; + +export default rule('noOneChoice', context => { + return { + enterPlural(element) { + if (Object.keys(element.options).length < 2) { + context.report( + '{plural} requires multiple options for Smartling', + element.location + ); + } + }, + }; +});