@orderly.network/i18n 3.0.4-alpha.3 → 3.0.4-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -437,6 +437,8 @@ declare const en: {
437
437
  "transfer.LTV.tooltip": string;
438
438
  "transfer.LTV.currentLTV": string;
439
439
  "transfer.LTV.isolatedModeUsdcOnly": string;
440
+ "transfer.LTV.availableCrossMarginHint": string;
441
+ "transfer.LTV.isolatedMarginOrderHint": string;
440
442
  "transfer.convert": string;
441
443
  "transfer.deposit.globalMaxQty.error": string;
442
444
  "transfer.deposit.gasFee.error": string;
@@ -437,6 +437,8 @@ declare const en: {
437
437
  "transfer.LTV.tooltip": string;
438
438
  "transfer.LTV.currentLTV": string;
439
439
  "transfer.LTV.isolatedModeUsdcOnly": string;
440
+ "transfer.LTV.availableCrossMarginHint": string;
441
+ "transfer.LTV.isolatedMarginOrderHint": string;
440
442
  "transfer.convert": string;
441
443
  "transfer.deposit.globalMaxQty.error": string;
442
444
  "transfer.deposit.gasFee.error": string;
@@ -1,2 +1,2 @@
1
- export { f as LocaleEnum, g as defaultLanguages, h as defaultLng, i as defaultNS, k as i18nCookieKey, j as i18nLocalStorageKey } from './constant-BwPxVQ3H.mjs';
1
+ export { f as LocaleEnum, g as defaultLanguages, h as defaultLng, i as defaultNS, k as i18nCookieKey, j as i18nLocalStorageKey } from './constant-CIx423sl.mjs';
2
2
  import 'react';
@@ -1,2 +1,2 @@
1
- export { f as LocaleEnum, g as defaultLanguages, h as defaultLng, i as defaultNS, k as i18nCookieKey, j as i18nLocalStorageKey } from './constant-BwPxVQ3H.js';
1
+ export { f as LocaleEnum, g as defaultLanguages, h as defaultLng, i as defaultNS, k as i18nCookieKey, j as i18nLocalStorageKey } from './constant-CIx423sl.js';
2
2
  import 'react';
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as Resources, A as AsyncResources, L as LocaleCode, a as LanguageContextState } from './constant-BwPxVQ3H.mjs';
2
- export { b as Language, d as LanguageContext, f as LocaleEnum, e as LocaleMessages, P as PopupMode, c as PopupProps, g as defaultLanguages, h as defaultLng, i as defaultNS, l as en, k as i18nCookieKey, j as i18nLocalStorageKey, u as useLanguageContext } from './constant-BwPxVQ3H.mjs';
1
+ import { R as Resources, A as AsyncResources, L as LocaleCode, a as LanguageContextState } from './constant-CIx423sl.mjs';
2
+ export { b as Language, d as LanguageContext, f as LocaleEnum, e as LocaleMessages, P as PopupMode, c as PopupProps, g as defaultLanguages, h as defaultLng, i as defaultNS, l as en, k as i18nCookieKey, j as i18nLocalStorageKey, u as useLanguageContext } from './constant-CIx423sl.mjs';
3
3
  import * as react_i18next from 'react-i18next';
4
4
  import { FallbackNs, UseTranslationOptions } from 'react-i18next';
5
5
  export * from 'react-i18next';
@@ -96,8 +96,8 @@ declare function useLocaleCode(): LocaleCode;
96
96
  * Registers host-provided i18n resources into the shared i18n instance whenever
97
97
  * the active locale or `resources` reference changes.
98
98
  *
99
- * - When `resources` is a function, it is invoked for the current locale to
100
- * load the bundle (e.g. from another bundle, backend, or runtime loader).
99
+ * - When `resources` is a function, it is registered as a preloader for language
100
+ * switches and also invoked for the current locale after mount.
101
101
  * - When `resources` is a static map, all provided locale bundles are registered.
102
102
  *
103
103
  * Prefer a stable `resources` reference (e.g. `useCallback` for loaders, module
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as Resources, A as AsyncResources, L as LocaleCode, a as LanguageContextState } from './constant-BwPxVQ3H.js';
2
- export { b as Language, d as LanguageContext, f as LocaleEnum, e as LocaleMessages, P as PopupMode, c as PopupProps, g as defaultLanguages, h as defaultLng, i as defaultNS, l as en, k as i18nCookieKey, j as i18nLocalStorageKey, u as useLanguageContext } from './constant-BwPxVQ3H.js';
1
+ import { R as Resources, A as AsyncResources, L as LocaleCode, a as LanguageContextState } from './constant-CIx423sl.js';
2
+ export { b as Language, d as LanguageContext, f as LocaleEnum, e as LocaleMessages, P as PopupMode, c as PopupProps, g as defaultLanguages, h as defaultLng, i as defaultNS, l as en, k as i18nCookieKey, j as i18nLocalStorageKey, u as useLanguageContext } from './constant-CIx423sl.js';
3
3
  import * as react_i18next from 'react-i18next';
4
4
  import { FallbackNs, UseTranslationOptions } from 'react-i18next';
5
5
  export * from 'react-i18next';
@@ -96,8 +96,8 @@ declare function useLocaleCode(): LocaleCode;
96
96
  * Registers host-provided i18n resources into the shared i18n instance whenever
97
97
  * the active locale or `resources` reference changes.
98
98
  *
99
- * - When `resources` is a function, it is invoked for the current locale to
100
- * load the bundle (e.g. from another bundle, backend, or runtime loader).
99
+ * - When `resources` is a function, it is registered as a preloader for language
100
+ * switches and also invoked for the current locale after mount.
101
101
  * - When `resources` is a static map, all provided locale bundles are registered.
102
102
  *
103
103
  * Prefer a stable `resources` reference (e.g. `useCallback` for loaders, module
package/dist/index.js CHANGED
@@ -642,7 +642,7 @@ var orderEntry = {
642
642
  "marginMode.crossMargin": "Cross Margin",
643
643
  "marginMode.isolatedMargin": "Isolated Margin",
644
644
  "marginMode.crossMarginDescription": "Margin and PnL are shared across positions. You may lose all positions if liquidation occurs.",
645
- "marginMode.isolatedMarginDescription": "Margin and PnL are independent for each position. You'll only lose the current position if liquidation occurs.",
645
+ "marginMode.isolatedMarginDescription": "Margin and PnL are independent for each position. You'll only lose the current position if liquidation occurs. Only USDC is accepted as collateral. <0>Learn more</0>",
646
646
  "marginMode.current": "Current",
647
647
  "marginMode.marginModeSettings": "Margin mode settings",
648
648
  "marginMode.updatedSuccessfully": "Updated successfully",
@@ -1313,6 +1313,8 @@ var transfer = {
1313
1313
  "transfer.LTV.tooltip": `If your LTV exceeds {{threshold}}% or your USDC balance plus Unsettled PnL falls below {{usdcThreshold}}, your collateral will be automatically converted with a haircut. To avoid this, you can manually convert assets to USDC.`,
1314
1314
  "transfer.LTV.currentLTV": "Current LTV",
1315
1315
  "transfer.LTV.isolatedModeUsdcOnly": "Only USDC can be used as margin in Isolated Mode.",
1316
+ "transfer.LTV.availableCrossMarginHint": "Available balance = USDC balance + Unsettled PnL. All collateral assets contribute to your available margin.",
1317
+ "transfer.LTV.isolatedMarginOrderHint": "In Isolated Margin mode, only USDC is accepted as margin. Convert your assets to USDC to place orders.",
1316
1318
  "transfer.convert": "Convert",
1317
1319
  // "transfer.convert.note": "Please note that convert fees will be charged.",
1318
1320
  "transfer.deposit.globalMaxQty.error": "Your deposit couldn't be processed because the global deposit cap for {{token}} on {{chain}} has been reached. This is typically resolved after rebalancing, which takes around 1 hour. Please try again later, or use a smaller amount or a different chain. <0>Learn more</0>",
@@ -1488,6 +1490,25 @@ var en = {
1488
1490
  ...navigation
1489
1491
  };
1490
1492
 
1493
+ // src/resourceBundles/externalResources.ts
1494
+ var externalResourcePreloaders = /* @__PURE__ */ new Set();
1495
+ function registerExternalResourcePreloader(preloader) {
1496
+ externalResourcePreloaders.add(preloader);
1497
+ return () => {
1498
+ externalResourcePreloaders.delete(preloader);
1499
+ };
1500
+ }
1501
+ async function preloadExternalResources(lang) {
1502
+ await Promise.all(
1503
+ Array.from(externalResourcePreloaders).map(async (preloader) => {
1504
+ try {
1505
+ await preloader(lang);
1506
+ } catch (error) {
1507
+ }
1508
+ })
1509
+ );
1510
+ }
1511
+
1491
1512
  // src/i18n.ts
1492
1513
  var resources = {
1493
1514
  [defaultLng]: { [defaultNS]: en }
@@ -1511,6 +1532,28 @@ function createI18nInstance(options) {
1511
1532
  var i18n = createI18nInstance({
1512
1533
  resources
1513
1534
  });
1535
+ var parseChangeLanguageTarget = (lang) => {
1536
+ if (!lang) {
1537
+ return void 0;
1538
+ }
1539
+ const localeCodes = Object.values(LocaleEnum);
1540
+ if (localeCodes.includes(lang)) {
1541
+ return lang;
1542
+ }
1543
+ const match = lang.match(/^([a-z]{2})/i);
1544
+ if (match && localeCodes.includes(match[1])) {
1545
+ return match[1];
1546
+ }
1547
+ return lang;
1548
+ };
1549
+ var originalChangeLanguage = i18n.changeLanguage.bind(i18n);
1550
+ i18n.changeLanguage = (async (lang, callback) => {
1551
+ const localeCode = parseChangeLanguageTarget(lang);
1552
+ if (localeCode) {
1553
+ await preloadExternalResources(localeCode);
1554
+ }
1555
+ return originalChangeLanguage(lang, callback);
1556
+ });
1514
1557
  i18n.init();
1515
1558
  var i18n_default = i18n;
1516
1559
  var LanguageContext = react.createContext({
@@ -1720,18 +1763,63 @@ function useLocaleCode() {
1720
1763
  }, [i18n_default]);
1721
1764
  return localeCode;
1722
1765
  }
1766
+
1767
+ // src/hooks/useRegisterExternalResources.ts
1768
+ var asyncResourceLoadCache = /* @__PURE__ */ new WeakMap();
1769
+ function getAsyncResourceLoadState(resources2) {
1770
+ let state = asyncResourceLoadCache.get(resources2);
1771
+ if (!state) {
1772
+ state = {
1773
+ loadedLocales: /* @__PURE__ */ new Set(),
1774
+ pendingLoads: /* @__PURE__ */ new Map()
1775
+ };
1776
+ asyncResourceLoadCache.set(resources2, state);
1777
+ }
1778
+ return state;
1779
+ }
1780
+ function loadAsyncResources(resources2, localeCode) {
1781
+ const state = getAsyncResourceLoadState(resources2);
1782
+ if (state.loadedLocales.has(localeCode)) {
1783
+ return Promise.resolve();
1784
+ }
1785
+ const pendingLoad = state.pendingLoads.get(localeCode);
1786
+ if (pendingLoad) {
1787
+ return pendingLoad;
1788
+ }
1789
+ const loadPromise = registerResources(resources2, localeCode).then(() => {
1790
+ state.loadedLocales.add(localeCode);
1791
+ }).finally(() => {
1792
+ state.pendingLoads.delete(localeCode);
1793
+ });
1794
+ state.pendingLoads.set(localeCode, loadPromise);
1795
+ return loadPromise;
1796
+ }
1797
+ function useRegisterExternalResources(resources2) {
1798
+ const localeCode = useLocaleCode();
1799
+ react.useEffect(() => {
1800
+ if (typeof resources2 === "function") {
1801
+ return registerExternalResourcePreloader(
1802
+ (lang) => loadAsyncResources(resources2, lang)
1803
+ );
1804
+ }
1805
+ }, [resources2]);
1806
+ react.useEffect(() => {
1807
+ if (typeof resources2 === "function") {
1808
+ loadAsyncResources(resources2, localeCode).catch((error) => {
1809
+ });
1810
+ } else {
1811
+ registerResources(resources2, localeCode);
1812
+ }
1813
+ }, [localeCode, resources2]);
1814
+ }
1723
1815
  var LocaleProvider = (props) => {
1724
1816
  const { children, locale, resource, resources: resources2, ...languageProviderProps } = props;
1725
- const localeCodeFromI18n = useLocaleCode();
1817
+ useRegisterExternalResources(resources2);
1726
1818
  react.useEffect(() => {
1727
- if (resources2) {
1728
- registerResources(resources2, locale ?? localeCodeFromI18n);
1729
- return;
1730
- }
1731
- if (resource && locale) {
1819
+ if (!resources2 && resource && locale) {
1732
1820
  i18n_default.addResourceBundle(locale, defaultNS, resource, true, true);
1733
1821
  }
1734
- }, [locale, localeCodeFromI18n, resource, resources2]);
1822
+ }, [locale, resource, resources2]);
1735
1823
  react.useEffect(() => {
1736
1824
  if (locale && locale !== i18n_default.language) {
1737
1825
  i18n_default.changeLanguage(locale);
@@ -1739,12 +1827,6 @@ var LocaleProvider = (props) => {
1739
1827
  }, [locale]);
1740
1828
  return /* @__PURE__ */ jsxRuntime.jsx(LanguageProvider, { ...languageProviderProps, children: /* @__PURE__ */ jsxRuntime.jsx(reactI18next.I18nextProvider, { i18n: i18n_default, defaultNS, children }) });
1741
1829
  };
1742
- function useRegisterExternalResources(resources2) {
1743
- const localeCode = useLocaleCode();
1744
- react.useEffect(() => {
1745
- registerResources(resources2, localeCode);
1746
- }, [localeCode, resources2]);
1747
- }
1748
1830
  var ExternalLocaleProvider = (props) => {
1749
1831
  useRegisterExternalResources(props.resources);
1750
1832
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });