movie-web/src/hooks/useRandomTranslation.ts

16 lines
368 B
TypeScript
Raw Normal View History

2023-10-25 16:58:38 +02:00
import { useTranslation } from "react-i18next";
export function useRandomTranslation() {
const { t } = useTranslation();
const getRandomTranslation = (key: string) => {
const res = t(key, { returnObjects: true });
if (Array.isArray(res)) return res[Math.floor(Math.random() * res.length)];
return res;
};
return { t: getRandomTranslation };
}