gemi 0.13.7 → 0.13.8

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 (104) hide show
  1. package/dist/app/index.js +2 -2
  2. package/dist/app/index.js.map +1 -1
  3. package/dist/broadcasting/index.js +1 -1
  4. package/dist/{chunk-5q5qjyxf.js → chunk-012pty5m.js} +2 -2
  5. package/dist/{chunk-5q5qjyxf.js.map → chunk-012pty5m.js.map} +1 -1
  6. package/dist/{chunk-dak25pw2.js → chunk-27wb042h.js} +2 -2
  7. package/dist/{chunk-dak25pw2.js.map → chunk-27wb042h.js.map} +1 -1
  8. package/dist/{chunk-6fy0y9na.js → chunk-3za8zsph.js} +2 -2
  9. package/dist/{chunk-6fy0y9na.js.map → chunk-3za8zsph.js.map} +1 -1
  10. package/dist/{chunk-pvxzx61f.js → chunk-4zy0b2cq.js} +3 -3
  11. package/dist/{chunk-pvxzx61f.js.map → chunk-4zy0b2cq.js.map} +1 -1
  12. package/dist/{chunk-00q77h4a.js → chunk-5p9mcds2.js} +2 -2
  13. package/dist/{chunk-00q77h4a.js.map → chunk-5p9mcds2.js.map} +1 -1
  14. package/dist/{chunk-0mfpz0sr.js → chunk-7hhtnc5w.js} +2 -2
  15. package/dist/{chunk-0mfpz0sr.js.map → chunk-7hhtnc5w.js.map} +1 -1
  16. package/dist/{chunk-0wr6m6f4.js → chunk-8nyhavne.js} +2 -2
  17. package/dist/{chunk-0wr6m6f4.js.map → chunk-8nyhavne.js.map} +1 -1
  18. package/dist/{chunk-m2p40y0k.js → chunk-9bat8gf8.js} +2 -2
  19. package/dist/{chunk-m2p40y0k.js.map → chunk-9bat8gf8.js.map} +1 -1
  20. package/dist/chunk-a1hr4h7e.js +4 -0
  21. package/dist/{chunk-6pwjkfk5.js.map → chunk-a1hr4h7e.js.map} +1 -1
  22. package/dist/{chunk-rre72epn.js → chunk-b91cs7rz.js} +3 -3
  23. package/dist/{chunk-rre72epn.js.map → chunk-b91cs7rz.js.map} +1 -1
  24. package/dist/{chunk-qcr71k85.js → chunk-brew2st9.js} +2 -2
  25. package/dist/{chunk-qcr71k85.js.map → chunk-brew2st9.js.map} +1 -1
  26. package/dist/{chunk-0vq2p4bq.js → chunk-d0c15za6.js} +2 -2
  27. package/dist/{chunk-0vq2p4bq.js.map → chunk-d0c15za6.js.map} +1 -1
  28. package/dist/{chunk-4e18rqet.js → chunk-ee0fv5gm.js} +2 -2
  29. package/dist/{chunk-4e18rqet.js.map → chunk-ee0fv5gm.js.map} +1 -1
  30. package/dist/{chunk-jn8jhrkd.js → chunk-ejrp23v3.js} +2 -2
  31. package/dist/{chunk-jn8jhrkd.js.map → chunk-ejrp23v3.js.map} +1 -1
  32. package/dist/{chunk-3nzz6kqw.js → chunk-gjhm9wdg.js} +2 -2
  33. package/dist/{chunk-3nzz6kqw.js.map → chunk-gjhm9wdg.js.map} +1 -1
  34. package/dist/{chunk-jxftkhsd.js → chunk-j2ymcc6q.js} +2 -2
  35. package/dist/{chunk-jxftkhsd.js.map → chunk-j2ymcc6q.js.map} +1 -1
  36. package/dist/{chunk-0wa1m3yq.js → chunk-jt1cpbzj.js} +4 -4
  37. package/dist/{chunk-0wa1m3yq.js.map → chunk-jt1cpbzj.js.map} +3 -4
  38. package/dist/{chunk-svh4hjg3.js → chunk-kcpnz8df.js} +2 -2
  39. package/dist/{chunk-svh4hjg3.js.map → chunk-kcpnz8df.js.map} +1 -1
  40. package/dist/{chunk-67ytmbmn.js → chunk-m2mrqsmj.js} +3 -3
  41. package/dist/{chunk-67ytmbmn.js.map → chunk-m2mrqsmj.js.map} +1 -1
  42. package/dist/{chunk-acfdk70y.js → chunk-mpybe78g.js} +3 -3
  43. package/dist/{chunk-acfdk70y.js.map → chunk-mpybe78g.js.map} +1 -1
  44. package/dist/{chunk-tyv9h73f.js → chunk-n221batm.js} +3 -3
  45. package/dist/{chunk-tyv9h73f.js.map → chunk-n221batm.js.map} +1 -1
  46. package/dist/{chunk-nxrhps23.js → chunk-ng2p76w0.js} +2 -2
  47. package/dist/{chunk-nxrhps23.js.map → chunk-ng2p76w0.js.map} +1 -1
  48. package/dist/{chunk-wbg45cdc.js → chunk-nryqtba3.js} +2 -2
  49. package/dist/{chunk-wbg45cdc.js.map → chunk-nryqtba3.js.map} +1 -1
  50. package/dist/{chunk-wewz52mc.js → chunk-qkvwfa7s.js} +2 -2
  51. package/dist/{chunk-wewz52mc.js.map → chunk-qkvwfa7s.js.map} +1 -1
  52. package/dist/{chunk-95b1a8cw.js → chunk-t82sd6ag.js} +2 -2
  53. package/dist/{chunk-95b1a8cw.js.map → chunk-t82sd6ag.js.map} +1 -1
  54. package/dist/{chunk-yvrp97kk.js → chunk-ta13zfs4.js} +3 -3
  55. package/dist/{chunk-yvrp97kk.js.map → chunk-ta13zfs4.js.map} +1 -1
  56. package/dist/{chunk-6kfbsmxx.js → chunk-w3bpe08v.js} +2 -2
  57. package/dist/{chunk-6kfbsmxx.js.map → chunk-w3bpe08v.js.map} +1 -1
  58. package/dist/{chunk-68kvbrqd.js → chunk-wbjejbf3.js} +2 -2
  59. package/dist/{chunk-68kvbrqd.js.map → chunk-wbjejbf3.js.map} +1 -1
  60. package/dist/{chunk-jwebzy40.js → chunk-x2v7c34f.js} +2 -2
  61. package/dist/{chunk-jwebzy40.js.map → chunk-x2v7c34f.js.map} +1 -1
  62. package/dist/{chunk-cgh2sw3g.js → chunk-xr2hsrr8.js} +2 -2
  63. package/dist/{chunk-cgh2sw3g.js.map → chunk-xr2hsrr8.js.map} +1 -1
  64. package/dist/chunk-xs7ze1bn.js +4 -0
  65. package/dist/{chunk-3q85w7aa.js.map → chunk-xs7ze1bn.js.map} +1 -1
  66. package/dist/{chunk-fe1gn043.js → chunk-xttpe58q.js} +2 -2
  67. package/dist/{chunk-fe1gn043.js.map → chunk-xttpe58q.js.map} +1 -1
  68. package/dist/{chunk-tw3t6x2n.js → chunk-z2117ncx.js} +3 -3
  69. package/dist/{chunk-tw3t6x2n.js.map → chunk-z2117ncx.js.map} +1 -1
  70. package/dist/client/ClientRouter.d.ts.map +1 -1
  71. package/dist/client/ClientRouterContext.d.ts +2 -0
  72. package/dist/client/ClientRouterContext.d.ts.map +1 -1
  73. package/dist/client/I18nContext.d.ts +2 -1
  74. package/dist/client/I18nContext.d.ts.map +1 -1
  75. package/dist/client/Link.d.ts +2 -1
  76. package/dist/client/Link.d.ts.map +1 -1
  77. package/dist/client/RouteStateContext.d.ts +1 -0
  78. package/dist/client/RouteStateContext.d.ts.map +1 -1
  79. package/dist/client/ServerDataProvider.d.ts +1 -0
  80. package/dist/client/ServerDataProvider.d.ts.map +1 -1
  81. package/dist/client/index.js +165 -109
  82. package/dist/client/index.js.map +1 -1
  83. package/dist/client/useLocale.d.ts.map +1 -1
  84. package/dist/client/useLocation.d.ts +1 -0
  85. package/dist/client/useLocation.d.ts.map +1 -1
  86. package/dist/client/useNavigate.d.ts +4 -0
  87. package/dist/client/useNavigate.d.ts.map +1 -1
  88. package/dist/client/useTranslator.d.ts.map +1 -1
  89. package/dist/email/index.js +1 -1
  90. package/dist/facades/index.js +4 -4
  91. package/dist/facades/index.js.map +3 -3
  92. package/dist/http/index.js +2 -2
  93. package/dist/http/index.js.map +1 -1
  94. package/dist/i18n/index.js +1 -1
  95. package/dist/kernel/index.js +2 -2
  96. package/dist/kernel/index.js.map +1 -1
  97. package/dist/server/index.js +2 -2
  98. package/dist/server/index.js.map +1 -1
  99. package/dist/services/index.js +44 -44
  100. package/dist/services/index.js.map +2 -2
  101. package/dist/services/router/ViewRouterServiceContainer.d.ts.map +1 -1
  102. package/package.json +1 -1
  103. package/dist/chunk-3q85w7aa.js +0 -4
  104. package/dist/chunk-6pwjkfk5.js +0 -4
