Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make other form optional #49

Merged
merged 2 commits into from
May 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/plural/general.ts
Original file line number Diff line number Diff line change
@@ -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 = {
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -4,17 +4,17 @@

type NoEnumLikeStringLiteral<T> = string extends T ? T : never;

export type I18NFn<T = any> = {

Check warning on line 7 in src/types.ts

GitHub Actions / test

Unexpected any. Specify a different type
<K extends keyof T, G extends keyof T[K], S extends string>(
keysetName: K,
key: G | NoEnumLikeStringLiteral<S>,
params?: {[key: string]: any},

Check warning on line 11 in src/types.ts

GitHub Actions / test

Unexpected any. Specify a different type
): S extends G ? T[K][G] : string;
keyset<K extends keyof T>(
keysetName: K,
): <G extends keyof T[K], S extends string>(
key: G | NoEnumLikeStringLiteral<S>,
params?: {[key: string]: any},

Check warning on line 17 in src/types.ts

GitHub Actions / test

Unexpected any. Specify a different type
) => S extends G ? T[K][G] : string;
i18n<K extends keyof T, G extends keyof T[K], S extends string>(
keysetName: K,
@@ -25,21 +25,21 @@
key: string
): () => boolean;
bind(
thisArg: any,

Check warning on line 28 in src/types.ts

GitHub Actions / test

Unexpected any. Specify a different type
): <K extends keyof T, G extends keyof T[K], S extends string>(
keysetName: K,
key: G | NoEnumLikeStringLiteral<S>,
params?: {[key: string]: any},

Check warning on line 32 in src/types.ts

GitHub Actions / test

Unexpected any. Specify a different type
) => S extends G ? T[K][G] : string;
bind<K extends keyof T>(
thisArg: any,

Check warning on line 35 in src/types.ts

GitHub Actions / test

Unexpected any. Specify a different type
keysetName: K,
): <G extends keyof T[K], S extends string>(
key: G | NoEnumLikeStringLiteral<S>,
params?: {[key: string]: any},

Check warning on line 39 in src/types.ts

GitHub Actions / test

Unexpected any. Specify a different type
) => S extends G ? T[K][G] : string;
bind<K extends keyof T, G extends keyof T[K], S extends string>(
thisArg: any,

Check warning on line 42 in src/types.ts

GitHub Actions / test

Unexpected any. Specify a different type
keysetName: K,
key: G | NoEnumLikeStringLiteral<S>,
): (params?: {[key: string]: any}) => S extends G ? T[K][G] : string;
@@ -73,7 +73,7 @@
two?: string;
few?: string;
many?: string;
other: string;
other?: string;
}

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

Unchanged files with check annotations Beta

this.fallbackLang = fallbackLang;
}
/**

Check warning on line 116 in src/index.ts

GitHub Actions / test

Missing JSDoc @returns for function

Check warning on line 116 in src/index.ts

GitHub Actions / test

Missing JSDoc for parameter 'pluralizers'
* @deprecated Plurals automatically used from Intl.PluralRules. You can safely remove this call. Will be removed in v2.
*/
configurePluralization(pluralizers: Record<string, Pluralizer>) {