@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.mjs CHANGED
@@ -4,7 +4,7 @@ import { I18nextProvider, I18nContext, useTranslation as useTranslation$1 } from
4
4
  export * from 'react-i18next';
5
5
  import LanguageDetector from 'i18next-browser-languagedetector';
6
6
  import { createContext, useContext, useState, useRef, useEffect, useCallback, useMemo } from 'react';
7
- import { jsx } from 'react/jsx-runtime';
7
+ import { jsx, Fragment } from 'react/jsx-runtime';
8
8
 
9
9
  // src/types.ts
10
10
 
@@ -94,6 +94,10 @@ var affiliate = {
94
94
  "affiliate.referralCode.label": "Enter referral code",
95
95
  "affiliate.referralCode.bound": "Referral code bound",
96
96
  "affiliate.referralCode.notExist": "This referral code does not exist.",
97
+ "affiliate.referralCode.bind.modal.title": "Were you referred by someone?",
98
+ "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.",
99
+ "affiliate.referralCode.bind.input.placeholder": "Enter referrer's code",
100
+ "affiliate.referralCode.bind.skip": "No, I was not referred by anyone",
97
101
  "affiliate.process.title": "How It Works",
98
102
  "affiliate.process.step1.title": "Trade $10,000+ or apply",
99
103
  "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.",
@@ -155,6 +159,7 @@ var affiliate = {
155
159
  "affiliate.direct": "Direct",
156
160
  "affiliate.directInclBonus": "Incl. {{amount}} bonus",
157
161
  "affiliate.indirect": "Indirect",
162
+ "affiliate.referredBy": "Referred by {{name}}",
158
163
  "affiliate.referrals": "Referrals",
159
164
  "affiliate.referralCode.edit.modal.title": "Configure your referral settings",
160
165
  "affiliate.referralCode.create": "Create referral code",
@@ -514,6 +519,11 @@ var markets = {
514
519
  "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."
515
520
  };
516
521
 
522
+ // src/locale/module/navigation.ts
523
+ var navigation = {
524
+ "tradingPoints.points": "Points"
525
+ };
526
+
517
527
  // src/locale/module/notification.ts
518
528
  var notification = {
519
529
  // Announcement related keys
@@ -1115,46 +1125,6 @@ var tradingLeaderboard = {
1115
1125
  "tradingLeaderboard.tradingVolume.tooltip": "Total trading volume generated during the campaign period. Updated every 30 seconds."
1116
1126
  };
1117
1127
 
1118
- // src/locale/module/tradingPoints.ts
1119
- var tradingPoints = {
1120
- "tradingPoints.points": "Points",
1121
- "tradingPoints.startsIn": "Starts in",
1122
- "tradingPoints.days": "Days",
1123
- "tradingPoints.hours": "Hours",
1124
- "tradingPoints.minutes": "Minutes",
1125
- "tradingPoints.seconds": "Seconds",
1126
- "tradingPoints.learnMore": "Learn more",
1127
- "tradingPoints.stagePoints": "Stage points",
1128
- "tradingPoints.stageRanking": "Stage ranking",
1129
- "tradingPoints.referralCode": "Referral code",
1130
- "tradingPoints.referralLink": "Referral link",
1131
- "tradingPoints.currentPoints": "Current points",
1132
- "tradingPoints.ranking": "Ranking",
1133
- "tradingPoints.myPoints": "My points",
1134
- "tradingPoints.thisWeek": "This week",
1135
- "tradingPoints.lastWeek": "Last week",
1136
- "tradingPoints.all": "All",
1137
- "tradingPoints.tradePoints": "Trade points",
1138
- "tradingPoints.tradePointsTooltip": "Trade Points are calculated based on your perps trading volume.Updated daily.",
1139
- "tradingPoints.tradeNow": "Trade now",
1140
- "tradingPoints.pnlPoints": "PNL points",
1141
- "tradingPoints.pnlPointsTooltip": "Both profit or loss of each trade will be recorded. Updated daily.",
1142
- "tradingPoints.referralPoints": "Referral points",
1143
- "tradingPoints.referralPointsTooltip": "First-level invitee's rebates: {{l1}}%, Second-level invitee's rebates: {{l2}}%, Update daily.",
1144
- "tradingPoints.copyLink": "Copy Link",
1145
- "tradingPoints.faq.title": "FAQ",
1146
- "tradingPoints.faq.whatArePoints.question": "What are Points?",
1147
- "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.",
1148
- "tradingPoints.faq.allocation.question": "What is the points allocation criteria?",
1149
- "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",
1150
- "tradingPoints.faq.distribution.question": "When will points be distributed?",
1151
- "tradingPoints.faq.distribution.answer": "Points are distributed at 08:00 UTC everyday.",
1152
- "tradingPoints.faq.pnl.question": "How are PNL points calculated?",
1153
- "tradingPoints.faq.pnl.answer": "Points are based on your net profit or loss each trading.",
1154
- "tradingPoints.faq.referral.question": "How does the referral work?",
1155
- "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."
1156
- };
1157
-
1158
1128
  // src/locale/module/tradingRewards.ts
1159
1129
  var tradingRewards = {
1160
1130
  "tradingRewards.rewards": "Rewards",
@@ -1499,10 +1469,10 @@ var en = {
1499
1469
  ...affiliate,
1500
1470
  ...ui,
1501
1471
  ...tradingLeaderboard,
1502
- ...tradingPoints,
1503
1472
  ...widget,
1504
1473
  ...vaults,
1505
- ...notification
1474
+ ...notification,
1475
+ ...navigation
1506
1476
  };
1507
1477
 
1508
1478
  // src/i18n.ts
@@ -1514,19 +1484,46 @@ var languageDetector = new LanguageDetector(null, {
1514
1484
  lookupCookie: i18nCookieKey,
1515
1485
  caches: ["localStorage", "cookie"]
1516
1486
  });
1517
- var i18n = createInstance({
1518
- // lng: defaultLng,
1519
- fallbackLng: defaultLng,
1520
- // debug: true,
1521
- interpolation: {
1522
- escapeValue: false
1523
- },
1487
+ function createI18nInstance(options) {
1488
+ return createInstance({
1489
+ // lng: defaultLng,
1490
+ fallbackLng: defaultLng,
1491
+ // debug: true,
1492
+ interpolation: {
1493
+ escapeValue: false
1494
+ },
1495
+ ...options
1496
+ }).use(languageDetector);
1497
+ }
1498
+ var i18n = createI18nInstance({
1524
1499
  resources
1525
- }).use(languageDetector);
1500
+ });
1526
1501
  i18n.init();
1527
1502
  var i18n_default = i18n;
1503
+ var LanguageContext = createContext({
1504
+ languages: [],
1505
+ onLanguageBeforeChanged: () => Promise.resolve(),
1506
+ onLanguageChanged: () => Promise.resolve()
1507
+ });
1508
+ var useLanguageContext = () => {
1509
+ return useContext(LanguageContext);
1510
+ };
1528
1511
 
1529
- // src/backend.ts
1512
+ // src/resourceBundles/registerResources.ts
1513
+ async function registerResources(resources2, localeCode) {
1514
+ if (typeof resources2 === "function") {
1515
+ const resource = await resources2(localeCode, defaultNS);
1516
+ i18n_default.addResourceBundle(localeCode, defaultNS, resource, true, true);
1517
+ return;
1518
+ }
1519
+ if (resources2) {
1520
+ Object.entries(resources2).forEach(([locale, messages]) => {
1521
+ i18n_default.addResourceBundle(locale, defaultNS, messages, true, true);
1522
+ });
1523
+ }
1524
+ }
1525
+
1526
+ // src/resourceBundles/httpBackend.ts
1530
1527
  var Backend = class {
1531
1528
  constructor(options) {
1532
1529
  this.options = options;
@@ -1570,15 +1567,38 @@ var Backend = class {
1570
1567
  await Promise.all(promises);
1571
1568
  }
1572
1569
  };
1573
- var LocaleContext = createContext({
1574
- languages: [],
1575
- onLanguageBeforeChanged: () => Promise.resolve(),
1576
- onLanguageChanged: () => Promise.resolve()
1577
- });
1578
- var useLocaleContext = () => {
1579
- return useContext(LocaleContext);
1570
+
1571
+ // src/resourceBundles/registerDefaultResource.ts
1572
+ var registerDefaultResource = (messages) => {
1573
+ i18n_default.addResourceBundle(defaultLng, defaultNS, messages, true, true);
1580
1574
  };
1581
1575
 
1576
+ // src/resourceBundles/importLocaleJsonModule.ts
1577
+ function asMessageRecord(value) {
1578
+ if (!value) {
1579
+ return {};
1580
+ }
1581
+ if (typeof value !== "string") {
1582
+ return value;
1583
+ }
1584
+ try {
1585
+ return JSON.parse(value);
1586
+ } catch {
1587
+ return {};
1588
+ }
1589
+ }
1590
+ async function importLocaleJsonModule(loader) {
1591
+ if (!loader) {
1592
+ return asMessageRecord(void 0);
1593
+ }
1594
+ try {
1595
+ const mod = await loader();
1596
+ return asMessageRecord(mod.default);
1597
+ } catch {
1598
+ return {};
1599
+ }
1600
+ }
1601
+
1582
1602
  // src/utils.ts
1583
1603
  function parseI18nLang(lang, localeCodes, defaultLang) {
1584
1604
  localeCodes = localeCodes || Object.values(LocaleEnum);
@@ -1616,45 +1636,18 @@ function generatePath(params) {
1616
1636
  localePath = locale || parseI18nLang(i18n_default.language);
1617
1637
  return `/${localePath}${path}${searchUrl}`;
1618
1638
  }
1619
- var I18nProvider = (props) => {
1620
- const { children, ...rest } = props;
1621
- return (
1622
- // @ts-ignore
1623
- /* @__PURE__ */ jsx(I18nextProvider, { ...rest, children })
1624
- );
1625
- };
1626
- var LocaleProvider = (props) => {
1639
+ var LanguageProvider = (props) => {
1627
1640
  const {
1628
1641
  children,
1629
- locale,
1630
- resource,
1631
- resources: resources2,
1632
1642
  backend,
1633
1643
  popup,
1634
1644
  supportedLanguages,
1635
1645
  onLanguageChanged,
1636
1646
  convertDetectedLanguage,
1637
- onLanguageBeforeChanged,
1638
- onLocaleChange
1647
+ onLanguageBeforeChanged
1639
1648
  } = props;
1640
1649
  const [languages, setLanguages] = useState(defaultLanguages);
1641
1650
  const backendRef = useRef(new Backend(backend));
1642
- useEffect(() => {
1643
- if (resources2) {
1644
- Object.entries(resources2).forEach(([locale2, messages]) => {
1645
- i18n_default.addResourceBundle(locale2, defaultNS, messages, true, true);
1646
- });
1647
- return;
1648
- }
1649
- if (resource && locale) {
1650
- i18n_default.addResourceBundle(locale, defaultNS, resource, true, true);
1651
- }
1652
- }, [locale, resource, resources2]);
1653
- useEffect(() => {
1654
- if (locale && locale !== i18n_default.language) {
1655
- i18n_default.changeLanguage(locale);
1656
- }
1657
- }, [locale]);
1658
1651
  useEffect(() => {
1659
1652
  if (Array.isArray(props.languages)) {
1660
1653
  setLanguages(props.languages);
@@ -1665,7 +1658,7 @@ var LocaleProvider = (props) => {
1665
1658
  ).filter((item) => !!item)
1666
1659
  );
1667
1660
  }
1668
- }, [supportedLanguages, props.languages]);
1661
+ }, [props.languages, supportedLanguages]);
1669
1662
  useEffect(() => {
1670
1663
  const initLanguage = async () => {
1671
1664
  const lang = typeof convertDetectedLanguage === "function" ? convertDetectedLanguage(i18n_default.language) : parseI18nLang(i18n_default.language);
@@ -1686,9 +1679,8 @@ var LocaleProvider = (props) => {
1686
1679
  const languageChangedHandle = useCallback(
1687
1680
  async (lang) => {
1688
1681
  onLanguageChanged?.(lang);
1689
- onLocaleChange?.(lang);
1690
1682
  },
1691
- [onLanguageChanged, onLocaleChange]
1683
+ [onLanguageChanged]
1692
1684
  );
1693
1685
  const memoizedValue = useMemo(() => {
1694
1686
  return {
@@ -1698,32 +1690,63 @@ var LocaleProvider = (props) => {
1698
1690
  onLanguageChanged: languageChangedHandle
1699
1691
  };
1700
1692
  }, [popup, languages, languageBeforeChangedHandle, languageChangedHandle]);
1701
- return /* @__PURE__ */ jsx(LocaleContext.Provider, { value: memoizedValue, children: /* @__PURE__ */ jsx(I18nextProvider, { i18n: i18n_default, defaultNS, children }) });
1693
+ return /* @__PURE__ */ jsx(LanguageContext.Provider, { value: memoizedValue, children });
1702
1694
  };
1703
- function useTranslation(ns, options) {
1704
- const context = useContext(I18nContext);
1705
- return useTranslation$1(ns, {
1706
- i18n: context?.i18n || i18n_default,
1707
- // @ts-ignore
1708
- // when the language resource is loaded, notify the translation component to re-render
1709
- bindI18nStore: "added",
1710
- ...options
1711
- });
1712
- }
1713
1695
  function useLocaleCode() {
1714
- const [loacaleCode, setLoacaleCode] = useState(i18n_default.language);
1696
+ const [localeCode, setLocaleCode] = useState(
1697
+ parseI18nLang(i18n_default.language)
1698
+ );
1715
1699
  useEffect(() => {
1716
1700
  const handleLanguageChange = (lng) => {
1717
- setLoacaleCode(lng);
1701
+ setLocaleCode(lng);
1718
1702
  };
1719
1703
  i18n_default.on("languageChanged", handleLanguageChange);
1720
1704
  return () => {
1721
1705
  i18n_default.off("languageChanged", handleLanguageChange);
1722
1706
  };
1723
1707
  }, [i18n_default]);
1724
- return loacaleCode;
1708
+ return localeCode;
1709
+ }
1710
+ var LocaleProvider = (props) => {
1711
+ const { children, locale, resource, resources: resources2, ...languageProviderProps } = props;
1712
+ const localeCodeFromI18n = useLocaleCode();
1713
+ useEffect(() => {
1714
+ if (resources2) {
1715
+ registerResources(resources2, locale ?? localeCodeFromI18n);
1716
+ return;
1717
+ }
1718
+ if (resource && locale) {
1719
+ i18n_default.addResourceBundle(locale, defaultNS, resource, true, true);
1720
+ }
1721
+ }, [locale, localeCodeFromI18n, resource, resources2]);
1722
+ useEffect(() => {
1723
+ if (locale && locale !== i18n_default.language) {
1724
+ i18n_default.changeLanguage(locale);
1725
+ }
1726
+ }, [locale]);
1727
+ return /* @__PURE__ */ jsx(LanguageProvider, { ...languageProviderProps, children: /* @__PURE__ */ jsx(I18nextProvider, { i18n: i18n_default, defaultNS, children }) });
1728
+ };
1729
+ function useRegisterExternalResources(resources2) {
1730
+ const localeCode = useLocaleCode();
1731
+ useEffect(() => {
1732
+ registerResources(resources2, localeCode);
1733
+ }, [localeCode, resources2]);
1734
+ }
1735
+ var ExternalLocaleProvider = (props) => {
1736
+ useRegisterExternalResources(props.resources);
1737
+ return /* @__PURE__ */ jsx(Fragment, { children: props.children });
1738
+ };
1739
+ function useTranslation(ns, options) {
1740
+ const context = useContext(I18nContext);
1741
+ return useTranslation$1(ns, {
1742
+ i18n: context?.i18n || i18n_default,
1743
+ // @ts-ignore
1744
+ // when the language resource is loaded, notify the translation component to re-render
1745
+ bindI18nStore: "added",
1746
+ ...options
1747
+ });
1725
1748
  }
1726
1749
 
1727
- export { I18nProvider, LocaleContext, LocaleEnum, LocaleProvider, defaultLanguages, defaultLng, defaultNS, en, generatePath, getLocalePathFromPathname, i18n_default as i18n, i18nCookieKey, i18nLocalStorageKey, parseI18nLang, removeLangPrefix, useLocaleCode, useLocaleContext, useTranslation };
1750
+ export { Backend, ExternalLocaleProvider, LanguageContext, LanguageProvider, LocaleEnum, LocaleProvider, asMessageRecord, createI18nInstance, defaultLanguages, defaultLng, defaultNS, en, generatePath, getLocalePathFromPathname, i18n_default as i18n, i18nCookieKey, i18nLocalStorageKey, importLocaleJsonModule, parseI18nLang, registerDefaultResource, registerResources, removeLangPrefix, useLanguageContext, useLocaleCode, useRegisterExternalResources, useTranslation };
1728
1751
  //# sourceMappingURL=index.mjs.map
1729
1752
  //# sourceMappingURL=index.mjs.map