fix: components not updating correctly when changing language
The issue was caused by incorrect handling of the `i18n.global.locale` value in the Composition API.
When using `createI18n` with `legacy: false`, `i18n.global.locale` is a reactive ref.
Assigning directly with `i18n.global.locale = lang;` breaks reactivity.
The correct usage is : `i18n.global.locale.value = lang;`.
However, this assignment was unnecessary because the value is already updated automatically when the language changes.
All scripts using `const { locale } = useI18n({ useScope: "global" });` are updated to use `locale.value` instead of just `locale`, to ensure correct reactive behavior.
Fixes: #1597, #1772, and possibly other related issues.
This commit is contained in:
@@ -27,7 +27,7 @@ import { useI18n } from "vue-i18n";
|
|||||||
|
|
||||||
const { locale } = useI18n({ useScope: "global" });
|
const { locale } = useI18n({ useScope: "global" });
|
||||||
|
|
||||||
const localeConverted = locale.replace("_", "-");
|
const localeConverted = computed(() => locale.value.replace("_", "-"));
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
@@ -40,15 +40,15 @@ const props = withDefaults(
|
|||||||
const dateObj = computed<Date>(() => new Date(props.date));
|
const dateObj = computed<Date>(() => new Date(props.date));
|
||||||
|
|
||||||
const month = computed<string>(() =>
|
const month = computed<string>(() =>
|
||||||
dateObj.value.toLocaleString(localeConverted, { month: "short" })
|
dateObj.value.toLocaleString(localeConverted.value, { month: "short" })
|
||||||
);
|
);
|
||||||
|
|
||||||
const day = computed<string>(() =>
|
const day = computed<string>(() =>
|
||||||
dateObj.value.toLocaleString(localeConverted, { day: "numeric" })
|
dateObj.value.toLocaleString(localeConverted.value, { day: "numeric" })
|
||||||
);
|
);
|
||||||
|
|
||||||
const weekday = computed<string>(() =>
|
const weekday = computed<string>(() =>
|
||||||
dateObj.value.toLocaleString(localeConverted, { weekday: "short" })
|
dateObj.value.toLocaleString(localeConverted.value, { weekday: "short" })
|
||||||
);
|
);
|
||||||
|
|
||||||
const smallStyle = computed<string>(() => (props.small ? "1.2" : "2"));
|
const smallStyle = computed<string>(() => (props.small ? "1.2" : "2"));
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ const asyncData = async (query: string): Promise<void> => {
|
|||||||
try {
|
try {
|
||||||
const queryVars = {
|
const queryVars = {
|
||||||
query,
|
query,
|
||||||
locale: locale,
|
locale: locale.value,
|
||||||
type: props.resultType,
|
type: props.resultType,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -428,7 +428,7 @@ const reverseGeoCode = async (e: LatLng, zoom: number) => {
|
|||||||
latitude: e.lat,
|
latitude: e.lat,
|
||||||
longitude: e.lng,
|
longitude: e.lng,
|
||||||
zoom,
|
zoom,
|
||||||
locale: locale as unknown as string,
|
locale: locale.value as unknown as string,
|
||||||
});
|
});
|
||||||
if (!result) return;
|
if (!result) return;
|
||||||
addressData.value = result.reverseGeocode;
|
addressData.value = result.reverseGeocode;
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ export const i18n = createI18n({
|
|||||||
const loadedLanguages = [DEFAULT_LOCALE];
|
const loadedLanguages = [DEFAULT_LOCALE];
|
||||||
|
|
||||||
function setI18nLanguage(lang: string): string {
|
function setI18nLanguage(lang: string): string {
|
||||||
i18n.global.locale = lang;
|
|
||||||
setLanguageInDOM(lang);
|
setLanguageInDOM(lang);
|
||||||
return lang;
|
return lang;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ const { locale } = useI18n({ useScope: "global" });
|
|||||||
const { result: configResult } = useQuery<{ config: IConfig }>(
|
const { result: configResult } = useQuery<{ config: IConfig }>(
|
||||||
PRIVACY,
|
PRIVACY,
|
||||||
() => ({
|
() => ({
|
||||||
locale: locale,
|
locale: locale.value,
|
||||||
}),
|
}),
|
||||||
() => ({
|
() => ({
|
||||||
enabled: locale !== undefined,
|
enabled: locale.value !== undefined,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ const { result: termsResult, loading: termsLoading } = useQuery<{
|
|||||||
}>(
|
}>(
|
||||||
TERMS,
|
TERMS,
|
||||||
() => ({
|
() => ({
|
||||||
locale: locale,
|
locale: locale.value,
|
||||||
}),
|
}),
|
||||||
() => ({
|
() => ({
|
||||||
enabled: locale !== undefined,
|
enabled: locale.value !== undefined,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user