Skip to content

Commit

Permalink
Remove count from plugin arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
faradaytrs committed Nov 23, 2021
1 parent c8bea5d commit c0ae5dc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/context.ts
Expand Up @@ -19,7 +19,7 @@ export type TranslationMap = {
[language in Language]?: Translation;
};

export type TranslationPlugin = (key: string | number, count: number | string, params: TranslationProperties) => string;
export type TranslationPlugin = (key: string | number, params: TranslationProperties) => string;

export type TranslationSettings = {
translations: TranslationMap;
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/english-plurals.ts
@@ -1,3 +1,5 @@
export const englishPlurals = (count: number | string) => {
return +count === 1 ? "" : "_plural";
import {TranslationPlugin} from "..";

export const englishPlurals: TranslationPlugin = (_key, params) => {
return +params.count === 1 ? "" : "_plural";
};
4 changes: 2 additions & 2 deletions src/plugins/russian-plurals.ts
Expand Up @@ -19,6 +19,6 @@ const toRussianCasesRules = (n: number) => {
return 0;
};

export const russianPlurals: TranslationPlugin = (_key, count) => {
return `_${toLowestTheSame(toRussianCasesRules(+count))}`;
export const russianPlurals: TranslationPlugin = (_key, params) => {
return `_${toLowestTheSame(toRussianCasesRules(+params.count))}`;
};
8 changes: 4 additions & 4 deletions src/tests/useTranslation.test.tsx
Expand Up @@ -2,7 +2,7 @@ import {renderHook} from "@testing-library/react-hooks/native";
import {FC} from "react";
import {Language} from "../context.js";
import {TranslationProvider} from "../index.js";
import {useTranslation} from "../useTranslation.js";
import {TranslationProperties, useTranslation} from "../useTranslation.js";
import {translation} from "../translation.js";

const settings = {
Expand Down Expand Up @@ -59,9 +59,9 @@ const settings = {
language: Language.Chinese,
fallbackLanguage: Language.English,
plugins: {
[Language.Chinese]: (_key: string | number, count: number | string) => {
if (typeof count === "number" || typeof count === "string") {
return `_${count}`;
[Language.Chinese]: (_key: string | number, params: TranslationProperties) => {
if (typeof params.count === "number" || typeof params.count === "string") {
return `_${params.count}`;
}
return "";
},
Expand Down
2 changes: 1 addition & 1 deletion src/useTranslation.ts
Expand Up @@ -92,7 +92,7 @@ const getSuffix = (key: string, params: TranslationProperties, plugin?: Translat
if (typeof plugin !== "function") {
return "";
}
return plugin(key, +params.count, params);
return plugin(key, params);
};

export const generateTranslationFunction = (
Expand Down

0 comments on commit c0ae5dc

Please sign in to comment.