Add noOneChoice icu rule and fix broken string

This commit is contained in:
Jamie Kyle 2023-06-13 12:08:18 -07:00 committed by GitHub
parent 5c1b5dcad8
commit 7c8dec4b21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 6 deletions

View file

@ -5083,7 +5083,7 @@
"description": "aria-label for reaction emoji when one person reacts with an emoji" "description": "aria-label for reaction emoji when one person reacts with an emoji"
}, },
"icu:Message__reaction-emoji-label--many": { "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" "description": "Used as an aria-label for when many people react to a message. Count is always greater than 1"
}, },
"icu:Message__role-description": { "icu:Message__role-description": {

View file

@ -18,6 +18,7 @@ import onePlural from './rules/onePlural';
import noLegacyVariables from './rules/noLegacyVariables'; import noLegacyVariables from './rules/noLegacyVariables';
import noNestedChoice from './rules/noNestedChoice'; import noNestedChoice from './rules/noNestedChoice';
import noOffset from './rules/noOffset'; import noOffset from './rules/noOffset';
import noOneChoice from './rules/noOneChoice';
import noOrdinal from './rules/noOrdinal'; import noOrdinal from './rules/noOrdinal';
import pluralPound from './rules/pluralPound'; import pluralPound from './rules/pluralPound';
@ -26,6 +27,7 @@ const RULES = [
noLegacyVariables, noLegacyVariables,
noNestedChoice, noNestedChoice,
noOffset, noOffset,
noOneChoice,
noOrdinal, noOrdinal,
onePlural, onePlural,
pluralPound, pluralPound,
@ -38,23 +40,34 @@ type Test = {
const tests: Record<string, Test> = { const tests: Record<string, Test> = {
'icu:err1': { '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'], expectErrors: ['onePlural'],
}, },
'icu:err2': { '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'], expectErrors: ['noNestedChoice', 'onePlural'],
}, },
'icu:err3': { 'icu:err3': {
messageformat: '{a, select, other {{b, select, other {b}}}}', messageformat:
'{a, select, one {a} other {{b, select, one {b} other {bs}}}}',
expectErrors: ['noNestedChoice'], expectErrors: ['noNestedChoice'],
}, },
'icu:err4': { 'icu:err4': {
messageformat: '{a, plural, offset:1 other {a}}', messageformat: '{a, plural, offset:1 one {a} other {as}}',
expectErrors: ['noOffset'], expectErrors: ['noOffset'],
}, },
'icu:noOneChoice:1': {
messageformat: '{a, plural, other {a}}',
expectErrors: ['noOneChoice'],
},
'icu:noOneChoice:2': {
messageformat: '{a, plural}',
expectErrors: ['noOneChoice'],
},
'icu:err5': { 'icu:err5': {
messageformat: '{a, selectordinal, other {a}}', messageformat: '{a, selectordinal, one {a} other {as}}',
expectErrors: ['noOrdinal'], expectErrors: ['noOrdinal'],
}, },
'icu:err6': { 'icu:err6': {

View file

@ -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
);
}
},
};
});