diff --git a/packages/surveys/package.json b/packages/surveys/package.json index 035dbcf325..cf91143e64 100644 --- a/packages/surveys/package.json +++ b/packages/surveys/package.json @@ -54,7 +54,6 @@ "devDependencies": { "@formbricks/config-typescript": "workspace:*", "@formbricks/eslint-config": "workspace:*", - "@formbricks/i18n-utils": "workspace:*", "@formbricks/types": "workspace:*", "@preact/preset-vite": "2.10.1", "@tailwindcss/postcss": "4.1.17", @@ -70,4 +69,4 @@ "vite-plugin-dts": "4.5.3", "vite-tsconfig-paths": "5.1.4" } -} \ No newline at end of file +} diff --git a/packages/surveys/src/components/general/language-switch.tsx b/packages/surveys/src/components/general/language-switch.tsx index 04d6c100dd..d297113953 100644 --- a/packages/surveys/src/components/general/language-switch.tsx +++ b/packages/surveys/src/components/general/language-switch.tsx @@ -1,10 +1,10 @@ import { useRef, useState } from "preact/hooks"; import { useTranslation } from "react-i18next"; -import { getLanguageLabel } from "@formbricks/i18n-utils/src"; import { TJsEnvironmentStateSurvey } from "@formbricks/types/js"; import { type TSurveyLanguage } from "@formbricks/types/surveys/types"; import { LanguageIcon } from "@/components/icons/language-icon"; import { mixColor } from "@/lib/color"; +import { getLanguageDisplayName } from "@/lib/get-language-display-name"; import { getI18nLanguage } from "@/lib/i18n-utils"; import i18n from "@/lib/i18n.config"; import { useClickOutside } from "@/lib/use-click-outside-hook"; @@ -80,7 +80,7 @@ export function LanguageSwitch({ title={t("common.language_switch")} type="button" className={cn( - "text-heading relative flex h-8 w-8 items-center justify-center rounded-md focus:ring-2 focus:ring-offset-2 focus:outline-hidden" + "text-heading focus:outline-hidden relative flex h-8 w-8 items-center justify-center rounded-md focus:ring-2 focus:ring-offset-2" )} style={{ backgroundColor: isHovered ? hoverColorWithOpacity : "transparent", @@ -113,7 +113,7 @@ export function LanguageSwitch({ onClick={() => { changeLanguage(surveyLanguage.language.code); }}> - {getLanguageLabel(surveyLanguage.language.code, "en-US")} + {getLanguageDisplayName(surveyLanguage.language.code)} ); })} diff --git a/packages/surveys/src/lib/get-language-display-name.ts b/packages/surveys/src/lib/get-language-display-name.ts new file mode 100644 index 0000000000..8083c19d1b --- /dev/null +++ b/packages/surveys/src/lib/get-language-display-name.ts @@ -0,0 +1,14 @@ +/** + * Returns the display name for a language code using Intl.DisplayNames (built-in, 0 KB). + * Falls back to the code if the API is unavailable or the tag is unknown. + */ +export function getLanguageDisplayName(code: string): string { + if (typeof Intl === "undefined" || !Intl.DisplayNames) return code; + try { + const displayNames = new Intl.DisplayNames(["en-US"], { type: "language" }); + const name = displayNames.of(code); + return name && name !== code ? name : code; + } catch { + return code; + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fa2788291c..5cb1b51f61 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -999,9 +999,6 @@ importers: '@formbricks/eslint-config': specifier: workspace:* version: link:../config-eslint - '@formbricks/i18n-utils': - specifier: workspace:* - version: link:../i18n-utils '@formbricks/types': specifier: workspace:* version: link:../types @@ -7663,6 +7660,7 @@ packages: glob@10.5.0: resolution: {integrity: sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==} + deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me hasBin: true glob@11.1.0: @@ -7672,7 +7670,7 @@ packages: glob@7.2.3: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} - deprecated: Glob versions prior to v9 are no longer supported + deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me globals@13.24.0: resolution: {integrity: sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==}