mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-18 03:20:35 -05:00
fix: (Duplicate) prevent multi-language survey buttons from falling back to English (#7559)
This commit is contained in:
committed by
GitHub
parent
d197271771
commit
b4472f48e9
@@ -1,6 +1,6 @@
|
||||
import { Languages } from "lucide-react";
|
||||
import { getLanguageLabel } from "@formbricks/i18n-utils/src/utils";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { getLanguageLabel } from "@formbricks/i18n-utils/src/utils";
|
||||
import { TSurvey } from "@formbricks/types/surveys/types";
|
||||
import { TUserLocale } from "@formbricks/types/user";
|
||||
import { getEnabledLanguages } from "@/lib/i18n/utils";
|
||||
@@ -18,11 +18,7 @@ interface LanguageDropdownProps {
|
||||
locale: TUserLocale;
|
||||
}
|
||||
|
||||
export const LanguageDropdown = ({
|
||||
survey,
|
||||
setLanguage,
|
||||
locale,
|
||||
}: LanguageDropdownProps) => {
|
||||
export const LanguageDropdown = ({ survey, setLanguage, locale }: LanguageDropdownProps) => {
|
||||
const { t } = useTranslation();
|
||||
const enabledLanguages = getEnabledLanguages(survey.languages ?? []);
|
||||
|
||||
@@ -33,7 +29,10 @@ export const LanguageDropdown = ({
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="secondary" title={t("common.select_language")} aria-label={t("common.select_language")}>
|
||||
<Button
|
||||
variant="secondary"
|
||||
title={t("common.select_language")}
|
||||
aria-label={t("common.select_language")}>
|
||||
<Languages className="h-5 w-5" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
@@ -41,9 +41,16 @@ export const getLocalizedValue = (
|
||||
* This ensures translations are always available, even when called from API routes
|
||||
*/
|
||||
export const getTranslations = (languageCode: string): TFunction => {
|
||||
// "default" is a Formbricks-internal language identifier, not a valid i18next locale.
|
||||
// When "default" is passed, use the current i18n language (which was already resolved
|
||||
// to a real locale by the I18nProvider or LanguageSwitch). Calling
|
||||
// i18n.changeLanguage("default") would cause i18next to fall back to "en", resetting
|
||||
// the user's selected language (see issue #7515).
|
||||
const resolvedCode = languageCode === "default" ? i18n.language : languageCode;
|
||||
|
||||
// Ensure the language is set (i18n.changeLanguage is synchronous when resources are already loaded)
|
||||
if (i18n.language !== languageCode) {
|
||||
i18n.changeLanguage(languageCode);
|
||||
if (i18n.language !== resolvedCode) {
|
||||
i18n.changeLanguage(resolvedCode);
|
||||
}
|
||||
return i18n.getFixedT(languageCode);
|
||||
return i18n.getFixedT(resolvedCode);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user