mirror of
https://github.com/movie-web/movie-web.git
synced 2025-01-14 05:49:08 +01:00
16 lines
368 B
TypeScript
16 lines
368 B
TypeScript
|
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 };
|
||
|
}
|