You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
357 B
TypeScript

import { useRouter } from 'next/router';
export type Locales = 'ru' | 'en';
export type LocalesMap = {
[locale in Locales]: { [key: string]: string | any };
};
export default function useLocale(locales: LocalesMap) {
const router = useRouter();
const t = (key: string) =>
locales[(router.locale || 'en') as Locales][key] || key;
return t;
}