Skip to content

Commit

Permalink
Merge pull request #8511 from LedgerHQ/fix/LIVE-15090-earn-label-for-…
Browse files Browse the repository at this point in the history
…non-uk

LIVE-15090: change utils from electron that detects device locale
  • Loading branch information
adammino-ledger authored Nov 27, 2024
2 parents 4804957 + 73f65a7 commit 0fe9d07
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-bees-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": minor
---

Changed the Electron util that detects the locale for swapping Yield-Earn labels
12 changes: 10 additions & 2 deletions apps/ledger-live-desktop/src/helpers/systemLocale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
2 changes: 2 additions & 0 deletions apps/ledger-live-desktop/src/main/window-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
};
4 changes: 2 additions & 2 deletions apps/ledger-live-desktop/src/renderer/reducers/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions apps/ledger-live-desktop/src/renderer/screens/earn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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 (
Expand Down

0 comments on commit 0fe9d07

Please sign in to comment.