mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-21 14:47:41 +01:00
Specify defaultValue in random extra title
This commit is contained in:
parent
78bdf07c4a
commit
1573077f77
1 changed files with 5 additions and 2 deletions
|
@ -2,7 +2,7 @@ import { useCallback, useMemo } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
// 10% chance of getting a joke title
|
// 10% chance of getting a joke title
|
||||||
const shouldGiveJokeTitle = () => Math.floor(Math.random() * 10) === 0;
|
const shouldGiveJokeTitle = () => Math.floor(Math.random() * 0) === 0;
|
||||||
|
|
||||||
export function useRandomTranslation() {
|
export function useRandomTranslation() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
@ -14,7 +14,10 @@ export function useRandomTranslation() {
|
||||||
const defaultTitle = t(`${key}.default`) ?? "";
|
const defaultTitle = t(`${key}.default`) ?? "";
|
||||||
if (!shouldJoke) return defaultTitle;
|
if (!shouldJoke) return defaultTitle;
|
||||||
|
|
||||||
const keys = t(`${key}.extra`, { returnObjects: true });
|
const keys = t(`${key}.extra`, {
|
||||||
|
returnObjects: true,
|
||||||
|
defaultValue: defaultTitle,
|
||||||
|
});
|
||||||
if (Array.isArray(keys)) {
|
if (Array.isArray(keys)) {
|
||||||
if (keys.length === 0) return defaultTitle;
|
if (keys.length === 0) return defaultTitle;
|
||||||
return keys[Math.floor(seed * keys.length)];
|
return keys[Math.floor(seed * keys.length)];
|
||||||
|
|
Loading…
Reference in a new issue