diff --git a/package.json b/package.json
index 8d60a60..7ca53f9 100755
--- a/package.json
+++ b/package.json
@@ -87,7 +87,11 @@
"react-router-dom": "^6.21.3",
"swr": "^2.2.4",
"use-debounce": "^9.0.4",
- "zustand": "^4.3.8"
+ "zustand": "^4.3.8",
+ "i18next": "^25.0.0",
+ "i18next-browser-languagedetector": "^8.0.5",
+ "i18next-http-backend": "^3.0.2",
+ "react-i18next": "^15.4.1"
},
"dependencies": {
"bowser": "1.9.4",
@@ -97,10 +101,10 @@
"i18next": "^25.0.0",
"i18next-browser-languagedetector": "^8.0.5",
"i18next-http-backend": "^3.0.2",
+ "react-i18next": "^15.4.1",
"mobile-detect": "^1.4.5",
"mui-tel-input": "^5.1.2",
"react-helmet-async": "^2.0.5",
- "react-i18next": "^15.4.1",
"react-imask": "^7.6.0",
"react-phone-number-input": "^3.4.1"
},
diff --git a/src/i18n/i18n.ts b/src/i18n/i18n.ts
index e4f8067..a100e94 100644
--- a/src/i18n/i18n.ts
+++ b/src/i18n/i18n.ts
@@ -18,7 +18,56 @@ const getLanguageFromURL = (): string => {
return "ru"; // Жёсткий фолбэк
};
-// 2. Конфиг с полной отладкой
+// 2. Проверяем, работаем ли мы в виджете
+const isWidget = typeof window !== "undefined" && window.location.pathname.includes("widget");
+
+// 3. Встроенные переводы для виджета
+const builtInTranslations = {
+ ru: {
+ Next: "Далее",
+ Prev: "Назад",
+ Step: "Шаг",
+ of: "из",
+ "Enter your answer": "Введите ваш ответ",
+ "Fill out the form to receive your test results": "Заполните форму для получения результатов теста",
+ Name: "Имя",
+ "Phone number": "Номер телефона",
+ "Get results": "Получить результаты",
+ "Data sent successfully": "Данные отправлены успешно",
+ "Please fill in the fields": "Пожалуйста, заполните поля",
+ "Incorrect email entered": "Введен некорректный email",
+ "quiz is inactive": "Квиз неактивен",
+ "no questions found": "Вопросы не найдены",
+ "quiz is empty": "Квиз пуст",
+ "quiz already completed": "Квиз уже пройден",
+ "no quiz id": "ID квиза не указан",
+ "quiz data is null": "Данные квиза не предоставлены",
+ "default message": "Что-то пошло не так",
+ },
+ en: {
+ Next: "Next",
+ Prev: "Previous",
+ Step: "Step",
+ of: "of",
+ "Enter your answer": "Enter your answer",
+ "Fill out the form to receive your test results": "Fill out the form to receive your test results",
+ Name: "Name",
+ "Phone number": "Phone number",
+ "Get results": "Get results",
+ "Data sent successfully": "Data sent successfully",
+ "Please fill in the fields": "Please fill in the fields",
+ "Incorrect email entered": "Incorrect email entered",
+ "quiz is inactive": "Quiz is inactive",
+ "no questions found": "No questions found",
+ "quiz is empty": "Quiz is empty",
+ "quiz already completed": "Quiz already completed",
+ "no quiz id": "No quiz id",
+ "quiz data is null": "Quiz data is null",
+ "default message": "Something went wrong",
+ },
+};
+
+// 4. Конфиг с полной отладкой
i18n
.use(Backend)
.use(initReactI18next)
@@ -31,7 +80,7 @@ i18n
escapeValue: false,
},
backend: {
- loadPath: "/locales/{{lng}}.json",
+ loadPath: "/locales/{{lng}}.json", // Единый путь для всех
allowMultiLoading: false,
},
react: {
@@ -54,6 +103,7 @@ i18n
stack: new Error().stack, // Выведет стек вызовов
});
},
+ resources: isWidget ? builtInTranslations : undefined, // Встроенные переводы для виджета
})
.then(() => {
//console.log("i18n инициализирован! Текущий язык:", i18n.language);
diff --git a/src/widget.tsx b/src/widget.tsx
index 653e35b..928d2a4 100644
--- a/src/widget.tsx
+++ b/src/widget.tsx
@@ -1,5 +1,6 @@
import QuizAnswerer from "@/components/QuizAnswerer";
import { createRoot } from "react-dom/client";
+import "./i18n/i18n"; // Инициализация i18n для виджета
// eslint-disable-next-line react-refresh/only-export-components
export * from "./widgets";
@@ -19,7 +20,13 @@ const widget = {
const root = createRoot(element);
- root.render();
+ root.render(
+
+ );
},
};