hotfix/AW-334-translate-version

This commit is contained in:
Денис Катаев 2024-11-04 20:49:56 +00:00 committed by Daniil Chemerkin
parent 0eb9f51ef6
commit 9db28d0d52

View File

@ -4,6 +4,7 @@ import { selectors } from "@/store";
import { useCallback, useEffect, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useSelector } from "react-redux";
import { useSearchParams } from "react-router-dom";
type TranslationOptions = {
[key: string]: unknown;
@ -12,12 +13,15 @@ type TranslationOptions = {
export const useTranslations = (
placement: ELocalesPlacement = ELocalesPlacement.V0
) => {
const [searchParams] = useSearchParams();
const { t, i18n } = useTranslation();
const gender =
useSelector(selectors.selectQuestionnaire)?.gender || "default";
const { flags } = useMetricABFlags();
const esFlag = flags?.esFlag?.[0];
const translateVersion = searchParams.get("tv");
useEffect(() => {
const _esFlag = localStorage.getItem("esFlag");
if (!_esFlag?.length && esFlag) {
@ -64,6 +68,14 @@ export const useTranslations = (
);
}
// Hint translate
if (translateVersion === "h") {
_key = prefixPlacementKey(
prefixGenderKey(key),
ELocalesPlacement.PalmistryV01
);
}
const translation = t(_key, options);
if (translation === key) {
@ -75,7 +87,7 @@ export const useTranslations = (
return translation;
},
[placement, prefixGenderKey, prefixPlacementKey, t]
[placement, prefixGenderKey, prefixPlacementKey, t, translateVersion]
);
return useMemo(() => ({ translate, i18n }), [i18n, translate]);