Compare commits

...

1 Commits

Author SHA1 Message Date
Dhruwang
626b40e070 refactor: removed i18n-utils dependency from surveys package 2026-02-06 18:38:28 +05:30
4 changed files with 20 additions and 9 deletions

View File

@@ -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"
}
}
}

View File

@@ -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)}
</button>
);
})}

View File

@@ -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;
}
}

6
pnpm-lock.yaml generated
View File

@@ -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==}