Skip to content

Commit

Permalink
feat: make other form optional (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirfilosof authored May 4, 2024
1 parent a25cea2 commit cec6a95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/plural/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ export function getPluralViaIntl(key: string, value: PluralValue, count: number,
}

const pluralRules = new Intl.PluralRules(lang);
return value[pluralRules.select(count)] || value.other;

const form = pluralRules.select(count);

if (form === 'other' && typeof value.other === 'undefined') {
return value.many || value.few;
}

return value[form] || value.other;
}

type FormatPluralArgs = {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export type PluralValue = {
two?: string;
few?: string;
many?: string;
other: string;
other?: string;
}

export function isPluralValue(value: KeyData): value is DeprecatedPluralValue | PluralValue {
Expand Down

0 comments on commit cec6a95

Please sign in to comment.