@orderly.network/i18n 2.12.0 → 2.12.1-alpha.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 (58) hide show
  1. package/README.md +27 -314
  2. package/bin/cli.js +92 -37
  3. package/dist/{constant-D_rlt5w0.d.mts → constant-DkvDyddr.d.mts} +12 -40
  4. package/dist/{constant-D_rlt5w0.d.ts → constant-DkvDyddr.d.ts} +12 -40
  5. package/dist/constant.d.mts +1 -1
  6. package/dist/constant.d.ts +1 -1
  7. package/dist/constant.js.map +1 -1
  8. package/dist/constant.mjs.map +1 -1
  9. package/dist/index.d.mts +84 -20
  10. package/dist/index.d.ts +84 -20
  11. package/dist/index.js +138 -107
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +129 -106
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/locale.csv +7 -105
  16. package/dist/locales/de.json +7 -37
  17. package/dist/locales/en.json +7 -37
  18. package/dist/locales/es.json +7 -37
  19. package/dist/locales/fr.json +7 -37
  20. package/dist/locales/id.json +7 -37
  21. package/dist/locales/it.json +7 -37
  22. package/dist/locales/ja.json +7 -37
  23. package/dist/locales/ko.json +7 -37
  24. package/dist/locales/nl.json +7 -37
  25. package/dist/locales/pl.json +7 -37
  26. package/dist/locales/pt.json +7 -37
  27. package/dist/locales/ru.json +7 -37
  28. package/dist/locales/tc.json +7 -37
  29. package/dist/locales/tr.json +7 -37
  30. package/dist/locales/uk.json +7 -37
  31. package/dist/locales/vi.json +7 -37
  32. package/dist/locales/zh.json +7 -37
  33. package/dist/utils.d.mts +1 -1
  34. package/dist/utils.d.ts +1 -1
  35. package/dist/utils.js +25 -50
  36. package/dist/utils.js.map +1 -1
  37. package/dist/utils.mjs +25 -50
  38. package/dist/utils.mjs.map +1 -1
  39. package/docs/guide/AGENTS.md +109 -0
  40. package/docs/guide/cli.md +133 -0
  41. package/docs/guide/examples.md +455 -0
  42. package/docs/guide/exports.md +14 -0
  43. package/docs/guide/integration.md +223 -0
  44. package/docs/guide/utils.md +14 -0
  45. package/package.json +13 -11
  46. package/{script → scripts}/copyLocales.js +1 -1
  47. package/scripts/filterLocaleKeys.js +127 -0
  48. package/{script → scripts}/generateCsv.js +3 -3
  49. package/{script → scripts}/utils.js +20 -14
  50. /package/{script → scripts}/csv2json.js +0 -0
  51. /package/{script → scripts}/diffCsv.js +0 -0
  52. /package/{script → scripts}/fillJson.js +0 -0
  53. /package/{script → scripts}/generateEnJson.js +0 -0
  54. /package/{script → scripts}/generateMissingKeys.js +0 -0
  55. /package/{script → scripts}/json-csv-converter.js +0 -0
  56. /package/{script → scripts}/json2csv.js +0 -0
  57. /package/{script → scripts}/mergeJson.js +0 -0
  58. /package/{script → scripts}/separateJson.js +0 -0
package/dist/index.js CHANGED
@@ -99,6 +99,10 @@ var affiliate = {
99
99
  "affiliate.referralCode.label": "Enter referral code",
100
100
  "affiliate.referralCode.bound": "Referral code bound",
101
101
  "affiliate.referralCode.notExist": "This referral code does not exist.",
102
+ "affiliate.referralCode.bind.modal.title": "Were you referred by someone?",
103
+ "affiliate.referralCode.bind.modal.description": "If an affiliate shared their referral code with you, enter it below to bind your account and receive affiliate benefits.",
104
+ "affiliate.referralCode.bind.input.placeholder": "Enter referrer's code",
105
+ "affiliate.referralCode.bind.skip": "No, I was not referred by anyone",
102
106
  "affiliate.process.title": "How It Works",
103
107
  "affiliate.process.step1.title": "Trade $10,000+ or apply",
104
108
  "affiliate.process.step1.description": "Unlock a referral code automatically ($0 of $10,000 completed - main account only), or apply for a higher rate via the form.",
@@ -160,6 +164,7 @@ var affiliate = {
160
164
  "affiliate.direct": "Direct",
161
165
  "affiliate.directInclBonus": "Incl. {{amount}} bonus",
162
166
  "affiliate.indirect": "Indirect",
167
+ "affiliate.referredBy": "Referred by {{name}}",
163
168
  "affiliate.referrals": "Referrals",
164
169
  "affiliate.referralCode.edit.modal.title": "Configure your referral settings",
165
170
  "affiliate.referralCode.create": "Create referral code",
@@ -519,6 +524,11 @@ var markets = {
519
524
  "markets.symbolInfoBar.riskNotice.content": "{{symbolWithBroker}} is a permissionless listing supported on Isolated Margin only, deployed and operated independently by {{brokerName}}. Please be aware of elevated risks, including low liquidity, high volatility, and increased liquidation risk."
520
525
  };
521
526
 
527
+ // src/locale/module/navigation.ts
528
+ var navigation = {
529
+ "tradingPoints.points": "Points"
530
+ };
531
+
522
532
  // src/locale/module/notification.ts
523
533
  var notification = {
524
534
  // Announcement related keys
@@ -1120,46 +1130,6 @@ var tradingLeaderboard = {
1120
1130
  "tradingLeaderboard.tradingVolume.tooltip": "Total trading volume generated during the campaign period. Updated every 30 seconds."
1121
1131
  };
1122
1132
 
1123
- // src/locale/module/tradingPoints.ts
1124
- var tradingPoints = {
1125
- "tradingPoints.points": "Points",
1126
- "tradingPoints.startsIn": "Starts in",
1127
- "tradingPoints.days": "Days",
1128
- "tradingPoints.hours": "Hours",
1129
- "tradingPoints.minutes": "Minutes",
1130
- "tradingPoints.seconds": "Seconds",
1131
- "tradingPoints.learnMore": "Learn more",
1132
- "tradingPoints.stagePoints": "Stage points",
1133
- "tradingPoints.stageRanking": "Stage ranking",
1134
- "tradingPoints.referralCode": "Referral code",
1135
- "tradingPoints.referralLink": "Referral link",
1136
- "tradingPoints.currentPoints": "Current points",
1137
- "tradingPoints.ranking": "Ranking",
1138
- "tradingPoints.myPoints": "My points",
1139
- "tradingPoints.thisWeek": "This week",
1140
- "tradingPoints.lastWeek": "Last week",
1141
- "tradingPoints.all": "All",
1142
- "tradingPoints.tradePoints": "Trade points",
1143
- "tradingPoints.tradePointsTooltip": "Trade Points are calculated based on your perps trading volume.Updated daily.",
1144
- "tradingPoints.tradeNow": "Trade now",
1145
- "tradingPoints.pnlPoints": "PNL points",
1146
- "tradingPoints.pnlPointsTooltip": "Both profit or loss of each trade will be recorded. Updated daily.",
1147
- "tradingPoints.referralPoints": "Referral points",
1148
- "tradingPoints.referralPointsTooltip": "First-level invitee's rebates: {{l1}}%, Second-level invitee's rebates: {{l2}}%, Update daily.",
1149
- "tradingPoints.copyLink": "Copy Link",
1150
- "tradingPoints.faq.title": "FAQ",
1151
- "tradingPoints.faq.whatArePoints.question": "What are Points?",
1152
- "tradingPoints.faq.whatArePoints.answer": "The Points program is designed to encourage genuine user engagement with products and to reward loyal users who actively contribute to the growth of the {{brokerName}} ecosystem. Rewards will be airdropped in the future based on users' point accumulation.",
1153
- "tradingPoints.faq.allocation.question": "What is the points allocation criteria?",
1154
- "tradingPoints.faq.allocation.answer": "Points = Trade points + PNL points + Referral points.\n\nThe page will update your points daily, calculating the points you are expected to receive based on your contribution.\n\nNote: Wash trading (e.g., self-trades) will not receive any points",
1155
- "tradingPoints.faq.distribution.question": "When will points be distributed?",
1156
- "tradingPoints.faq.distribution.answer": "Points are distributed at 08:00 UTC everyday.",
1157
- "tradingPoints.faq.pnl.question": "How are PNL points calculated?",
1158
- "tradingPoints.faq.pnl.answer": "Points are based on your net profit or loss each trading.",
1159
- "tradingPoints.faq.referral.question": "How does the referral work?",
1160
- "tradingPoints.faq.referral.answer": "Based on the total points of your invitees and their invitees. Points earned from first-level invitees are higher than those from second-level invitees. Updated daily."
1161
- };
1162
-
1163
1133
  // src/locale/module/tradingRewards.ts
1164
1134
  var tradingRewards = {
1165
1135
  "tradingRewards.rewards": "Rewards",
@@ -1504,10 +1474,10 @@ var en = {
1504
1474
  ...affiliate,
1505
1475
  ...ui,
1506
1476
  ...tradingLeaderboard,
1507
- ...tradingPoints,
1508
1477
  ...widget,
1509
1478
  ...vaults,
1510
- ...notification
1479
+ ...notification,
1480
+ ...navigation
1511
1481
  };
1512
1482
 
1513
1483
  // src/i18n.ts
@@ -1519,19 +1489,46 @@ var languageDetector = new LanguageDetector__default.default(null, {
1519
1489
  lookupCookie: i18nCookieKey,
1520
1490
  caches: ["localStorage", "cookie"]
1521
1491
  });
1522
- var i18n = i18next.createInstance({
1523
- // lng: defaultLng,
1524
- fallbackLng: defaultLng,
1525
- // debug: true,
1526
- interpolation: {
1527
- escapeValue: false
1528
- },
1492
+ function createI18nInstance(options) {
1493
+ return i18next.createInstance({
1494
+ // lng: defaultLng,
1495
+ fallbackLng: defaultLng,
1496
+ // debug: true,
1497
+ interpolation: {
1498
+ escapeValue: false
1499
+ },
1500
+ ...options
1501
+ }).use(languageDetector);
1502
+ }
1503
+ var i18n = createI18nInstance({
1529
1504
  resources
1530
- }).use(languageDetector);
1505
+ });
1531
1506
  i18n.init();
1532
1507
  var i18n_default = i18n;
1508
+ var LanguageContext = react.createContext({
1509
+ languages: [],
1510
+ onLanguageBeforeChanged: () => Promise.resolve(),
1511
+ onLanguageChanged: () => Promise.resolve()
1512
+ });
1513
+ var useLanguageContext = () => {
1514
+ return react.useContext(LanguageContext);
1515
+ };
1533
1516
 
1534
- // src/backend.ts
1517
+ // src/resourceBundles/registerResources.ts
1518
+ async function registerResources(resources2, localeCode) {
1519
+ if (typeof resources2 === "function") {
1520
+ const resource = await resources2(localeCode, defaultNS);
1521
+ i18n_default.addResourceBundle(localeCode, defaultNS, resource, true, true);
1522
+ return;
1523
+ }
1524
+ if (resources2) {
1525
+ Object.entries(resources2).forEach(([locale, messages]) => {
1526
+ i18n_default.addResourceBundle(locale, defaultNS, messages, true, true);
1527
+ });
1528
+ }
1529
+ }
1530
+
1531
+ // src/resourceBundles/httpBackend.ts
1535
1532
  var Backend = class {
1536
1533
  constructor(options) {
1537
1534
  this.options = options;
@@ -1575,15 +1572,38 @@ var Backend = class {
1575
1572
  await Promise.all(promises);
1576
1573
  }
1577
1574
  };
1578
- var LocaleContext = react.createContext({
1579
- languages: [],
1580
- onLanguageBeforeChanged: () => Promise.resolve(),
1581
- onLanguageChanged: () => Promise.resolve()
1582
- });
1583
- var useLocaleContext = () => {
1584
- return react.useContext(LocaleContext);
1575
+
1576
+ // src/resourceBundles/registerDefaultResource.ts
1577
+ var registerDefaultResource = (messages) => {
1578
+ i18n_default.addResourceBundle(defaultLng, defaultNS, messages, true, true);
1585
1579
  };
1586
1580
 
1581
+ // src/resourceBundles/importLocaleJsonModule.ts
1582
+ function asMessageRecord(value) {
1583
+ if (!value) {
1584
+ return {};
1585
+ }
1586
+ if (typeof value !== "string") {
1587
+ return value;
1588
+ }
1589
+ try {
1590
+ return JSON.parse(value);
1591
+ } catch {
1592
+ return {};
1593
+ }
1594
+ }
1595
+ async function importLocaleJsonModule(loader) {
1596
+ if (!loader) {
1597
+ return asMessageRecord(void 0);
1598
+ }
1599
+ try {
1600
+ const mod = await loader();
1601
+ return asMessageRecord(mod.default);
1602
+ } catch {
1603
+ return {};
1604
+ }
1605
+ }
1606
+
1587
1607
  // src/utils.ts
1588
1608
  function parseI18nLang(lang, localeCodes, defaultLang) {
1589
1609
  localeCodes = localeCodes || Object.values(LocaleEnum);
@@ -1621,45 +1641,18 @@ function generatePath(params) {
1621
1641
  localePath = locale || parseI18nLang(i18n_default.language);
1622
1642
  return `/${localePath}${path}${searchUrl}`;
1623
1643
  }
1624
- var I18nProvider = (props) => {
1625
- const { children, ...rest } = props;
1626
- return (
1627
- // @ts-ignore
1628
- /* @__PURE__ */ jsxRuntime.jsx(reactI18next.I18nextProvider, { ...rest, children })
1629
- );
1630
- };
1631
- var LocaleProvider = (props) => {
1644
+ var LanguageProvider = (props) => {
1632
1645
  const {
1633
1646
  children,
1634
- locale,
1635
- resource,
1636
- resources: resources2,
1637
1647
  backend,
1638
1648
  popup,
1639
1649
  supportedLanguages,
1640
1650
  onLanguageChanged,
1641
1651
  convertDetectedLanguage,
1642
- onLanguageBeforeChanged,
1643
- onLocaleChange
1652
+ onLanguageBeforeChanged
1644
1653
  } = props;
1645
1654
  const [languages, setLanguages] = react.useState(defaultLanguages);
1646
1655
  const backendRef = react.useRef(new Backend(backend));
1647
- react.useEffect(() => {
1648
- if (resources2) {
1649
- Object.entries(resources2).forEach(([locale2, messages]) => {
1650
- i18n_default.addResourceBundle(locale2, defaultNS, messages, true, true);
1651
- });
1652
- return;
1653
- }
1654
- if (resource && locale) {
1655
- i18n_default.addResourceBundle(locale, defaultNS, resource, true, true);
1656
- }
1657
- }, [locale, resource, resources2]);
1658
- react.useEffect(() => {
1659
- if (locale && locale !== i18n_default.language) {
1660
- i18n_default.changeLanguage(locale);
1661
- }
1662
- }, [locale]);
1663
1656
  react.useEffect(() => {
1664
1657
  if (Array.isArray(props.languages)) {
1665
1658
  setLanguages(props.languages);
@@ -1670,7 +1663,7 @@ var LocaleProvider = (props) => {
1670
1663
  ).filter((item) => !!item)
1671
1664
  );
1672
1665
  }
1673
- }, [supportedLanguages, props.languages]);
1666
+ }, [props.languages, supportedLanguages]);
1674
1667
  react.useEffect(() => {
1675
1668
  const initLanguage = async () => {
1676
1669
  const lang = typeof convertDetectedLanguage === "function" ? convertDetectedLanguage(i18n_default.language) : parseI18nLang(i18n_default.language);
@@ -1691,9 +1684,8 @@ var LocaleProvider = (props) => {
1691
1684
  const languageChangedHandle = react.useCallback(
1692
1685
  async (lang) => {
1693
1686
  onLanguageChanged?.(lang);
1694
- onLocaleChange?.(lang);
1695
1687
  },
1696
- [onLanguageChanged, onLocaleChange]
1688
+ [onLanguageChanged]
1697
1689
  );
1698
1690
  const memoizedValue = react.useMemo(() => {
1699
1691
  return {
@@ -1703,30 +1695,61 @@ var LocaleProvider = (props) => {
1703
1695
  onLanguageChanged: languageChangedHandle
1704
1696
  };
1705
1697
  }, [popup, languages, languageBeforeChangedHandle, languageChangedHandle]);
1706
- return /* @__PURE__ */ jsxRuntime.jsx(LocaleContext.Provider, { value: memoizedValue, children: /* @__PURE__ */ jsxRuntime.jsx(reactI18next.I18nextProvider, { i18n: i18n_default, defaultNS, children }) });
1698
+ return /* @__PURE__ */ jsxRuntime.jsx(LanguageContext.Provider, { value: memoizedValue, children });
1707
1699
  };
1708
- function useTranslation(ns, options) {
1709
- const context = react.useContext(reactI18next.I18nContext);
1710
- return reactI18next.useTranslation(ns, {
1711
- i18n: context?.i18n || i18n_default,
1712
- // @ts-ignore
1713
- // when the language resource is loaded, notify the translation component to re-render
1714
- bindI18nStore: "added",
1715
- ...options
1716
- });
1717
- }
1718
1700
  function useLocaleCode() {
1719
- const [loacaleCode, setLoacaleCode] = react.useState(i18n_default.language);
1701
+ const [localeCode, setLocaleCode] = react.useState(
1702
+ parseI18nLang(i18n_default.language)
1703
+ );
1720
1704
  react.useEffect(() => {
1721
1705
  const handleLanguageChange = (lng) => {
1722
- setLoacaleCode(lng);
1706
+ setLocaleCode(lng);
1723
1707
  };
1724
1708
  i18n_default.on("languageChanged", handleLanguageChange);
1725
1709
  return () => {
1726
1710
  i18n_default.off("languageChanged", handleLanguageChange);
1727
1711
  };
1728
1712
  }, [i18n_default]);
1729
- return loacaleCode;
1713
+ return localeCode;
1714
+ }
1715
+ var LocaleProvider = (props) => {
1716
+ const { children, locale, resource, resources: resources2, ...languageProviderProps } = props;
1717
+ const localeCodeFromI18n = useLocaleCode();
1718
+ react.useEffect(() => {
1719
+ if (resources2) {
1720
+ registerResources(resources2, locale ?? localeCodeFromI18n);
1721
+ return;
1722
+ }
1723
+ if (resource && locale) {
1724
+ i18n_default.addResourceBundle(locale, defaultNS, resource, true, true);
1725
+ }
1726
+ }, [locale, localeCodeFromI18n, resource, resources2]);
1727
+ react.useEffect(() => {
1728
+ if (locale && locale !== i18n_default.language) {
1729
+ i18n_default.changeLanguage(locale);
1730
+ }
1731
+ }, [locale]);
1732
+ return /* @__PURE__ */ jsxRuntime.jsx(LanguageProvider, { ...languageProviderProps, children: /* @__PURE__ */ jsxRuntime.jsx(reactI18next.I18nextProvider, { i18n: i18n_default, defaultNS, children }) });
1733
+ };
1734
+ function useRegisterExternalResources(resources2) {
1735
+ const localeCode = useLocaleCode();
1736
+ react.useEffect(() => {
1737
+ registerResources(resources2, localeCode);
1738
+ }, [localeCode, resources2]);
1739
+ }
1740
+ var ExternalLocaleProvider = (props) => {
1741
+ useRegisterExternalResources(props.resources);
1742
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
1743
+ };
1744
+ function useTranslation(ns, options) {
1745
+ const context = react.useContext(reactI18next.I18nContext);
1746
+ return reactI18next.useTranslation(ns, {
1747
+ i18n: context?.i18n || i18n_default,
1748
+ // @ts-ignore
1749
+ // when the language resource is loaded, notify the translation component to re-render
1750
+ bindI18nStore: "added",
1751
+ ...options
1752
+ });
1730
1753
  }
1731
1754
 
1732
1755
  Object.defineProperty(exports, "createInstance", {
@@ -1737,10 +1760,14 @@ Object.defineProperty(exports, "i18next", {
1737
1760
  enumerable: true,
1738
1761
  get: function () { return i18next__default.default; }
1739
1762
  });
1740
- exports.I18nProvider = I18nProvider;
1741
- exports.LocaleContext = LocaleContext;
1763
+ exports.Backend = Backend;
1764
+ exports.ExternalLocaleProvider = ExternalLocaleProvider;
1765
+ exports.LanguageContext = LanguageContext;
1766
+ exports.LanguageProvider = LanguageProvider;
1742
1767
  exports.LocaleEnum = LocaleEnum;
1743
1768
  exports.LocaleProvider = LocaleProvider;
1769
+ exports.asMessageRecord = asMessageRecord;
1770
+ exports.createI18nInstance = createI18nInstance;
1744
1771
  exports.defaultLanguages = defaultLanguages;
1745
1772
  exports.defaultLng = defaultLng;
1746
1773
  exports.defaultNS = defaultNS;
@@ -1750,10 +1777,14 @@ exports.getLocalePathFromPathname = getLocalePathFromPathname;
1750
1777
  exports.i18n = i18n_default;
1751
1778
  exports.i18nCookieKey = i18nCookieKey;
1752
1779
  exports.i18nLocalStorageKey = i18nLocalStorageKey;
1780
+ exports.importLocaleJsonModule = importLocaleJsonModule;
1753
1781
  exports.parseI18nLang = parseI18nLang;
1782
+ exports.registerDefaultResource = registerDefaultResource;
1783
+ exports.registerResources = registerResources;
1754
1784
  exports.removeLangPrefix = removeLangPrefix;
1785
+ exports.useLanguageContext = useLanguageContext;
1755
1786
  exports.useLocaleCode = useLocaleCode;
1756
- exports.useLocaleContext = useLocaleContext;
1787
+ exports.useRegisterExternalResources = useRegisterExternalResources;
1757
1788
  exports.useTranslation = useTranslation;
1758
1789
  Object.keys(reactI18next).forEach(function (k) {
1759
1790
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {