@tagadapay/plugin-sdk 2.7.24 → 2.7.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -51,13 +51,12 @@ import React, { useCallback, useMemo } from 'react';
|
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
export const useTranslation = (options = {}) => {
|
|
54
|
-
const { defaultLanguage } = options;
|
|
54
|
+
const { defaultLanguage = 'en', currentLanguage } = options;
|
|
55
55
|
// Get the current language from query params, browser, or fallback to default
|
|
56
56
|
const locale = useMemo(() => {
|
|
57
|
+
if (currentLanguage)
|
|
58
|
+
return currentLanguage;
|
|
57
59
|
// Check for language query parameter
|
|
58
|
-
if (defaultLanguage) {
|
|
59
|
-
return defaultLanguage;
|
|
60
|
-
}
|
|
61
60
|
if (typeof window !== 'undefined') {
|
|
62
61
|
const urlParams = new URLSearchParams(window.location.search);
|
|
63
62
|
const langFromQuery = urlParams.get('locale');
|
|
@@ -69,8 +68,8 @@ export const useTranslation = (options = {}) => {
|
|
|
69
68
|
const browserLang = navigator.language.split('-')[0]; // e.g., 'en-US' -> 'en'
|
|
70
69
|
return browserLang;
|
|
71
70
|
}
|
|
72
|
-
return
|
|
73
|
-
}, [defaultLanguage]);
|
|
71
|
+
return defaultLanguage;
|
|
72
|
+
}, [defaultLanguage, currentLanguage]);
|
|
74
73
|
const t = useCallback((text, fallback, params, languageCode) => {
|
|
75
74
|
// Helper function to interpolate params into the translated string
|
|
76
75
|
const interpolate = (str, params) => {
|
|
@@ -155,7 +154,7 @@ export const useTranslation = (options = {}) => {
|
|
|
155
154
|
return interpolate(fallback || '', params);
|
|
156
155
|
if (typeof text === 'string')
|
|
157
156
|
return interpolate(text, params);
|
|
158
|
-
const targetLocale = languageCode || locale;
|
|
157
|
+
const targetLocale = languageCode || currentLanguage || locale;
|
|
159
158
|
let translatedText = '';
|
|
160
159
|
if (text[targetLocale]) {
|
|
161
160
|
translatedText = text[targetLocale];
|
|
@@ -163,7 +162,7 @@ export const useTranslation = (options = {}) => {
|
|
|
163
162
|
else if (fallback) {
|
|
164
163
|
translatedText = fallback;
|
|
165
164
|
}
|
|
166
|
-
else if (
|
|
165
|
+
else if (text[defaultLanguage]) {
|
|
167
166
|
translatedText = text[defaultLanguage];
|
|
168
167
|
}
|
|
169
168
|
else {
|