@@ -557,13 +557,14 @@ function useLocation() {
557
557
  if (!ctx) {
558
558
  throw new Error("Router context not found");
559
559
  }
560
- const { hash, pathname, search, state } = ctx;
560
+ const { hash, pathname, search, state, locale } = ctx;
561
561
  return {
562
562
  hash,
563
563
  key: pathname,
564
564
  pathname,
565
565
  search,
566
- state
566
+ state,
567
+ locale
567
568
  };
568
569
  }
569
570
  function _extends() {
@@ -651,7 +652,7 @@ function createBrowserHistory(options) {
651
652
  }
652
653
  window2.addEventListener(PopStateEventType, handlePop);
653
654
  var action = Action.Pop;
654
- var _getIndexAndLocation2 = getIndexAndLocation(), index = _getIndexAndLocation2[0], location2 = _getIndexAndLocation2[1];
655
+ var _getIndexAndLocation2 = getIndexAndLocation(), index = _getIndexAndLocation2[0], location = _getIndexAndLocation2[1];
655
656
  var listeners = createEvents();
656
657
  var blockers = createEvents();
657
658
  if (index == null) {
@@ -668,7 +669,7 @@ function createBrowserHistory(options) {
668
669
  state = null;
669
670
  }
670
671
  return readOnly(_extends({
671
- pathname: location2.pathname,
672
+ pathname: location.pathname,
672
673
  hash: "",
673
674
  search: ""
674
675
  }, typeof to === "string" ? parsePath(to) : to, {
@@ -683,10 +684,10 @@ function createBrowserHistory(options) {
683
684
  idx: index2
684
685
  }, createHref(nextLocation)];
685
686
  }
686
- function allowTx(action2, location3, retry) {
687
+ function allowTx(action2, location2, retry) {
687
688
  return !blockers.length || (blockers.call({
688
689
  action: action2,
689
- location: location3,
690
+ location: location2,
690
691
  retry
691
692
  }), false);
692
693
  }
@@ -694,10 +695,10 @@ function createBrowserHistory(options) {
694
695
  action = nextAction;
695
696
  var _getIndexAndLocation3 = getIndexAndLocation();
696
697
  index = _getIndexAndLocation3[0];
697
- location2 = _getIndexAndLocation3[1];
698
+ location = _getIndexAndLocation3[1];
698
699
  listeners.call({
699
700
  action,
700
- location: location2
701
+ location
701
702
  });
702
703
  }
703
704
  function push(to, state) {
@@ -736,7 +737,7 @@ function createBrowserHistory(options) {
736
737
  return action;
737
738
  },
738
739
  get location() {
739
- return location2;
740
+ return location;
740
741
  },
741
742
  createHref,
742
743
  push,
@@ -1663,6 +1664,77 @@ const HttpReload = () => {
1663
1664
  document.body
1664
1665
  );
1665
1666
  };
1667
+ const I18nContext = createContext({});
1668
+ const I18nProvider = (props) => {
1669
+ const { i18n } = useContext(ServerDataContext);
1670
+ const { fetch: fetch2, host } = useContext(HttpClientContext);
1671
+ const [currentLocale, setCurrentLocale] = useState(i18n.currentLocale);
1672
+ const dictionary = useRef(
1673
+ (() => {
1674
+ const dictionary2 = /* @__PURE__ */ new Map();
1675
+ for (const [locale, value] of Object.entries((i18n == null ? void 0 : i18n.dictionary) ?? {})) {
1676
+ const components = /* @__PURE__ */ new Map();
1677
+ for (const [component, translations] of Object.entries(value)) {
1678
+ components.set(component, translations);
1679
+ }
1680
+ dictionary2.set(locale, components);
1681
+ }
1682
+ return dictionary2;
1683
+ })()
1684
+ );
1685
+ function updateDictionary(translations = {}, locale) {
1686
+ for (const [locale2, value] of Object.entries(translations)) {
1687
+ if (!dictionary.current.has(locale2)) {
1688
+ dictionary.current.set(locale2, /* @__PURE__ */ new Map());
1689
+ }
1690
+ const scopes = dictionary.current.get(locale2);
1691
+ for (const [scope, translations2] of Object.entries(value)) {
1692
+ if (!scopes.has(scope)) {
1693
+ scopes.set(scope, {});
1694
+ }
1695
+ scopes.set(scope, translations2);
1696
+ }
1697
+ }
1698
+ changeLocale(locale);
1699
+ }
1700
+ const changeLocale = (locale) => {
1701
+ if (dictionary.current.has(locale)) {
1702
+ setCurrentLocale(locale);
1703
+ }
1704
+ };
1705
+ const getTranslations = (locale) => {
1706
+ return (component) => {
1707
+ return dictionary.current.get(locale).get(component);
1708
+ };
1709
+ };
1710
+ const fetchTranslations = async (pathname, locale, signal) => {
1711
+ if (Object.keys(i18n).length === 0) {
1712
+ return;
1713
+ }
1714
+ const response = await fetch2(
1715
+ `${host}/api/__gemi__/services/i18n/translations/${locale || currentLocale}${pathname === "/" ? "" : pathname}`,
1716
+ {
1717
+ signal
1718
+ }
1719
+ );
1720
+ const translations = await response.json();
1721
+ updateDictionary(translations);
1722
+ };
1723
+ return /* @__PURE__ */ jsx(
1724
+ I18nContext.Provider,
1725
+ {
1726
+ value: {
1727
+ getComponentTranslations: getTranslations(currentLocale),
1728
+ locale: currentLocale,
1729
+ changeLocale,
1730
+ updateDictionary,
1731
+ fetchTranslations,
1732
+ supportedLocales: i18n.supportedLocales
1733
+ },
1734
+ children: props.children
1735
+ }
1736
+ );
1737
+ };
1666
1738
  const ClientRouterContext = createContext(
1667
1739
  {}
1668
1740
  );
@@ -1677,12 +1749,14 @@ const ClientRouterProvider = (props) => {
1677
1749
  pageData,
1678
1750
  params,
1679
1751
  searchParams,
1680
- breadcrumbs
1752
+ breadcrumbs,
1753
+ urlLocaleSegment
1681
1754
  } = props;
1682
1755
  const navigationAbortControllerRef = useRef(new AbortController());
1683
1756
  const [isNavigatingSubject] = useState(() => {
1684
1757
  return new Subject(false);
1685
1758
  });
1759
+ const { supportedLocales, locale } = useContext(I18nContext);
1686
1760
  const { fetch: fetch2, host } = useContext(HttpClientContext);
1687
1761
  const [progressManager] = useState(new ProgressManager(isNavigatingSubject));
1688
1762
  const pageDataRef = useRef(structuredClone(pageData));
@@ -1701,7 +1775,8 @@ const ClientRouterProvider = (props) => {
1701
1775
  pathname,
1702
1776
  hash: "",
1703
1777
  action: null,
1704
- routePath: currentPath
1778
+ routePath: currentPath,
1779
+ locale
1705
1780
  });
1706
1781
  });
1707
1782
  const [history] = useState(() => {
@@ -1713,10 +1788,12 @@ const ClientRouterProvider = (props) => {
1713
1788
  });
1714
1789
  const findMatchingRouteFromParams = useMemo(
1715
1790
  () => (pathname2) => {
1791
+ let routePath = pathname2.replace("/en-US", "").replace("/tr-TR", "");
1792
+ routePath = routePath === "" ? "/" : routePath;
1716
1793
  const candidates = [];
1717
1794
  for (const route of Object.keys(routeManifest)) {
1718
1795
  const urlPattern = new me({ pathname: route });
1719
- if (urlPattern.test({ pathname: pathname2 })) {
1796
+ if (urlPattern.test({ pathname: routePath })) {
1720
1797
  candidates.push(route);
1721
1798
  }
1722
1799
  }
@@ -1753,26 +1830,38 @@ const ClientRouterProvider = (props) => {
1753
1830
  [findMatchingRouteFromParams]
1754
1831
  );
1755
1832
  useEffect(() => {
1756
- history == null ? void 0 : history.listen(({ location: location2, action }) => {
1833
+ history == null ? void 0 : history.listen(({ location, action }) => {
1757
1834
  if (!window.scrollHistory) {
1758
1835
  window.scrollHistory = /* @__PURE__ */ new Map();
1759
1836
  }
1760
1837
  const { hash, pathname: pathname2, search } = routerSubject.getValue();
1761
- const key = [pathname2, hash, search].join("");
1838
+ const key = [pathname2, search, hash].join("");
1762
1839
  window.scrollHistory.set(key, window.scrollY);
1763
- const routePath = getRoutePathnameFromHref(location2.pathname);
1840
+ let _pathname = location.pathname;
1841
+ let _locale = null;
1842
+ for (const locale2 of supportedLocales) {
1843
+ if (_pathname.startsWith(`/${locale2}`)) {
1844
+ _locale = locale2;
1845
+ _pathname = _pathname.replace(`/${locale2}`, "");
1846
+ break;
1847
+ }
1848
+ }
1849
+ _pathname = _pathname === "" ? "/" : _pathname;
1850
+ const routePath = getRoutePathnameFromHref(_pathname);
1764
1851
  routerSubject.next({
1765
- views: getViewPathsFromPathname(location2.pathname),
1766
- params: getParams(location2.pathname),
1767
- search: location2.search,
1768
- state: location2.state,
1769
- pathname: location2.pathname,
1852
+ views: getViewPathsFromPathname(_pathname),
1853
+ params: getParams(_pathname),
1854
+ search: location.search,
1855
+ state: location.state,
1856
+ pathname: _pathname,
1770
1857
  action,
1771
1858
  routePath,
1772
- hash: location2.hash
1859
+ hash: location.hash,
1860
+ locale: _locale
1773
1861
  });
1774
1862
  });
1775
1863
  }, [
1864
+ supportedLocales,
1776
1865
  history,
1777
1866
  routerSubject,
1778
1867
  getParams,
@@ -1843,7 +1932,8 @@ const ClientRouterProvider = (props) => {
1843
1932
  progressManager,
1844
1933
  fetchRouteCSS,
1845
1934
  breadcrumbsCache: breadcrumbsCache.current,
1846
- routerSubject
1935
+ routerSubject,
1936
+ urlLocaleSegment
1847
1937
  },
1848
1938
  children: [
1849
1939
  children,
@@ -1854,6 +1944,7 @@ const ClientRouterProvider = (props) => {
1854
1944
  };
1855
1945
  function useNavigate() {
1856
1946
  const { history, setNavigationAbortController } = useContext(ClientRouterContext);
1947
+ const location = useLocation();
1857
1948
  function action(pushOrReplace) {
1858
1949
  return async (path, ...args) => {
1859
1950
  const navigationAbortController = new AbortController();
@@ -1862,22 +1953,32 @@ function useNavigate() {
1862
1953
  const {
1863
1954
  search = {},
1864
1955
  params = {},
1865
- shallow
1956
+ shallow,
1957
+ locale,
1958
+ hash
1866
1959
  } = {
1867
1960
  params: {},
1868
1961
  shallow: false,
1962
+ locale: null,
1963
+ hash: "",
1869
1964
  ...options
1870
1965
  };
1871
1966
  const urlSearchParams = new URLSearchParams(search);
1967
+ let localeSegment = location.locale;
1968
+ if (locale) {
1969
+ localeSegment = locale;
1970
+ }
1971
+ const routePath = applyParams$1(path, params);
1872
1972
  const navigationPath = [
1873
- applyParams$1(path, params),
1973
+ `${localeSegment ? `/${localeSegment}` : ""}${routePath}`,
1874
1974
  urlSearchParams.toString()
1875
- ].join("?");
1975
+ ].filter((s) => s.length > 0).join("?");
1976
+ const finalPath = [navigationPath, hash].filter(Boolean).join("");
1876
1977
  if (shallow) {
1877
- history == null ? void 0 : history[pushOrReplace](navigationPath);
1978
+ history == null ? void 0 : history[pushOrReplace](finalPath, { shallow });
1878
1979
  return;
1879
1980
  }
1880
- history == null ? void 0 : history[pushOrReplace](navigationPath);
1981
+ history == null ? void 0 : history[pushOrReplace](finalPath);
1881
1982
  };
1882
1983
  }
1883
1984
  return {
@@ -1958,9 +2059,9 @@ class SearchParams {
1958
2059
  }
1959
2060
  function useSearchParams() {
1960
2061
  const { push } = useNavigate();
1961
- const { search } = useContext(RouteStateContext);
2062
+ const { search, pathname } = useContext(RouteStateContext);
1962
2063
  const callback = (search2, shallow) => {
1963
- push(location.pathname, {
2064
+ push(pathname, {
1964
2065
  search: search2,
1965
2066
  shallow
1966
2067
  });
@@ -2010,17 +2111,23 @@ const Link = (props) => {
2010
2111
  const {
2011
2112
  href,
2012
2113
  onClick,
2114
+ hash = "",
2013
2115
  active = false,
2014
2116
  params = {},
2015
2117
  search = {},
2016
2118
  ...rest
2017
2119
  } = { params: _params, search: {}, ...props };
2018
2120
  const { push } = useNavigate();
2019
- const location2 = useLocation();
2121
+ const location = useLocation();
2020
2122
  const searchParams = new URLSearchParams(normalizeSearch(search));
2021
2123
  const path = applyParams$1(href, params);
2022
- const targetHref = [path, searchParams.toString()].filter((s) => s.length > 0).join("?");
2023
- const currentHref = [location2.pathname, location2.search].filter((item) => !!item).join("");
2124
+ const urlLocaleSegment = location.locale;
2125
+ const localeSegment = urlLocaleSegment ? `/${urlLocaleSegment}` : "";
2126
+ const targetHref = [
2127
+ [`${localeSegment}${path}`, searchParams.toString()].filter((s) => s.length > 0).join("?"),
2128
+ hash
2129
+ ].join("");
2130
+ const currentHref = [location.pathname, location.search, location.hash].filter((item) => !!item).join("");
2024
2131
  return /* @__PURE__ */ jsx(
2025
2132
  "a",
2026
2133
  {
@@ -2034,12 +2141,18 @@ const Link = (props) => {
2034
2141
  return;
2035
2142
  }
2036
2143
  }
2037
- e.preventDefault();
2144
+ let currentPath = window.location.pathname.replace(localeSegment, "");
2145
+ currentPath = currentPath === "" ? "/" : currentPath;
2146
+ onClick == null ? void 0 : onClick(e);
2147
+ if (hash === "") {
2148
+ e.preventDefault();
2149
+ }
2038
2150
  onClick == null ? void 0 : onClick(e);
2039
2151
  push(href, {
2152
+ hash,
2040
2153
  search,
2041
2154
  params,
2042
- shallow: path === window.location.pathname
2155
+ shallow: path === currentPath
2043
2156
  });
2044
2157
  },
2045
2158
  ...rest
@@ -31508,75 +31621,6 @@ const ComponentsProvider = (props) => {
31508
31621
  }
31509
31622
  );
31510
31623
  };
31511
- const I18nContext = createContext({});
31512
- const I18nProvider = (props) => {
31513
- const { i18n } = useContext(ServerDataContext);
31514
- const { fetch: fetch2, host } = useContext(HttpClientContext);
31515
- const [currentLocale, setCurrentLocale] = useState(i18n.currentLocale);
31516
- const dictionary = useRef(
31517
- (() => {
31518
- const dictionary2 = /* @__PURE__ */ new Map();
31519
- for (const [locale, value] of Object.entries((i18n == null ? void 0 : i18n.dictionary) ?? {})) {
31520
- const components = /* @__PURE__ */ new Map();
31521
- for (const [component, translations] of Object.entries(value)) {
31522
- components.set(component, translations);
31523
- }
31524
- dictionary2.set(locale, components);
31525
- }
31526
- return dictionary2;
31527
- })()
31528
- );
31529
- function updateDictionary(translations = {}) {
31530
- for (const [locale, value] of Object.entries(translations)) {
31531
- if (!dictionary.current.has(locale)) {
31532
- dictionary.current.set(locale, /* @__PURE__ */ new Map());
31533
- }
31534
- const scopes = dictionary.current.get(locale);
31535
- for (const [scope, translations2] of Object.entries(value)) {
31536
- if (!scopes.has(scope)) {
31537
- scopes.set(scope, {});
31538
- }
31539
- scopes.set(scope, translations2);
31540
- }
31541
- }
31542
- }
31543
- const changeLocale = (locale) => {
31544
- if (dictionary.current.has(locale)) {
31545
- setCurrentLocale(locale);
31546
- }
31547
- };
31548
- const getTranslations = (locale) => {
31549
- return (component) => {
31550
- return dictionary.current.get(locale).get(component);
31551
- };
31552
- };
31553
- const fetchTranslations = async (pathname, locale, signal) => {
31554
- if (Object.keys(i18n).length === 0) {
31555
- return;
31556
- }
31557
- const response = await fetch2(
31558
- `${host}/api/__gemi__/services/i18n/translations/${locale || currentLocale}${pathname === "/" ? "" : pathname}`,
31559
- {
31560
- signal
31561
- }
31562
- );
31563
- const translations = await response.json();
31564
- updateDictionary(translations);
31565
- };
31566
- return /* @__PURE__ */ jsx(
31567
- I18nContext.Provider,
31568
- {
31569
- value: {
31570
- getComponentTranslations: getTranslations(currentLocale),
31571
- locale: currentLocale,
31572
- changeLocale,
31573
- updateDictionary,
31574
- fetchTranslations
31575
- },
31576
- children: props.children
31577
- }
31578
- );
31579
- };
31580
31624
  const WebSocketContext = createContext(
31581
31625
  {}
31582
31626
  );
@@ -31635,7 +31679,7 @@ function restoreScroll(action = null, _pathname = "no path") {
31635
31679
  return;
31636
31680
  }
31637
31681
  const { pathname, search, hash } = window.location;
31638
- const key = [pathname, hash, search].join("");
31682
+ const key = [pathname, search, hash].join("");
31639
31683
  const sh = window.scrollHistory;
31640
31684
  const scrollPosition = sh == null ? void 0 : sh.get(key);
31641
31685
  if (action !== Action.Pop) {
@@ -31718,7 +31762,8 @@ const Routes = (props) => {
31718
31762
  action: null,
31719
31763
  hash: routerSubject.getValue().hash,
31720
31764
  state: routerSubject.getValue().state,
31721
- routePath: routerSubject.getValue().routePath
31765
+ routePath: routerSubject.getValue().routePath,
31766
+ locale: routerSubject.getValue().locale
31722
31767
  });
31723
31768
  const { replace } = useNavigate();
31724
31769
  useEffect(() => {
@@ -31735,7 +31780,10 @@ const Routes = (props) => {
31735
31780
  setRouteState(routerState);
31736
31781
  return;
31737
31782
  }
31738
- const url = `${host}${pathname}.json${search}`;
31783
+ const localeSegment = routerState.locale ? `/${routerState.locale}` : "";
31784
+ const _pathname = localeSegment.length > 0 && pathname === "/" ? "" : pathname;
31785
+ const pathnameWithLocaleSegment = `${localeSegment}${_pathname}`;
31786
+ const url = `${host}${pathnameWithLocaleSegment}.json${search}`;
31739
31787
  const [res] = await Promise.all([
31740
31788
  fetch2(url),
31741
31789
  fetchRouteCSS(pathname),
@@ -31763,7 +31811,7 @@ const Routes = (props) => {
31763
31811
  }
31764
31812
  updatePageData(data, breadcrumbs);
31765
31813
  updatePrefecthedData(prefetchedData);
31766
- updateDictionary((i18n == null ? void 0 : i18n.dictionary) ?? {});
31814
+ updateDictionary((i18n == null ? void 0 : i18n.dictionary) ?? {}, (i18n == null ? void 0 : i18n.currentLocale) ?? "");
31767
31815
  if (is404) {
31768
31816
  startTransition(() => {
31769
31817
  setRouteState((state2) => ({
@@ -31820,6 +31868,7 @@ const ClientRouter = (props) => {
31820
31868
  currentPath: router.currentPath,
31821
31869
  routeManifest,
31822
31870
  breadcrumbs,
31871
+ urlLocaleSegment: router.urlLocaleSegment,
31823
31872
  children: /* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(RootLayout, { children: /* @__PURE__ */ jsx(Routes, { componentTree }) }) })
31824
31873
  }
31825
31874
  ) }) }) }) });
@@ -32103,10 +32152,17 @@ function useTranslator(component) {
32103
32152
  function useLocale() {
32104
32153
  const { changeLocale, locale, fetchTranslations } = useContext(I18nContext);
32105
32154
  const { getRoutePathnameFromHref } = useContext(ClientRouterContext);
32106
- const { pathname } = useLocation();
32155
+ const { pathname, search } = useLocation();
32156
+ const { replace } = useNavigate();
32107
32157
  const setLocale = async (locale2) => {
32108
- await fetchTranslations(getRoutePathnameFromHref(pathname), locale2);
32158
+ const urlSearchParams = new URLSearchParams(search);
32109
32159
  changeLocale(locale2);
32160
+ replace(pathname, {
32161
+ locale: locale2,
32162
+ // TODO: fix: this conversion is wrong, because there can be multiple
32163
+ // search params with the same name
32164
+ search: Object.fromEntries(urlSearchParams.entries())
32165
+ });
32110
32166
  };
32111
32167
  return [locale, setLocale];
32112
32168
  }