diff --git a/.changeset/new-bees-attack.md b/.changeset/new-bees-attack.md new file mode 100644 index 000000000000..c52f7de06c66 --- /dev/null +++ b/.changeset/new-bees-attack.md @@ -0,0 +1,5 @@ +--- +"ledger-live-desktop": minor +--- + +Changed the Electron util that detects the locale for swapping Yield-Earn labels diff --git a/apps/ledger-live-desktop/src/helpers/systemLocale.ts b/apps/ledger-live-desktop/src/helpers/systemLocale.ts index 67e90de78d0e..a06e1b8f819e 100644 --- a/apps/ledger-live-desktop/src/helpers/systemLocale.ts +++ b/apps/ledger-live-desktop/src/helpers/systemLocale.ts @@ -15,7 +15,15 @@ const parse = memoize(navLang => { * We don't use window.navigator.language directly as it doesn't always actually * follow the system language, it's unreliable. cf. https://stackoverflow.com/a/3335420 * */ -export const getSystemLocale = () => { +export const getAppLocale = () => { return new URLSearchParams(window.location.search).get("appLocale") || window.navigator.language; }; -export const getParsedSystemLocale = () => parse(getSystemLocale()); + +export const getSystemLocale = () => { + return ( + new URLSearchParams(window.location.search).get("systemLocale") || window.navigator.language + ); +}; + +export const getParsedSystemDeviceLocale = () => parse(getSystemLocale()); +export const getParsedSystemLocale = () => parse(getAppLocale()); diff --git a/apps/ledger-live-desktop/src/main/window-lifecycle.ts b/apps/ledger-live-desktop/src/main/window-lifecycle.ts index 3d8a88cc5a63..272baddc4830 100644 --- a/apps/ledger-live-desktop/src/main/window-lifecycle.ts +++ b/apps/ledger-live-desktop/src/main/window-lifecycle.ts @@ -78,6 +78,8 @@ export const loadWindow = async () => { fullUrl.searchParams.append("appDirname", app.dirname || ""); fullUrl.searchParams.append("theme", theme || ""); fullUrl.searchParams.append("appLocale", app.getLocale()); + fullUrl.searchParams.append("systemLocale", app.getSystemLocale()); + await mainWindow.loadURL(fullUrl.href); } }; diff --git a/apps/ledger-live-desktop/src/renderer/hooks/useGetStakeLabelLocaleBased.ts b/apps/ledger-live-desktop/src/renderer/hooks/useGetStakeLabelLocaleBased.ts index 6de0099fceb2..11f63a8bcc45 100644 --- a/apps/ledger-live-desktop/src/renderer/hooks/useGetStakeLabelLocaleBased.ts +++ b/apps/ledger-live-desktop/src/renderer/hooks/useGetStakeLabelLocaleBased.ts @@ -1,8 +1,9 @@ import { useTranslation } from "react-i18next"; -import { getSystemLocale } from "~/helpers/systemLocale"; +import { getParsedSystemDeviceLocale } from "~/helpers/systemLocale"; export const useGetStakeLabelLocaleBased = () => { - const locale = getSystemLocale(); + const { region } = getParsedSystemDeviceLocale(); const { t } = useTranslation(); - return locale === "en-GB" ? t("accounts.contextMenu.yield") : t("accounts.contextMenu.earn"); + + return region === "GB" ? t("accounts.contextMenu.yield") : t("accounts.contextMenu.earn"); }; diff --git a/apps/ledger-live-desktop/src/renderer/reducers/settings.ts b/apps/ledger-live-desktop/src/renderer/reducers/settings.ts index ba9039484a9c..d3a72dc964f3 100644 --- a/apps/ledger-live-desktop/src/renderer/reducers/settings.ts +++ b/apps/ledger-live-desktop/src/renderer/reducers/settings.ts @@ -27,7 +27,7 @@ import { } from "~/config/languages"; import { State } from "."; import regionsByKey from "~/renderer/screens/settings/sections/General/regions.json"; -import { getSystemLocale } from "~/helpers/systemLocale"; +import { getAppLocale } from "~/helpers/systemLocale"; import { Handlers } from "./types"; import { Layout, LayoutKey } from "LLD/features/Collectibles/types/Layouts"; import { OnboardingUseCase } from "../components/Onboarding/OnboardingUseCase"; @@ -128,7 +128,7 @@ export type SettingsState = { }; export const getInitialLanguageAndLocale = (): { language: Language; locale: Locale } => { - const systemLocal = getSystemLocale(); + const systemLocal = getAppLocale(); // Find language from system locale (i.e., en, fr, es ...) const languageId = LanguageIds.find(lang => systemLocal.startsWith(lang)); diff --git a/apps/ledger-live-desktop/src/renderer/screens/earn/index.tsx b/apps/ledger-live-desktop/src/renderer/screens/earn/index.tsx index 303ccb9ce2f8..96cd75502317 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/earn/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/earn/index.tsx @@ -12,7 +12,7 @@ import useTheme from "~/renderer/hooks/useTheme"; import { useDeepLinkListener } from "~/renderer/screens/earn/useDeepLinkListener"; import { useDiscreetMode } from "~/renderer/components/Discreet"; import { useLocalLiveAppManifest } from "@ledgerhq/live-common/wallet-api/LocalLiveAppProvider/index"; -import { getParsedSystemLocale } from "~/helpers/systemLocale"; +import { getParsedSystemDeviceLocale } from "~/helpers/systemLocale"; const DEFAULT_EARN_APP_ID = "earn"; @@ -25,7 +25,7 @@ const Earn = () => { const manifest = localManifest || remoteManifest; const themeType = useTheme().colors.palette.type; const discreetMode = useDiscreetMode(); - const countryLocale = getParsedSystemLocale().region; + const countryLocale = getParsedSystemDeviceLocale().region; useDeepLinkListener(); return (