create products page

This commit is contained in:
2025-06-03 12:59:05 +03:30
parent 05e50f0eee
commit bd368ab6b5
17 changed files with 408 additions and 64 deletions
+17 -5
View File
@@ -39,19 +39,31 @@ export function changeLanguage(lang: TLocales, days = 365) {
}
export const locales = {
en: en as Translates,
en: en as unknown as Translates,
fa,
} as Record<TLocales, Translates>;
export const translates = (key: keyof Translates): string | (() => string) => {
export const translates = (
key: keyof Translates,
dynamicValue?: Record<string, string | number>,
): string | ((dynamicValue: Record<string, string | number>) => string) => {
const lang = (getCookie('lang') || 'en') as TLocales;
return locales[lang][key] || locales.en[key] || key;
const value = locales[lang][key] || locales.en[key] || key;
if (typeof value === 'function') {
return value(dynamicValue || {});
}
return value;
};
export const t = (key: keyof Translates) => translates(key);
export const t = (
key: keyof Translates,
dynamicValue?: Record<string, string | number>,
) => translates(key, dynamicValue);
export type TLocales = 'en' | 'fa';
export type Translates = {
[K in keyof typeof en]: string | (() => string);
[K in keyof typeof en]:
| string
| ((dynamicValue: Record<string, string | number>) => string);
};