@levo-so/site-runtime 0.3.8 → 0.3.9

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.
package/index.d.ts CHANGED
@@ -5,6 +5,15 @@ import { ILevoMembership } from '@levo-so/core';
5
5
  import { JSX } from 'react/jsx-runtime';
6
6
  import { LevoQuery } from '@levo-so/core';
7
7
 
8
+ /**
9
+ * Build the canonical + hreflang link set for one page.
10
+ *
11
+ * The canonical is ALWAYS self-referential — a page canonicals to its own URL, never to a
12
+ * different variant. That single rule is what stops the variants fragmenting into
13
+ * duplicate content, which is the problem the whole design exists to avoid.
14
+ */
15
+ export declare const buildHreflangLinks: (options: IBuildHreflangOptions) => IHreflangLink[];
16
+
8
17
  /** Color-mode preference. `system` follows the OS `prefers-color-scheme`. */
9
18
  export declare type ColorMode = "dark" | "light" | "system";
10
19
 
@@ -69,6 +78,23 @@ export declare const createLevoLoader: (site: ISiteJson) => (sources: ILevoDataS
69
78
  params?: Record<string, string>;
70
79
  }) => Promise<Record<string, unknown>>;
71
80
 
81
+ /**
82
+ * Build a route-existence matcher from a generated `routeTree`.
83
+ *
84
+ * LAZY on purpose — the walk runs on the first lookup, not here — and the reason is import
85
+ * order, not router construction. `__root.tsx` is imported BY `routeTree.gen.ts`, so anything
86
+ * it evaluates at module scope runs while the tree is still half-built: walk it there and the
87
+ * list comes back short or empty. Deferring to the first lookup (inside a request middleware
88
+ * or a `beforeLoad`, both of which run long after every module has evaluated) sidesteps that
89
+ * entirely.
90
+ *
91
+ * Two bugs of this exact shape have already shipped, and both presented identically: the server
92
+ * render was correct, the client fell back to the default language, and the visitor watched the
93
+ * page flip a second after load. Before making this eager, confirm where the starter calls it
94
+ * from — at module scope in `__root.tsx`, eager is wrong.
95
+ */
96
+ export declare const createRouteTreeMatcher: (routeTree: unknown) => ((pathname: string) => boolean);
97
+
72
98
  /**
73
99
  * Build the site's core Levo client from config, or `null` when the site isn't wired to a
74
100
  * backend yet (no `apiUrl`). SSR-safe — `createLevoClient` guards its window/document reads.
@@ -93,6 +119,15 @@ export declare const createSiteClient: (config?: ILevoSiteConfig) => ILevoClient
93
119
  */
94
120
  export declare const decideAccess: ({ rules, invalid, pageId, hasClient, isReady, isLoggedIn, check, }: IAccessDecisionInput) => IAccessDecision;
95
121
 
