@orderly.network/i18n 2.10.2 → 3.0.0-beta.0

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.
Files changed (49) hide show
  1. package/README.md +193 -34
  2. package/bin/cli.js +92 -37
  3. package/dist/{constant-UZhfXyyb.d.mts → constant-BeXwHrGj.d.mts} +27 -0
  4. package/dist/{constant-UZhfXyyb.d.ts → constant-BeXwHrGj.d.ts} +27 -0
  5. package/dist/constant.d.mts +1 -1
  6. package/dist/constant.d.ts +1 -1
  7. package/dist/index.d.mts +34 -9
  8. package/dist/index.d.ts +34 -9
  9. package/dist/index.js +80 -17
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +79 -19
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/locale.csv +30 -3
  14. package/dist/locales/de.json +30 -3
  15. package/dist/locales/en.json +30 -3
  16. package/dist/locales/es.json +30 -3
  17. package/dist/locales/fr.json +30 -3
  18. package/dist/locales/id.json +30 -3
  19. package/dist/locales/it.json +30 -3
  20. package/dist/locales/ja.json +30 -3
  21. package/dist/locales/ko.json +30 -3
  22. package/dist/locales/nl.json +30 -3
  23. package/dist/locales/pl.json +30 -3
  24. package/dist/locales/pt.json +30 -3
  25. package/dist/locales/ru.json +30 -3
  26. package/dist/locales/tc.json +30 -3
  27. package/dist/locales/tr.json +30 -3
  28. package/dist/locales/uk.json +30 -3
  29. package/dist/locales/vi.json +30 -3
  30. package/dist/locales/zh.json +30 -3
  31. package/dist/utils.d.mts +1 -1
  32. package/dist/utils.d.ts +1 -1
  33. package/dist/utils.js +46 -12
  34. package/dist/utils.js.map +1 -1
  35. package/dist/utils.mjs +46 -12
  36. package/dist/utils.mjs.map +1 -1
  37. package/package.json +7 -7
  38. package/script/copyLocales.js +0 -11
  39. package/script/csv2json.js +0 -28
  40. package/script/diffCsv.js +0 -175
  41. package/script/fillJson.js +0 -33
  42. package/script/generateCsv.js +0 -36
  43. package/script/generateEnJson.js +0 -11
  44. package/script/generateMissingKeys.js +0 -49
  45. package/script/json-csv-converter.js +0 -286
  46. package/script/json2csv.js +0 -38
  47. package/script/mergeJson.js +0 -67
  48. package/script/separateJson.js +0 -50
  49. package/script/utils.js +0 -88
package/dist/index.d.mts CHANGED
@@ -1,15 +1,16 @@
1
- import { L as LocaleCode, R as Resources, a as LocaleContextState } from './constant-UZhfXyyb.mjs';
2
- export { b as Language, d as LocaleContext, 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 useLocaleContext } from './constant-UZhfXyyb.mjs';
1
+ import { L as LocaleCode, R as Resources, a as LocaleContextState } from './constant-BeXwHrGj.mjs';
2
+ export { b as Language, d as LocaleContext, 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 useLocaleContext } from './constant-BeXwHrGj.mjs';
3
3
  import * as react_i18next from 'react-i18next';
4
4
  import { I18nextProviderProps, FallbackNs, UseTranslationOptions } from 'react-i18next';
5
5
  export * from 'react-i18next';
6
6
  import * as i18next from 'i18next';
7
- import { FlatNamespace, KeyPrefix } from 'i18next';
7
+ import { InitOptions, FlatNamespace, KeyPrefix } from 'i18next';
8
8
  export { createInstance, default as i18next } from 'i18next';
9
- import { ReactNode } from 'react';
9
+ import { ReactNode, PropsWithChildren, FC } from 'react';
10
10
  import { $Tuple } from 'react-i18next/helpers';
11
11
  export { generatePath, getLocalePathFromPathname, parseI18nLang, removeLangPrefix } from './utils.mjs';
12
12
 
13
+ declare function createI18nInstance(options?: InitOptions): i18next.i18n;
13
14
  declare const i18n: i18next.i18n;
14
15
 
