Skip to content

Commit

Permalink
refactor plural forms
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhenjaHorbach committed Sep 26, 2024
1 parent 12b3b41 commit a36a304
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3663,7 +3663,7 @@ const translations = {
trackTax: 'Track tax',
deleteRates: () => ({
one: 'Delete rate',
other: () => `Delete rates`,
other: 'Delete rates',
}),
enableRates: ({count}: DistanceRateOperationsParams) => `Enable ${Str.pluralize('rate', 'rates', count)}`,
disableRates: ({count}: DistanceRateOperationsParams) => `Disable ${Str.pluralize('rate', 'rates', count)}`,
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3713,7 +3713,7 @@ const translations = {
trackTax: 'Impuesto de seguimiento',
deleteRates: () => ({
one: 'Eliminar tasa',
other: () => `Eliminar tasas`,
other: 'Eliminar tasas',
}),
enableRates: ({count}: DistanceRateOperationsParams) => `Activar ${Str.pluralize('tasa', 'tasas', count)}`,
disableRates: ({count}: DistanceRateOperationsParams) => `Desactivar ${Str.pluralize('tasa', 'tasas', count)}`,
Expand Down
7 changes: 4 additions & 3 deletions src/languages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import type en from './en';

type PluralParams = {count: number};
type PluralHandler = ((count: number) => string) | string;
type PluralForm = {
zero?: string;
one: string;
two?: string;
few?: (count: number) => string;
many?: (count: number) => string;
other: (count: number) => string;
few?: PluralHandler;
many?: PluralHandler;
other: PluralHandler;
};

/**
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Localize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ function getTranslatedPhrase<TKey extends TranslationPaths>(
return pluralResult(phraseObject.count);
}

if (typeof translateResult.other === 'string') {
return translateResult.other;
}

return translateResult.other(phraseObject.count);
}

Expand Down

0 comments on commit a36a304

Please sign in to comment.