122
+ /**
123
+ * Main entry: extract visitor country + language preferences.
124
+ * Accepts any header carrier — normalization is internal.
125
+ */
126
+ export declare const extractGeoAndLanguageData: (headers: Record<string, string | string[]> | Headers | null | undefined) => {
127
+ bestCountry: ICountryInfo | null;
128
+ languageData: IParsedLanguageData;
129
+ };
130
+
96
131
  /**
97
132
  * The gate's policy, as a pure function.
98
133
  *
@@ -138,6 +173,26 @@ export declare interface IAccessDecisionInput {
138
173
  };
139
174
  }
140
175
 
176
+ /**
177
+ * Everything needed to annotate ONE page. Describes that page across all languages, so the path
178
+ * is the language-neutral one and the locale list is the site's, not the page's.
179
+ */
180
+ export declare interface IBuildHreflangOptions {
181
+ /** Neutral path, no locale prefix — `/pricing`. */
182
+ neutralPath: string;
183
+ /** Site origin, e.g. `https://acme.com`. hreflang requires absolute URLs. */
184
+ origin: string;
185
+ locales: string[];
186
+ /**
187
+ * The locale prefix currently in the URL, or null on a neutral URL. Decides which URL is
188
+ * canonical: a prefixed visitor self-canonicals to their prefixed URL, a neutral visitor
189
+ * self-canonicals to the neutral one.
190
+ */
191
+ activePrefix?: string | null;
192
+ /** Route-existence check — a locale with no route file for this page gets no alternate. */
193
+ hasRoute?: (pathname: string) => boolean;
194
+ }
195
+
141
196
  export declare interface IColorModeProviderProps {
142
197
  children: React.ReactNode;
143
198
  /** Fallback when nothing is stored yet. */
@@ -165,6 +220,33 @@ export declare interface IComposedHead {
165
220
  scripts: IHeadEntry[];
166
221
  }
167
222
 
223
+ /**
224
+ * GeoIP header extractor.
225
+ *
226
+ * Pulls visitor country + language from HTTP headers across CDN providers
227
+ * (Cloudflare, Vercel, AWS CloudFront, Azure, BunnyCDN), nginx-ingress, and
228
+ * Traefik GeoIP2. Only surfaces `bestCountry` + `languageData` — the helpers
229
+ * that were historically exported (client IPs, provider-specific getters,
230
+ * raw header maps) are no longer used by any consumer.
231
+ *
232
+ * DELIBERATE DUPLICATE of `external/next-middleware/src/geoIp.ts`. The two must not be
233
+ * merged: next-middleware is a Next.js package serving V2 slate apps, and having a V2 app
234
+ * depend on the V3 site runtime (or vice versa) would couple two release trains that ship
235
+ * independently. The file has no framework imports, so copying is cheap — but a header
236
+ * added to ONE copy is a silent gap in the other. Change both.
237
+ *
238
+ * On v3 the live providers are nginx-ingress (`x-country-code`) and, on paper, Traefik
239
+ * (`x-geoip2-country`); our ingress sets both. See docs/studio-v3/site-localization.md.
240
+ */
241
+ export declare interface ICountryInfo {
242
+ countryCode: string;
243
+ city?: string;
244
+ region?: string;
245
+ latitude?: string;
246
+ longitude?: string;
247
+ source: string;
248
+ }
249
+
168
250
  /** Editor → preview (received by `onMessage`; dashboard's `IOutboundMessage`). */
169
251
  export declare type IEditorToPreview = {
170
252
  type: "set-inspect";
@@ -251,6 +333,48 @@ declare interface IHeadEntry {
251
333
 
252
334
  export declare type IHistoryFn = History["pushState"];
253
335
 
336
+ /**
337
+ * hreflang + canonical link generation for a localized site.
338
+ *
339
+ * These are the `<head>` annotations that tell Google which URL serves which language.
340
+ * They need NO database: the site knows its locale list (`site.json`) and which variants
341
+ * exist (the route tree), so correct annotations ship from day one — ahead of the sibling-row
342
+ * DB sync that the SITEMAP hreflang depends on.
343
+ *
344
+ * Known gap until that sync lands: these tags declare the relationships, but nothing points
345
+ * a crawler AT the prefixed URLs, so variants won't be indexed yet. See
346
+ * docs/studio-v3/site-localization.md.
347
+ */
348
+ /** One `<link>` to render into `<head>` — either this page's canonical or one language alternate. */
349
+ export declare interface IHreflangLink {
350
+ rel: "alternate" | "canonical";
351
+ href: string;
352
+ hrefLang?: string;
353
+ }
354
+
355
+ export declare interface ILanguageInfo {
356
+ locale: string;
357
+ language: string;
358
+ region?: string;
359
+ quality: number;
360
+ }
361
+
362
+ /** One selectable language, with the props a switcher needs to render it correctly. */
363
+ export declare interface ILanguageOption {
364
+ /** The locale tag, e.g. `fr-FR`. Label it however you like. */
365
+ locale: string;
366
+ isActive: boolean;
367
+ /**
368
+ * Spread onto an `<a>`. Contains the canonical `href`, the click interception, and
369
+ * `aria-current` — see `useLanguageOptions` for why each matters.
370
+ */
371
+ linkProps: {
372
+ href: string;
373
+ "aria-current": "true" | undefined;
374
+ onClick: (event: React.MouseEvent<HTMLAnchorElement>) => void;
375
+ };
376
+ }
377
+
254
378
  export declare interface ILayersNode {
255
379
  tag: string;
256
380
  source?: string;
@@ -785,6 +909,142 @@ export declare interface ILevoSourceResult<T = Record<string, unknown>> {
785
909
  };
786
910
  }
787
911
 
912
+ export declare interface ILocaleConfig {
913
+ /** Every locale the site publishes. Empty or single-entry on a non-localized site. */
914
+ locales: string[];
915
+ /** The locale served at unprefixed URLs. */
916
+ defaultLocale: string;
917
+ /**
918
+ * Whether this site does localization at all. Every site is single-locale until a workspace
919
+ * adds a second one, and the whole mechanism is inert while this is false.
920
+ */
921
+ isLocalized: boolean;
922
+ /**
923
+ * Absolute origin for hreflang, or null when the site has no domain stamped yet. hreflang
924
+ * requires absolute URLs, so an unstamped `site.json` means no tags rather than broken ones.
925
+ */
926
+ origin: string | null;
927
+ }
928
+
929
+ export declare type ILocaleDecision = ILocaleRender | ILocaleRedirect;
930
+
931
+ /** Mount once in `<head>`; the current page comes from router state, not from props. */
932
+ export declare interface ILocaleHreflangProps {
933
+ config: ILocaleConfig;
934
+ /**
935
+ * The generated route tree. Supplying it drops alternates for variants that have no route
936
+ * file, so an advertised URL never 404s. Omit and every locale is advertised.
937
+ */
938
+ routeTree?: unknown;
939
+ }
940
+
941
+ /**
942
+ * What the provider needs to expose a language to page code. Everything except `locale` is
943
+ * site-wide config; prefer `<SiteLocaleProvider>`, which derives all of it from `ILocaleConfig`.
944
+ */
945
+ export declare interface ILocaleProviderProps {
946
+ children: React.ReactNode;
947
+ /** The locale being rendered, from the server's resolution. */
948
+ locale: string;
949
+ /** Every locale the site publishes. */
950
+ locales?: string[];
951
+ /** Locale served at unprefixed URLs. */
952
+ defaultLocale?: string;
953
+ /** How `locale` was chosen — `"prefix"` means the visitor is on a canonical URL. */
954
+ source?: LocaleSource;
955
+ /**
956
+ * Does a route file exist at this path? Supplying it stops the switcher offering a language
957
+ * this page was never translated into — see `useLanguageOptions`.
958
+ */
959
+ hasRoute?: (pathname: string) => boolean;
960
+ }
961
+
962
+ /** Send the visitor to their language's URL. */
963
+ export declare interface ILocaleRedirect {
964
+ kind: "redirect";
965
+ locale: string;
966
+ source: LocaleSource;
967
+ /** Path only — `localeRedirectResponse` appends the request's own `search`/`hash`. */
968
+ path: string;
969
+ status: 302;
970
+ /**
971
+ * Every header the redirect must carry: `location`, the load-bearing `cache-control`, and
972
+ * `set-cookie` when the choice is worth remembering. Send them as-is; nothing is missing.
973
+ */
974
+ headers: Record<string, string>;
975
+ }
976
+
977
+ /** Serve the URL the visitor asked for. */
978
+ export declare interface ILocaleRender {
979
+ kind: "render";
980
+ locale: string;
981
+ source: LocaleSource;
982
+ }
983
+
984
+ export declare interface ILocaleRequestOptions {
985
+ /** The pathname the visitor asked for, e.g. `/pricing` or `/fr-FR/pricing`. */
986
+ pathname: string;
987
+ /** Every locale the site publishes, from `site.json`. */
988
+ locales: string[];
989
+ /** The locale served at unprefixed URLs. */
990
+ defaultLocale: string;
991
+ /**
992
+ * Request headers. Server path only — an in-app navigation never reaches the server, so the
993
+ * client path has none and negotiates from the cookie alone.
994
+ */
995
+ headers?: Record<string, string | string[]> | Headers | null;
996
+ /**
997
+ * A raw cookie string. Omit on the server, where it is read out of `headers`; pass
998
+ * `document.cookie` on the client, which has no headers to read it from.
999
+ */
1000
+ cookie?: string | null;
1001
+ /**
1002
+ * Does a route file exist at this path? Without it a visitor can be sent to a translation
1003
+ * nobody wrote. Build it with `createRouteTreeMatcher(routeTree)`.
1004
+ */
1005
+ hasRoute?: (pathname: string) => boolean;
1006
+ }
1007
+
1008
+ /**
1009
+ * What `useLocale()` returns: the language being rendered, the site's full list, and the one
1010
+ * mutation page code may perform. Read-only apart from `setLocale` — the URL, not this object,
1011
+ * is what decides the language.
1012
+ */
1013
+ export declare interface ILocaleState {
1014
+ locale: string;
1015
+ locales: string[];
1016
+ defaultLocale: string;
1017
+ source: LocaleSource;
1018
+ /** True once the site publishes more than one locale — gate switcher UI on this. */
1019
+ isMultiLocale: boolean;
1020
+ /**
1021
+ * Switch language: remember the choice and go to that language's URL for this page.
1022
+ *
1023
+ * It NAVIGATES rather than swapping content in place, because with the redirect model a
1024
+ * language IS a URL — `/hi-IN/pricing` is the Hindi page and the only place it exists. That
1025
+ * also means the result is shareable and cacheable, which staying on a neutral URL could
1026
+ * not give you.
1027
+ */
1028
+ setLocale: (locale: string) => void;
1029
+ /**
1030
+ * Route-existence check for this site, when the provider was given one. Consumed by
1031
+ * `useLanguageOptions`; page code should not need it.
1032
+ */
1033
+ hasRoute?: (pathname: string) => boolean;
1034
+ /**
1035
+ * Prefix a path with a locale. For the LANGUAGE SWITCHER only — the one place a visitor is
1036
+ * explicitly choosing a variant.
1037
+ *
1038
+ * Do NOT use it in shared chrome (navbar, footer, logo). Those render on every variant, and
1039
+ * building their links from the current page's language traps a visitor in the wrong one:
1040
+ * someone who landed on `/en` because no Hindi home exists then gets `/en/...` links
1041
+ * everywhere, and never finds their way back to `/hi/about` even though it exists. Shared
1042
+ * components link to the NEUTRAL path and let the doorway route them — it knows the cookie
1043
+ * and which translations exist, and a component knows neither.
1044
+ */
1045
+ pathFor: (path: string, locale: string) => string;
1046
+ }
1047
+
788
1048
  export declare function Inspector(): null;
789
1049
 
790
1050
  /** One page's head metadata. Every field optional — site defaults fill gaps per-field. */
@@ -848,6 +1108,12 @@ export declare interface IParsedAccess {
848
1108
  invalid: boolean;
849
1109
  }
850
1110
 
1111
+ export declare interface IParsedLanguageData {
1112
+ languages: ILanguageInfo[];
1113
+ primaryLanguage: string;
1114
+ inferredRegions: string[];
1115
+ }
1116
+
851
1117
  export declare interface IPatchedHistoryFn {
852
1118
  (this: History, ...args: Parameters<IHistoryFn>): ReturnType<IHistoryFn>;
853
1119
  __inspectorPatched?: boolean;
@@ -1001,6 +1267,63 @@ export declare interface IRegionElement {
1001
1267
  text?: string;
1002
1268
  }
1003
1269
 
1270
+ export declare interface IResolvedLocale {
1271
+ /** The locale to render, always a member of `locales` (or the default). */
1272
+ locale: string;
1273
+ source: LocaleSource;
1274
+ /**
1275
+ * The locale prefix stripped off the incoming pathname, if any — `/fr-FR/pricing` →
1276
+ * `fr-FR`. Null on a neutral URL. This is what tells the caller the visitor is on a
1277
+ * canonical URL rather than a negotiated one.
1278
+ */
1279
+ prefix: string | null;
1280
+ /** The pathname with any locale prefix removed — `/fr-FR/pricing` → `/pricing`. */
1281
+ neutralPath: string;
1282
+ }
1283
+
1284
+ export declare interface IResolveLocaleOptions {
1285
+ /** Full locale list from `site.json` (`workspace.locales`). */
1286
+ locales?: string[];
1287
+ /** Locale served at unprefixed URLs (`workspace.default_locale`). */
1288
+ defaultLocale?: string;
1289
+ /** The request pathname, e.g. `/fr-FR/pricing`. */
1290
+ pathname: string;
1291
+ /** Request headers. Server-side only; omit on the client. */
1292
+ headers?: Record<string, string | string[]> | Headers | null;
1293
+ /** Value of the `levo_locale` cookie, if the visitor has one. */
1294
+ cookieLocale?: string | null;
1295
+ /**
1296
+ * Skip cookie/header/geo negotiation and pin to the default. Set for crawlers, so a
1297
+ * neutral URL genuinely IS its canonical language from Google's point of view.
1298
+ */
1299
+ forceDefault?: boolean;
1300
+ }
1301
+
1302
+ export declare interface IResolveLocaleRedirectOptions {
1303
+ /** The locale the visitor should see, from `resolveLocale`. */
1304
+ locale: string;
1305
+ /** Locale served at unprefixed URLs. */
1306
+ defaultLocale: string;
1307
+ /** The locale prefix already present in the URL, or null on a neutral URL. */
1308
+ prefix: string | null;
1309
+ /** The request path with any locale prefix removed. */
1310
+ neutralPath: string;
1311
+ /** Every locale the site publishes. */
1312
+ locales: string[];
1313
+ /**
1314
+ * Does a route file exist at this path? Prevents redirecting to a translation that was
1315
+ * never written: `/hi-IN/careers` absent means the visitor stays on `/careers` and reads
1316
+ * the default language, rather than being bounced to a 404.
1317
+ */
1318
+ hasRoute?: (pathname: string) => boolean;
1319
+ /**
1320
+ * The pathname exactly as the visitor asked for it. Only used to detect a prefix whose
1321
+ * spelling differs from the site's own, e.g. `/EN/pricing` for a site publishing `en`.
1322
+ * Omit and that correction is skipped.
1323
+ */
1324
+ currentPath?: string;
1325
+ }
1326
+
1004
1327
  /** The element-selected payload — see `selectedPayload`. */
1005
1328
  export declare interface ISelectedElement {
1006
1329
  tag: string;
@@ -1080,6 +1403,22 @@ export declare interface ISiteJson {
1080
1403
  insights_url?: string | null;
1081
1404
  app_mode?: string;
1082
1405
  };
1406
+ /**
1407
+ * Every locale the site publishes, as dash-form full locales (`en-GB`, `fr-FR`, `ar-AE`)
1408
+ * to match how `page.language` stores them. Projected from `workspace.locales` — locales
1409
+ * are a WORKSPACE-level setting, so every site in a workspace shares this list.
1410
+ *
1411
+ * Absent or length <= 1 → localization is entirely inert: no rewrite, no hreflang, no
1412
+ * cookie. That is every site today, which is what lets the mechanism ship before the
1413
+ * builder learns to generate `/fr-FR/*` routes.
1414
+ */
1415
+ locales?: string[];
1416
+ /**
1417
+ * The locale served at UNPREFIXED URLs. `/pricing` is this locale's canonical home, and
1418
+ * it deliberately has no `/en-GB/pricing` twin — a prefixed default would be a duplicate
1419
+ * needing its own canonical. Projected from `workspace.default_locale`.
1420
+ */
1421
+ default_locale?: string;
1083
1422
  }
1084
1423
 
1085
1424
  /** Site-wide defaults + site-wide raw head, from `src/pages/_site.meta.ts`. */
@@ -1307,6 +1646,62 @@ export declare const LevoSiteProvider: React.FC<{
1307
1646
  children: React.ReactNode;
1308
1647
  }>;
1309
1648
 
1649
+ /** Cookie the resolved locale is persisted under. Readable by JS — the switcher writes it. */
1650
+ export declare const LOCALE_COOKIE = "levo_locale";
1651
+
1652
+ /** Cache-Control for the doorway redirect. Never let a shared cache store this — see above. */
1653
+ export declare const LOCALE_REDIRECT_CACHE_CONTROL = "private, no-store";
1654
+
1655
+ /**
1656
+ * Build the `beforeLoad` guard for a site's root route.
1657
+ *
1658
+ * `routeTree` is passed here rather than carried on the config because `__root.tsx` is imported
1659
+ * by the generated tree; the matcher it produces reads the tree lazily, on the first navigation,
1660
+ * which is what keeps that circular import safe.
1661
+ */
1662
+ export declare const localeBeforeLoad: (config: ILocaleConfig, routeTree: unknown) => ({ location }: {
1663
+ location: {
1664
+ pathname: string;
1665
+ searchStr?: string;
1666
+ };
1667
+ }) => void;
1668
+
1669
+ export declare const LocaleHreflang: React.FC<ILocaleHreflangProps>;
1670
+
1671
+ /**
1672
+ * The URL a page has in a given variant.
1673
+ *
1674
+ * On a multi-variant site EVERY variant is prefixed — including the site's default. That is
1675
+ * what makes each page cacheable: `/en/pricing` is always English and `/fr-FR/pricing` is
1676
+ * always French, so a plain URL-keyed cache is correct with no configuration. The unprefixed
1677
+ * `/pricing` is not a page at all under this model; it is the doorway that redirects.
1678
+ *
1679
+ * A single-variant site gets no prefixes — `/en/` on every URL of a site that only speaks
1680
+ * English is noise, and there is nothing to disambiguate.
1681
+ *
1682
+ * The default locale takes a prefix like every other, so this needs no knowledge of which one
1683
+ * it is. (It did while the default was unprefixed; that inverted on 2026-08-18.)
1684
+ */
1685
+ export declare const localePath: (path: string, locale: string, locales: string[]) => string;
1686
+
1687
+ export declare const LocaleProvider: React.FC<ILocaleProviderProps>;
1688
+
1689
+ /**
1690
+ * Build the HTTP response for a redirect decision.
1691
+ *
1692
+ * Exists so the server path cannot assemble it wrongly: status and headers come straight off the
1693
+ * decision, and `302` (never `301`) is fixed here — the target depends on who is asking, so a
1694
+ * browser must never remember it as permanent.
1695
+ */
1696
+ export declare const localeRedirectResponse: (decision: ILocaleRedirect, search?: string, hash?: string) => Response;
1697
+
1698
+ /**
1699
+ * How a locale was chosen. Surfaced so callers can act on provenance rather than re-deriving
1700
+ * it: `prefix` means the visitor is on a canonical locale URL (don't redirect, don't restamp
1701
+ * the cookie), and `default` on a multi-locale site means nothing matched.
1702
+ */
1703
+ export declare type LocaleSource = "prefix" | "cookie" | "header" | "geo" | "default";
1704
+
1310
1705
  /**
1311
1706
  * To E.164: strip every separator, keep one leading `+`. `"+91 98765 43210"` and
1312
1707
  * `"0091-98765-43210"` both normalize to `"+919876543210"` — the format the OTP endpoint
@@ -1387,6 +1782,9 @@ export declare const prefetchLevoSources: ({ queryClient, config, sources, param
1387
1782
  params?: Record<string, string>;
1388
1783
  }) => Promise<Record<string, unknown>>;
1389
1784
 
1785
+ /** Read the locale config out of a site's `site.json`. */
1786
+ export declare const readLocaleConfig: (site: ISiteJson) => ILocaleConfig;
1787
+
1390
1788
  /**
1391
1789
  * The id the currently matched route stamped into the head, or null when the site's
1392
1790
  * platform hasn't stamped ids into its meta files yet (the field ships empty). Client-only —
@@ -1407,6 +1805,41 @@ export declare const resolveAuthMethods: (rules: ILevoAccessConfig) => ILevoAuth
1407
1805
  /** What `system` resolves to — the class actually on `<html>`. */
1408
1806
  export declare type ResolvedColorMode = "dark" | "light";
1409
1807
 
1808
+ /**
1809
+ * Resolve which locale to serve.
1810
+ *
1811
+ * Precedence: explicit URL prefix → cookie → `Accept-Language` → GeoIP country → default.
1812
+ *
1813
+ * The prefix wins over the cookie deliberately: a `/fr-FR/pricing` link shared with someone
1814
+ * whose cookie says `de-DE` must render French, or shared links stop meaning anything.
1815
+ *
1816
+ * GeoIP sits BELOW `Accept-Language` because country is a weaker signal for language than
1817
+ * the visitor's own stated browser preference — someone in Belgium may want either Dutch or
1818
+ * French, and their browser already answered that.
1819
+ */
1820
+ export declare const resolveLocale: (options: IResolveLocaleOptions) => IResolvedLocale;
1821
+
1822
+ /**
1823
+ * The path to redirect a visitor to, or `null` to serve the current URL as-is.
1824
+ *
1825
+ * Returns null — meaning "no redirect" — in every one of these cases:
1826
+ * - the visitor is already on a prefixed URL (they asked for that language explicitly)
1827
+ * - the site publishes one locale or none
1828
+ * - no route file exists for this page in the visitor's language
1829
+ */
1830
+ export declare const resolveLocaleRedirect: (options: IResolveLocaleRedirectOptions) => string | null;
1831
+
1832
+ /**
1833
+ * Decide what to do with one request to a possibly-unprefixed URL.
1834
+ *
1835
+ * Bot detection is derived here rather than asked of the caller. Crawlers must always see the
1836
+ * default language at a neutral URL — it is what makes that URL genuinely *be* its canonical
1837
+ * language — and that is a property of the design, not a decision each doorway should be making
1838
+ * for itself. `resolveLocale`'s `forceDefault` stays available for anything that needs to pin it
1839
+ * directly.
1840
+ */
1841
+ export declare const resolveLocaleRequest: (options: ILocaleRequestOptions) => ILocaleDecision;
1842
+
1410
1843
  /**
1411
1844
  * The site's Levo client config from its `site.json` — the only place that mapping lives, so
1412
1845
  * the provider and the SSR route loader can't drift apart.
@@ -1416,9 +1849,65 @@ export declare type ResolvedColorMode = "dark" | "light";
1416
1849
  */
1417
1850
  export declare const siteConfigFromJson: (site: ISiteJson) => ILevoSiteConfig;
1418
1851
 
1852
+ /**
1853
+ * Mount the locale context from a site's config.
1854
+ *
1855
+ * Prefer this over `<LocaleProvider>` in a generated site: it derives the active language from
1856
+ * the URL itself, so there is no second copy of that derivation to fall out of step with the
1857
+ * `<html lang>` or the hreflang tags.
1858
+ */
1859
+ export declare const SiteLocaleProvider: React.FC<{
1860
+ config: ILocaleConfig;
1861
+ children: React.ReactNode;
1862
+ /**
1863
+ * The generated route tree. Supplying it lets the switcher hide languages this page has no
1864
+ * translation into — the difference between offering a link and offering a 404.
1865
+ */
1866
+ routeTree?: unknown;
1867
+ }>;
1868
+
1869
+ /**
1870
+ * Split a locale prefix off a pathname. Only strips a segment that is a KNOWN locale, so a
1871
+ * site with a page genuinely named `/fr-FR` (or any other collision) is unaffected — the
1872
+ * segment has to be in the site's own locale list to count.
1873
+ */
1874
+ export declare const splitLocalePrefix: (pathname: string, locales: string[]) => {
1875
+ prefix: string | null;
1876
+ neutralPath: string;
1877
+ };
1878
+
1419
1879
  /** Read/set the current color mode. Throws outside a `<ColorModeProvider>`. */
1420
1880
  export declare function useColorMode(): IColorModeState;
1421
1881
 
1882
+ /**
1883
+ * The behaviour half of a language switcher, so the starter only owns the look.
1884
+ *
1885
+ * Three things here are load-bearing and were previously comments in a starter component asking
1886
+ * not to be "simplified":
1887
+ *
1888
+ * 1. `href` is a real canonical URL, so a crawler can follow it. A switcher built from buttons
1889
+ * and a click handler is invisible to search, and the site's own hreflang tags then point at
1890
+ * pages nothing links to.
1891
+ * 2. A plain left-click is intercepted into a cookie write plus a navigation, so the choice is
1892
+ * remembered. Modifier and middle clicks are deliberately NOT intercepted, so "open in new
1893
+ * tab" lands on the real URL like any other link.
1894
+ * 3. The path is stripped back to its neutral form before each variant's URL is built, or the
1895
+ * hrefs come out doubled (`/de-DE/fr-FR/pricing`).
1896
+ *
1897
+ * Render `options` however you want; drop `linkProps` onto an `<a>` and none of the above can
1898
+ * be lost.
1899
+ *
1900
+ * Languages this page has no translation into are OMITTED, when the provider was given a route
1901
+ * tree. Their URL would be a real 404: a prefixed URL is an explicit request, so the doorway
1902
+ * correctly declines to redirect it, and there is no page behind it. This is the same rule the
1903
+ * hreflang tags follow — a switcher offering what hreflang refuses to advertise is the two
1904
+ * halves disagreeing about which pages exist.
1905
+ *
1906
+ * Returns an empty list when fewer than two languages remain, so a switcher self-hides on a
1907
+ * single-locale site and on a page that only exists in one language.
1908
+ */
1909
+ export declare function useLanguageOptions(): ILanguageOption[];
1910
+
1422
1911
  export declare const useLevoAccess: (source: ILevoAccessSource) => ILevoAccessResult;
1423
1912
 
1424
1913
  export declare const useLevoAuth: () => ILevoAuthState;
@@ -1468,4 +1957,26 @@ export declare const useLevoSite: () => ILevoClient | null;
1468
1957
  */
1469
1958
  export declare const useLevoSource: <T = Record<string, unknown>>(config: ILevoSourceConfig) => ILevoSourceResult<T>;
1470
1959
 
1960
+ /**
1961
+ * Read the active locale and switch languages.
1962
+ *
1963
+ * Returns an inert single-locale state outside a `<LocaleProvider>` rather than throwing —
1964
+ * unlike `useColorMode`, which throws. A switcher is page content the AI may drop onto a
1965
+ * site whose provider was never wired, and crashing the whole page over a language picker is
1966
+ * a worse failure than rendering nothing.
1967
+ */
1968
+ export declare function useLocale(): ILocaleState;
1969
+
1970
+ /**
1971
+ * The language the current URL serves.
1972
+ *
1973
+ * Read off the URL, not negotiated: every variant is a prefixed URL under the redirect model,
1974
+ * so `/hi-IN/pricing` is Hindi and nothing else, and server and browser cannot disagree about
1975
+ * it. (When locales were applied as a rewrite they could, and did — three separate bugs where
1976
+ * the page rendered in one language and hydrated in another.)
1977
+ *
1978
+ * For `<html lang>`, which sits above the provider and so cannot use `useLocale()`.
1979
+ */
1980
+ export declare function useUrlLocale(config: ILocaleConfig): string;
1981
+
1471
1982
  export { }