15
16
  type BackendOptions = {
@@ -27,10 +28,6 @@ type LocaleProviderProps = {
27
28
  * supported languages, you can select supported languages from default languages
28
29
  */
29
30
  supportedLanguages?: LocaleCode[];
30
- /**
31
- * @deprecated use onLanguageChanged instead, will be removed in next patch version
32
- */
33
- onLocaleChange?: (locale: LocaleCode) => void;
34
31
  /** optional conversion function to use to modify the detected language code */
35
32
  convertDetectedLanguage?: (lang: string) => LocaleCode;
36
33
  backend?: BackendOptions;
@@ -41,4 +38,32 @@ declare function useTranslation<Ns extends FlatNamespace | $Tuple<FlatNamespace>
41
38
 
42
39
  declare function useLocaleCode(): LocaleCode;
43
40
 
44
- export { I18nProvider, type I18nProviderProps, LocaleCode, LocaleContextState, LocaleProvider, type LocaleProviderProps, Resources, i18n, useLocaleCode, useTranslation };
41
+ /**
42
+ * preload default locale resources to prevent flickering of raw translation keys
43
+ */
44
+ declare const preloadDefaultResource: (messages: Record<string, string>) => void;
45
+
46
+ /**
47
+ * Async loader contract for pulling translation resources from an external system.
48
+ * Implementations are expected to return the full message table for the given locale
49
+ * and namespace so that the bundle can be replaced atomically.
50
+ */
51
+ type AsyncResources = (lang: LocaleCode, ns: string) => Promise<Record<string, string>>;
52
+ type ExternalLocaleProviderProps = PropsWithChildren<{
53
+ resources?: Resources | AsyncResources;
54
+ }>;
55
+ /**
56
+ * ExternalLocaleProvider lets host applications inject i18n resources that live
57
+ * outside of this package (e.g. from another bundle, backend, or runtime loader).
58
+ *
59
+ * - When `resources` is a function, it will be invoked whenever the locale changes
60
+ * to lazily fetch the latest bundle for that locale.
61
+ * - When `resources` is a static map, all provided locale bundles are registered
62
+ * synchronously on mount.
63
+ *
64
+ * This component renders no UI; it only manages i18n side effects and simply
65
+ * returns its children.
66
+ */
67
+ declare const ExternalLocaleProvider: FC<ExternalLocaleProviderProps>;
68
+
69
+ export { type AsyncResources, ExternalLocaleProvider, type ExternalLocaleProviderProps, I18nProvider, type I18nProviderProps, LocaleCode, LocaleContextState, LocaleProvider, type LocaleProviderProps, Resources, createI18nInstance, i18n, preloadDefaultResource, useLocaleCode, useTranslation };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,16 @@
1
- import { L as LocaleCode, R as Resources, a as LocaleContextState } from './constant-UZhfXyyb.js';
2
- export { b as Language, d as LocaleContext, 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 useLocaleContext } from './constant-UZhfXyyb.js';
1
+ import { L as LocaleCode, R as Resources, a as LocaleContextState } from './constant-BeXwHrGj.js';
2
+ export { b as Language, d as LocaleContext, 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 useLocaleContext } from './constant-BeXwHrGj.js';
3
3
  import * as react_i18next from 'react-i18next';
4
4
  import { I18nextProviderProps, FallbackNs, UseTranslationOptions } from 'react-i18next';
5
5
  export * from 'react-i18next';
6
6
  import * as i18next from 'i18next';
7
- import { FlatNamespace, KeyPrefix } from 'i18next';
7
+ import { InitOptions, FlatNamespace, KeyPrefix } from 'i18next';
8
8
  export { createInstance, default as i18next } from 'i18next';
9
- import { ReactNode } from 'react';
9
+ import { ReactNode, PropsWithChildren, FC } from 'react';
10
10
  import { $Tuple } from 'react-i18next/helpers';
11
11
  export { generatePath, getLocalePathFromPathname, parseI18nLang, removeLangPrefix } from './utils.js';
12
12
 
13
+ declare function createI18nInstance(options?: InitOptions): i18next.i18n;
13
14
  declare const i18n: i18next.i18n;
14
15
 
15
16
  type BackendOptions = {
@@ -27,10 +28,6 @@ type LocaleProviderProps = {
27
28
  * supported languages, you can select supported languages from default languages
28
29
  */
29
30
  supportedLanguages?: LocaleCode[];
30
- /**
31
- * @deprecated use onLanguageChanged instead, will be removed in next patch version
32
- */
33
- onLocaleChange?: (locale: LocaleCode) => void;
34
31
  /** optional conversion function to use to modify the detected language code */
35
32
  convertDetectedLanguage?: (lang: string) => LocaleCode;
36
33
  backend?: BackendOptions;
@@ -41,4 +38,32 @@ declare function useTranslation<Ns extends FlatNamespace | $Tuple<FlatNamespace>
41
38
 
42
39
  declare function useLocaleCode(): LocaleCode;
43
40
 
44
- export { I18nProvider, type I18nProviderProps, LocaleCode, LocaleContextState, LocaleProvider, type LocaleProviderProps, Resources, i18n, useLocaleCode, useTranslation };
41
+ /**
42
+ * preload default locale resources to prevent flickering of raw translation keys
43
+ */
44
+ declare const preloadDefaultResource: (messages: Record<string, string>) => void;
45
+
46
+ /**
47
+ * Async loader contract for pulling translation resources from an external system.
48
+ * Implementations are expected to return the full message table for the given locale
49
+ * and namespace so that the bundle can be replaced atomically.
50
+ */
51
+ type AsyncResources = (lang: LocaleCode, ns: string) => Promise<Record<string, string>>;
52
+ type ExternalLocaleProviderProps = PropsWithChildren<{
53
+ resources?: Resources | AsyncResources;
54
+ }>;
55
+ /**
56
+ * ExternalLocaleProvider lets host applications inject i18n resources that live
57
+ * outside of this package (e.g. from another bundle, backend, or runtime loader).
58
+ *
59
+ * - When `resources` is a function, it will be invoked whenever the locale changes
60
+ * to lazily fetch the latest bundle for that locale.
61
+ * - When `resources` is a static map, all provided locale bundles are registered
62
+ * synchronously on mount.
63
+ *
64
+ * This component renders no UI; it only manages i18n side effects and simply
65
+ * returns its children.
66
+ */
67
+ declare const ExternalLocaleProvider: FC<ExternalLocaleProviderProps>;
68
+
69
+ export { type AsyncResources, ExternalLocaleProvider, type ExternalLocaleProviderProps, I18nProvider, type I18nProviderProps, LocaleCode, LocaleContextState, LocaleProvider, type LocaleProviderProps, Resources, createI18nInstance, i18n, preloadDefaultResource, useLocaleCode, useTranslation };
package/dist/index.js CHANGED
@@ -237,6 +237,7 @@ var chart = {
237
237
  // src/locale/module/common.ts
238
238
  var common = {
239
239
  "common.cancel": "Cancel",
240
+ "common.close": "Close",
240
241
  "common.confirm": "Confirm",
241
242
  "common.ok": "OK",
242
243
  "common.yes": "Yes",
@@ -619,6 +620,21 @@ var orderEntry = {
619
620
  "orderEntry.slTriggerPrice.error.max": "SL Price must be less than {{value}}",
620
621
  "orderEntry.total.error.min": "The order value should be greater or equal to {{value}} USDC",
621
622
  "orderEntry.initialMarginTotal.error.min": "The initial margin should be greater or equal to {{value}} USDC",
623
+ // Margin mode (Cross / Isolated)
624
+ "marginMode.switchMarginMode": "Switch Margin Mode",
625
+ "marginMode.cross": "Cross",
626
+ "marginMode.isolated": "Isolated",
627
+ "marginMode.crossMargin": "Cross Margin",
628
+ "marginMode.isolatedMargin": "Isolated Margin",
629
+ "marginMode.crossMarginDescription": "Margin and PnL are shared across positions. You may lose all positions if liquidation occurs.",
630
+ "marginMode.isolatedMarginDescription": "Margin and PnL are independent for each position. You'll only lose the current position if liquidation occurs.",
631
+ "marginMode.current": "Current",
632
+ "marginMode.marginModeSettings": "Margin mode settings",
633
+ "marginMode.updatedSuccessfully": "Updated successfully",
634
+ "marginMode.perpetualFutures": "Perpetual futures",
635
+ "marginMode.searchPlaceholder": "Search",
636
+ "marginMode.selectAll": "Select all",
637
+ "marginMode.setAs": "Set as",
622
638
  "orderEntry.startPrice.error.required": "Start price is required",
623
639
  "orderEntry.startPrice.error.min": "Start price must be greater than {{value}}",
624
640
  "orderEntry.startPrice.error.max": "Start price must be less than {{value}}",
@@ -813,9 +829,9 @@ var positions = {
813
829
  "positions.column.liqPrice": "Liq. price",
814
830
  "positions.column.unrealPnl.tooltip": "Current unrealized profit or loss on your open positions across all widgets calculated using Mark Price.",
815
831
  "positions.column.unrealPnl.priceBasis": "Unrealized PnL Price Basis",
816
- "positions.column.margin": "Maintenance Margin",
817
- "positions.column.margin.tooltip": "The minimum equity to keep your position.",
818
- "positions.column.margin.formula": "Margin = Position size * Mark price * MMR",
832
+ "positions.column.margin": "Margin",
833
+ "positions.column.margin.tooltip": "Isolated margin locked in the position",
834
+ "positions.column.margin.formula": "Margin = Position size * Open price * IMR",
819
835
  "positions.column.close": "Close",
820
836
  "positions.limitClose": "Limit close",
821
837
  "positions.limitClose.description": "You agree closing {{quantity}} {{base}} position at limit price.",
@@ -863,7 +879,19 @@ var positions = {
863
879
  "positions.reverse.marketOpenLong": "Market Open Long",
864
880
  "positions.reverse.marketOpenShort": "Market Open Short",
865
881
  "positions.reverse.reverseToLong": "Reverse to Long",
866
- "positions.reverse.reverseToShort": "Reverse to Short"
882
+ "positions.reverse.reverseToShort": "Reverse to Short",
883
+ // Adjust Margin
884
+ "positions.adjustMargin.title": "Adjust Margin",
885
+ "positions.adjustMargin.add": "Add Margin",
886
+ "positions.adjustMargin.reduce": "Reduce Margin",
887
+ "positions.adjustMargin.quantity": "Quantity",
888
+ "positions.adjustMargin.max": "Max",
889
+ "positions.adjustMargin.currentMargin": "Current margin:",
890
+ "positions.adjustMargin.liqPriceAfter": "Liquidation price after adjustment:",
891
+ "positions.adjustMargin.leverageAfter": "Effective leverage after adjustment:",
892
+ "positions.adjustMargin.success": "Margin adjusted successfully",
893
+ "positions.adjustMargin.failed": "Failed to adjust margin",
894
+ "positions.adjustMargin.marginCannotMoreThanMax": "Margin cannot be more than max"
867
895
  };
868
896
 
869
897
  // src/locale/module/scaffold.ts
@@ -1283,6 +1311,7 @@ var transfer = {
1283
1311
  "transfer.LTV.description": `LTV (Loan-to-Value) is the ratio between your negative USDC and the current value of your collateral. If your LTV exceeds {{threshold}}, your collateral will be automatically converted to USDC.`,
1284
1312
  "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.`,
1285
1313
  "transfer.LTV.currentLTV": "Current LTV",
1314
+ "transfer.LTV.isolatedModeUsdcOnly": "Only USDC can be used as margin in Isolated Mode.",
1286
1315
  "transfer.convert": "Convert",
1287
1316
  // "transfer.convert.note": "Please note that convert fees will be charged.",
1288
1317
  "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>",
@@ -1465,15 +1494,20 @@ var languageDetector = new LanguageDetector__default.default(null, {
1465
1494
  lookupCookie: i18nCookieKey,
1466
1495
  caches: ["localStorage", "cookie"]
1467
1496
  });
1468
- var i18n = i18next.createInstance({
1469
- // lng: defaultLng,
1470
- fallbackLng: defaultLng,
1471
- // debug: true,
1472
- interpolation: {
1473
- escapeValue: false
1474
- },
1497
+ function createI18nInstance(options) {
1498
+ return i18next.createInstance({
1499
+ // lng: defaultLng,
1500
+ fallbackLng: defaultLng,
1501
+ // debug: true,
1502
+ interpolation: {
1503
+ escapeValue: false
1504
+ },
1505
+ ...options
1506
+ }).use(languageDetector);
1507
+ }
1508
+ var i18n = createI18nInstance({
1475
1509
  resources
1476
- }).use(languageDetector);
1510
+ });
1477
1511
  i18n.init();
1478
1512
  var i18n_default = i18n;
1479
1513
 
@@ -1585,8 +1619,7 @@ var LocaleProvider = (props) => {
1585
1619
  supportedLanguages,
1586
1620
  onLanguageChanged,
1587
1621
  convertDetectedLanguage,
1588
- onLanguageBeforeChanged,
1589
- onLocaleChange
1622
+ onLanguageBeforeChanged
1590
1623
  } = props;
1591
1624
  const [languages, setLanguages] = react.useState(defaultLanguages);
1592
1625
  const backendRef = react.useRef(new Backend(backend));
@@ -1637,9 +1670,8 @@ var LocaleProvider = (props) => {
1637
1670
  const languageChangedHandle = react.useCallback(
1638
1671
  async (lang) => {
1639
1672
  onLanguageChanged?.(lang);
1640
- onLocaleChange?.(lang);
1641
1673
  },
1642
- [onLanguageChanged, onLocaleChange]
1674
+ [onLanguageChanged]
1643
1675
  );
1644
1676
  const memoizedValue = react.useMemo(() => {
1645
1677
  return {
@@ -1662,7 +1694,9 @@ function useTranslation(ns, options) {
1662
1694
  });
1663
1695
  }
1664
1696
  function useLocaleCode() {
1665
- const [loacaleCode, setLoacaleCode] = react.useState(i18n_default.language);
1697
+ const [loacaleCode, setLoacaleCode] = react.useState(
1698
+ parseI18nLang(i18n_default.language)
1699
+ );
1666
1700
  react.useEffect(() => {
1667
1701
  const handleLanguageChange = (lng) => {
1668
1702
  setLoacaleCode(lng);
@@ -1675,6 +1709,32 @@ function useLocaleCode() {
1675
1709
  return loacaleCode;
1676
1710
  }
1677
1711
 
1712
+ // src/external/utils.ts
1713
+ var preloadDefaultResource = (messages) => {
1714
+ i18n_default.addResourceBundle(defaultLng, defaultNS, messages, true, true);
1715
+ };
1716
+ var asyncAddResource = async (localeCode, resources2) => {
1717
+ const resource = await resources2(localeCode, defaultNS);
1718
+ i18n_default.addResourceBundle(localeCode, defaultNS, resource, true, true);
1719
+ };
1720
+ var ExternalLocaleProvider = (props) => {
1721
+ const { resources: resources2 } = props;
1722
+ const localeCode = useLocaleCode();
1723
+ react.useEffect(() => {
1724
+ if (typeof resources2 === "function") {
1725
+ asyncAddResource(localeCode, resources2);
1726
+ return;
1727
+ }
1728
+ if (resources2) {
1729
+ Object.entries(resources2).forEach(([locale, messages]) => {
1730
+ i18n_default.addResourceBundle(locale, defaultNS, messages, true, true);
1731
+ });
1732
+ return;
1733
+ }
1734
+ }, [localeCode, resources2]);
1735
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
1736
+ };
1737
+
1678
1738
  Object.defineProperty(exports, "createInstance", {
1679
1739
  enumerable: true,
1680
1740
  get: function () { return i18next.createInstance; }
@@ -1683,10 +1743,12 @@ Object.defineProperty(exports, "i18next", {
1683
1743
  enumerable: true,
1684
1744
  get: function () { return i18next__default.default; }
1685
1745
  });
1746
+ exports.ExternalLocaleProvider = ExternalLocaleProvider;
1686
1747
  exports.I18nProvider = I18nProvider;
1687
1748
  exports.LocaleContext = LocaleContext;
1688
1749
  exports.LocaleEnum = LocaleEnum;
1689
1750
  exports.LocaleProvider = LocaleProvider;
1751
+ exports.createI18nInstance = createI18nInstance;
1690
1752
  exports.defaultLanguages = defaultLanguages;
1691
1753
  exports.defaultLng = defaultLng;
1692
1754
  exports.defaultNS = defaultNS;
@@ -1697,6 +1759,7 @@ exports.i18n = i18n_default;
1697
1759
  exports.i18nCookieKey = i18nCookieKey;
1698
1760
  exports.i18nLocalStorageKey = i18nLocalStorageKey;
1699
1761
  exports.parseI18nLang = parseI18nLang;
1762
+ exports.preloadDefaultResource = preloadDefaultResource;
1700
1763
  exports.removeLangPrefix = removeLangPrefix;
1701
1764
  exports.useLocaleCode = useLocaleCode;
1702
1765
  exports.useLocaleContext = useLocaleContext;