create products page
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user