{"version":3,"sources":["../../src/i18n/client.tsx","../../src/base-path.ts","../../src/i18n/routing.ts","../../src/i18n/resolver.ts","../../src/i18n/client-runtime.ts","../../src/i18n/bridge.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useSyncExternalStore } from \"react\";\nimport { createFarmLocaleCookie } from \"./resolver\";\nimport { localizeFarmHref } from \"./routing\";\nimport {\n  _hydrateFarmI18n,\n  createFarmClientTranslator,\n  getFarmI18nClientState,\n  subscribeFarmI18n,\n  t,\n} from \"./client-runtime\";\nimport type { FarmI18nClientSnapshot, FarmI18nLocale, FarmTranslator } from \"./types\";\n\nexport interface FarmLocaleState {\n  locale: FarmI18nLocale;\n  locales: readonly FarmI18nLocale[];\n  direction: \"ltr\" | \"rtl\";\n  setLocale(locale: FarmI18nLocale): void;\n}\n\ninterface FarmListFormatOptions {\n  localeMatcher?: \"lookup\" | \"best fit\";\n  type?: \"conjunction\" | \"disjunction\" | \"unit\";\n  style?: \"long\" | \"short\" | \"narrow\";\n}\n\nexport function useLocale(): FarmLocaleState {\n  const snapshot = useFarmI18nSnapshot();\n  return useMemo(\n    () => ({\n      locale: snapshot.locale as FarmI18nLocale,\n      locales: snapshot.locales as readonly FarmI18nLocale[],\n      direction: snapshot.direction,\n      setLocale,\n    }),\n    [snapshot],\n  );\n}\n\nexport function useTranslations(): FarmTranslator {\n  useFarmI18nSnapshot();\n  return createFarmClientTranslator();\n}\n\nexport function getLocale(): FarmI18nLocale {\n  return requireSnapshot().locale as FarmI18nLocale;\n}\n\nexport function getLocaleSource(): FarmI18nClientSnapshot[\"source\"] {\n  return requireSnapshot().source;\n}\n\nexport function createTranslator(): FarmTranslator {\n  return createFarmClientTranslator();\n}\n\nexport function setLocale(locale: FarmI18nLocale): void {\n  const snapshot = requireSnapshot();\n  if (!snapshot.locales.includes(locale)) {\n    throw new Error(`Unsupported Farm i18n locale \"${locale}\".`);\n  }\n  if (typeof window === \"undefined\") return;\n\n  document.cookie = createFarmLocaleCookie(locale, { cookie: snapshot.cookie });\n\n  const currentHref = `${window.location.pathname}${window.location.search}${window.location.hash}`;\n  const nextHref = localizeFarmHref(currentHref, locale, snapshot);\n  window.location.assign(nextHref);\n}\n\nexport function _setFarmI18nClientSnapshot(snapshot: FarmI18nClientSnapshot): void {\n  _hydrateFarmI18n(snapshot);\n}\n\nexport const format = {\n  number(value: number, options?: Intl.NumberFormatOptions): string {\n    return new Intl.NumberFormat(requireSnapshot().locale, options).format(value);\n  },\n  currency(\n    value: number,\n    currency: string,\n    options: Omit<Intl.NumberFormatOptions, \"style\" | \"currency\"> = {},\n  ): string {\n    return new Intl.NumberFormat(requireSnapshot().locale, {\n      ...options,\n      style: \"currency\",\n      currency,\n    }).format(value);\n  },\n  date(value: Date | number, options?: Intl.DateTimeFormatOptions): string {\n    return new Intl.DateTimeFormat(requireSnapshot().locale, options).format(value);\n  },\n  relativeTime(\n    value: number,\n    unit: Intl.RelativeTimeFormatUnit,\n    options?: Intl.RelativeTimeFormatOptions,\n  ): string {\n    return new Intl.RelativeTimeFormat(requireSnapshot().locale, options).format(value, unit);\n  },\n  list(values: Iterable<string>, options?: FarmListFormatOptions): string {\n    const ListFormat = (Intl as any).ListFormat;\n    return new ListFormat(requireSnapshot().locale, options).format(Array.from(values));\n  },\n};\n\nfunction useFarmI18nSnapshot(): FarmI18nClientSnapshot {\n  const snapshot = useSyncExternalStore(\n    subscribeFarmI18n,\n    getFarmI18nClientState,\n    getFarmI18nClientState,\n  );\n  if (!snapshot) {\n    throw new Error(\"Farm i18n is not configured or has not been hydrated.\");\n  }\n  return snapshot;\n}\n\nfunction requireSnapshot(): FarmI18nClientSnapshot {\n  const snapshot = getFarmI18nClientState();\n  if (!snapshot) {\n    throw new Error(\"Farm i18n is not configured or has not been hydrated.\");\n  }\n  return snapshot;\n}\n\nexport { t };\nexport type {\n  FarmI18nClientSnapshot,\n  FarmI18nLocale,\n  FarmI18nMessageArgs,\n  FarmI18nMessageKey,\n} from \"./types\";\n","const FARM_BASE_PATH = Symbol.for(\"farm.basePath\");\n\nfunction getFarmGlobalState(): Record<PropertyKey, unknown> {\n  return globalThis as unknown as Record<PropertyKey, unknown>;\n}\n\n/** @internal Configure the app-wide base path for framework link rendering. */\nexport function setFarmBasePath(basePath: string | undefined): void {\n  getFarmGlobalState()[FARM_BASE_PATH] = normalizeFarmBasePath(basePath);\n}\n\n/** @internal Read the app-wide base path used by framework links. */\nexport function getFarmBasePath(): string {\n  return (getFarmGlobalState()[FARM_BASE_PATH] as string | undefined) ?? \"\";\n}\n\nexport function applyFarmBasePath(href: string, basePath = getFarmBasePath()): string {\n  const normalizedBasePath = normalizeFarmBasePath(basePath);\n  if (!normalizedBasePath || !href.startsWith(\"/\") || href.startsWith(\"//\")) return href;\n  const canonicalHref = canonicalizeAppRelativeHref(href);\n  if (\n    canonicalHref === normalizedBasePath ||\n    canonicalHref.startsWith(`${normalizedBasePath}/`) ||\n    canonicalHref.startsWith(`${normalizedBasePath}?`) ||\n    canonicalHref.startsWith(`${normalizedBasePath}#`)\n  ) {\n    return canonicalHref;\n  }\n  return `${normalizedBasePath}${canonicalHref}`;\n}\n\nfunction canonicalizeAppRelativeHref(href: string): string {\n  const origin = \"http://farm.local\";\n  const resolved = new URL(href, origin);\n  if (resolved.origin !== origin) {\n    throw new Error(\"Farm app-relative href cannot change the URL origin.\");\n  }\n  return `${resolved.pathname}${resolved.search}${resolved.hash}`;\n}\n\nexport function stripFarmBasePath(pathname: string, basePath = getFarmBasePath()): string {\n  const normalizedBasePath = normalizeFarmBasePath(basePath);\n  if (!normalizedBasePath) return pathname || \"/\";\n  if (pathname === normalizedBasePath) return \"/\";\n  if (!pathname.startsWith(`${normalizedBasePath}/`)) return pathname || \"/\";\n  return pathname.slice(normalizedBasePath.length) || \"/\";\n}\n\nexport function normalizeFarmBasePath(basePath: string | undefined): string {\n  if (!basePath || basePath === \"/\") return \"\";\n\n  const hasUnstableCharacters = (candidate: string) =>\n    candidate.includes(\"\\\\\") ||\n    Array.from(candidate).some((character) => {\n      const code = character.charCodeAt(0);\n      return code <= 31 || (code >= 127 && code <= 159);\n    });\n\n  if (hasUnstableCharacters(basePath)) {\n    throw new Error(\"Farm basePath cannot contain backslashes or control characters.\");\n  }\n\n  const pathname = basePath.trim();\n  if (!pathname || pathname === \"/\") return \"\";\n  if (pathname.includes(\"?\") || pathname.includes(\"#\")) {\n    throw new Error(\"Farm basePath cannot contain a query string or hash.\");\n  }\n  if (pathname.startsWith(\"//\") || /^[a-z][a-z\\d+.-]*:\\/\\//i.test(pathname)) {\n    throw new Error('Farm basePath must be a pathname such as \"/docs\", not a URL.');\n  }\n\n  for (const segment of pathname.split(\"/\")) {\n    let decoded = segment;\n    try {\n      decoded = decodeURIComponent(segment);\n    } catch {\n      // Malformed escapes remain literal in URL pathnames and cannot be dot segments.\n    }\n    if (hasUnstableCharacters(decoded)) {\n      throw new Error(\"Farm basePath cannot contain backslashes or control characters.\");\n    }\n    if (decoded.includes(\"/\")) {\n      throw new Error(\"Farm basePath cannot contain percent-encoded path separators.\");\n    }\n    if (decoded === \".\" || decoded === \"..\") {\n      throw new Error('Farm basePath cannot contain \".\" or \"..\" path segments.');\n    }\n  }\n\n  return `/${pathname}`.replace(/\\/{2,}/g, \"/\").replace(/\\/+$/, \"\");\n}\n\n/** Normalize a configured application base path while preserving `/` for root. */\nexport function normalizeFarmConfigBasePath(basePath: string | undefined): string {\n  return normalizeFarmBasePath(basePath) || \"/\";\n}\n","import { applyFarmBasePath, stripFarmBasePath } from \"../base-path\";\nimport type { FarmI18nDirection, FarmI18nRouting, ResolvedFarmI18nConfig } from \"./types\";\n\nexport interface FarmLocalePathConfig {\n  locales: readonly string[];\n  defaultLocale: string;\n  routing: FarmI18nRouting;\n  basePath?: string;\n}\n\nexport interface FarmLocalePathMatch {\n  locale?: string;\n  pathname: string;\n  explicit: boolean;\n}\n\nconst RTL_LANGUAGES = new Set([\n  \"ar\",\n  \"arc\",\n  \"ckb\",\n  \"dv\",\n  \"fa\",\n  \"he\",\n  \"ku\",\n  \"nqo\",\n  \"ps\",\n  \"sd\",\n  \"syr\",\n  \"ug\",\n  \"ur\",\n  \"yi\",\n]);\n\nexport function resolveFarmLocalePath(\n  pathname: string,\n  config: FarmLocalePathConfig,\n): FarmLocalePathMatch {\n  const normalized = normalizePathname(stripFarmBasePath(pathname, config.basePath));\n  if (config.routing === \"none\") {\n    return { pathname: normalized, explicit: false };\n  }\n\n  const segments = normalized.split(\"/\").filter(Boolean);\n  const firstSegment = segments[0];\n  const locale = config.locales.find(\n    (candidate) => candidate.toLowerCase() === firstSegment?.toLowerCase(),\n  );\n  if (!locale) {\n    return { pathname: normalized, explicit: false };\n  }\n\n  const remaining = segments.slice(1);\n  return {\n    locale,\n    pathname: remaining.length > 0 ? `/${remaining.join(\"/\")}` : \"/\",\n    explicit: true,\n  };\n}\n\nexport function stripFarmLocaleFromPathname(\n  pathname: string,\n  config: FarmLocalePathConfig,\n): string {\n  return resolveFarmLocalePath(pathname, config).pathname;\n}\n\nexport function localizeFarmPathname(\n  pathname: string,\n  locale: string,\n  config: FarmLocalePathConfig,\n): string {\n  const internalPathname = resolveFarmLocalePath(pathname, config).pathname;\n  let localizedPathname = internalPathname;\n  if (config.routing === \"none\") {\n    return applyFarmBasePath(localizedPathname, config.basePath);\n  }\n  if (config.routing === \"prefix-except-default\" && locale === config.defaultLocale) {\n    return applyFarmBasePath(localizedPathname, config.basePath);\n  }\n  localizedPathname = internalPathname === \"/\" ? `/${locale}` : `/${locale}${internalPathname}`;\n  return applyFarmBasePath(localizedPathname, config.basePath);\n}\n\nexport function localizeFarmHref(\n  href: string,\n  locale: string,\n  config: FarmLocalePathConfig,\n): string {\n  if (!href.startsWith(\"/\") || href.startsWith(\"//\")) return href;\n  const url = new URL(href, \"http://farm.local\");\n  url.pathname = localizeFarmPathname(url.pathname, locale, config);\n  return `${url.pathname}${url.search}${url.hash}`;\n}\n\nexport function getFarmLocaleDirection(\n  locale: string,\n  direction: ResolvedFarmI18nConfig[\"direction\"] | undefined,\n): FarmI18nDirection {\n  const configured = direction?.[locale];\n  if (configured) return configured;\n  const language = locale.split(\"-\")[0]?.toLowerCase() || locale.toLowerCase();\n  return RTL_LANGUAGES.has(language) ? \"rtl\" : \"ltr\";\n}\n\nfunction normalizePathname(pathname: string): string {\n  const withLeadingSlash = pathname.startsWith(\"/\") ? pathname : `/${pathname}`;\n  if (withLeadingSlash === \"/\") return \"/\";\n  return withLeadingSlash.replace(/\\/{2,}/g, \"/\").replace(/\\/$/, \"\") || \"/\";\n}\n","import { localizeFarmPathname, resolveFarmLocalePath } from \"./routing\";\nimport { stripFarmBasePath } from \"../base-path\";\nimport type { FarmI18nLocaleSource, ResolvedFarmI18nConfig } from \"./types\";\n\nexport interface FarmLocaleResolution {\n  locale: string;\n  source: FarmI18nLocaleSource;\n  pathname: string;\n  redirect?: string;\n  persist: boolean;\n}\n\nexport function getFarmLocaleVaryHeaders(\n  config: ResolvedFarmI18nConfig,\n  resolution: FarmLocaleResolution,\n): string[] {\n  if (!config.enabled || resolution.source === \"url\") return [];\n\n  const headers: string[] = [];\n  if (config.detection.includes(\"cookie\")) headers.push(\"Cookie\");\n  if (config.detection.includes(\"accept-language\")) headers.push(\"Accept-Language\");\n  return headers;\n}\n\nexport function resolveFarmLocaleRequest(\n  request: Request,\n  config: ResolvedFarmI18nConfig,\n  options: { redirect?: boolean } = {},\n): FarmLocaleResolution {\n  const url = new URL(request.url);\n  if (!config.enabled) {\n    return {\n      locale: config.defaultLocale,\n      source: \"default\",\n      pathname: url.pathname,\n      persist: false,\n    };\n  }\n\n  const pathMatch = resolveFarmLocalePath(url.pathname, config);\n  if (pathMatch.explicit && pathMatch.locale) {\n    const canonicalPath = localizeFarmPathname(pathMatch.pathname, pathMatch.locale, config);\n    // The locale canonical is always trailing-slash-free, but the app's dedicated\n    // trailing-slash redirect owns that normalization. When the only difference is\n    // a trailing slash, defer to it: otherwise, under trailingSlash: true, the i18n\n    // redirect (strip) and the trailing-slash redirect (add) bounce a locale URL\n    // between 307 and 308 forever and every locale page becomes unreachable.\n    const differsOnlyByTrailingSlash =\n      canonicalPath !== url.pathname &&\n      (url.pathname.length > 1 ? url.pathname.replace(/\\/+$/, \"\") : url.pathname) === canonicalPath;\n    const redirect =\n      options.redirect !== false && canonicalPath !== url.pathname && !differsOnlyByTrailingSlash\n        ? `${canonicalPath}${url.search}${url.hash}`\n        : undefined;\n    return {\n      locale: pathMatch.locale,\n      source: \"url\",\n      pathname: pathMatch.pathname,\n      redirect,\n      // Locale-prefixed pages are canonical and can be cached publicly. Locale\n      // switchers persist the same choice before navigating in the browser.\n      persist: false,\n    };\n  }\n\n  const detected = detectLocale(request, config);\n  const shouldRedirect =\n    options.redirect !== false &&\n    !isInternalOrApiPath(stripFarmBasePath(url.pathname, config.basePath)) &&\n    config.routing !== \"none\" &&\n    (config.routing === \"prefix-always\" || detected.locale !== config.defaultLocale);\n\n  return {\n    locale: detected.locale,\n    source: detected.source,\n    pathname: pathMatch.pathname,\n    redirect: shouldRedirect\n      ? `${localizeFarmPathname(pathMatch.pathname, detected.locale, config)}${url.search}${url.hash}`\n      : undefined,\n    persist: detected.source !== \"default\",\n  };\n}\n\nexport function createFarmLocaleCookie(\n  locale: string,\n  config: Pick<ResolvedFarmI18nConfig, \"cookie\">,\n): string {\n  const cookie = config.cookie;\n  let value = `${encodeURIComponent(cookie.name)}=${encodeURIComponent(locale)}`;\n  value += `; Max-Age=${cookie.maxAge}`;\n  value += `; Path=${cookie.path}`;\n  value += `; SameSite=${capitalize(cookie.sameSite)}`;\n  if (cookie.secure) value += \"; Secure\";\n  return value;\n}\n\nexport function matchFarmLocale(\n  requested: string | null | undefined,\n  locales: readonly string[],\n): string | undefined {\n  if (!requested) return undefined;\n  let canonical: string;\n  try {\n    canonical = Intl.getCanonicalLocales(requested)[0]!;\n  } catch {\n    return undefined;\n  }\n\n  const exact = locales.find((locale) => locale.toLowerCase() === canonical.toLowerCase());\n  if (exact) return exact;\n\n  const language = canonical.split(\"-\")[0]?.toLowerCase();\n  const base = locales.find((locale) => locale.toLowerCase() === language);\n  if (base) return base;\n  return locales.find((locale) => locale.split(\"-\")[0]?.toLowerCase() === language);\n}\n\nfunction detectLocale(\n  request: Request,\n  config: ResolvedFarmI18nConfig,\n): { locale: string; source: FarmI18nLocaleSource } {\n  for (const signal of config.detection) {\n    if (signal === \"url\") continue;\n\n    if (signal === \"cookie\") {\n      const locale = matchFarmLocale(\n        readCookie(request.headers.get(\"cookie\"), config.cookie.name),\n        config.locales,\n      );\n      if (locale) return { locale, source: \"cookie\" };\n    }\n\n    if (signal === \"accept-language\") {\n      const locale = resolveAcceptLanguage(request.headers.get(\"accept-language\"), config.locales);\n      if (locale) return { locale, source: \"accept-language\" };\n    }\n  }\n\n  return { locale: config.defaultLocale, source: \"default\" };\n}\n\nfunction resolveAcceptLanguage(\n  header: string | null,\n  locales: readonly string[],\n): string | undefined {\n  if (!header) return undefined;\n\n  const byRange = new Map<string, { locale: string; quality: number; index: number }>();\n  for (const [index, entry] of header.split(\",\").entries()) {\n    const [rawLocale = \"\", ...parameters] = entry.trim().split(\";\");\n    const locale = rawLocale.trim();\n    if (!locale) continue;\n\n    let quality = 1;\n    for (const parameter of parameters) {\n      const [rawName, rawValue] = parameter.trim().split(\"=\", 2);\n      if (rawName?.trim().toLowerCase() !== \"q\") continue;\n      const value = rawValue?.trim() ?? \"\";\n      quality = /^(?:0(?:\\.\\d{0,3})?|1(?:\\.0{0,3})?)$/.test(value) ? Number(value) : 0;\n    }\n\n    const key = locale.toLowerCase();\n    const previous = byRange.get(key);\n    if (!previous || quality > previous.quality) {\n      byRange.set(key, { locale, quality, index: previous?.index ?? index });\n    }\n  }\n\n  const candidates = [...byRange.values()]\n    .filter((candidate) => candidate.quality > 0)\n    .sort((a, b) => b.quality - a.quality || a.index - b.index);\n  const explicitRanges = [...byRange.values()].filter(({ locale }) => locale !== \"*\");\n\n  for (const candidate of candidates) {\n    if (candidate.locale === \"*\") {\n      const wildcardMatch = locales.find(\n        (locale) =>\n          !explicitRanges.some((range) => matchFarmLocale(range.locale, [locale]) !== undefined),\n      );\n      if (wildcardMatch) return wildcardMatch;\n      continue;\n    }\n\n    const locale = matchFarmLocale(candidate.locale, locales);\n    if (locale) return locale;\n  }\n  return undefined;\n}\n\nfunction readCookie(header: string | null, name: string): string | undefined {\n  if (!header) return undefined;\n  for (const part of header.split(\";\")) {\n    const separator = part.indexOf(\"=\");\n    if (separator < 0) continue;\n    let key: string;\n    try {\n      key = decodeURIComponent(part.slice(0, separator).trim());\n    } catch {\n      continue;\n    }\n    if (key !== name) continue;\n    try {\n      return decodeURIComponent(part.slice(separator + 1).trim());\n    } catch {\n      return part.slice(separator + 1).trim();\n    }\n  }\n  return undefined;\n}\n\nfunction isInternalOrApiPath(pathname: string): boolean {\n  return (\n    pathname === \"/api\" ||\n    pathname.startsWith(\"/api/\") ||\n    pathname.startsWith(\"/__farm/\") ||\n    pathname.startsWith(\"/_farm/\")\n  );\n}\n\nfunction capitalize(value: string): string {\n  return value.charAt(0).toUpperCase() + value.slice(1);\n}\n","import IntlMessageFormat from \"intl-messageformat\";\nimport { getActiveFarmI18nSnapshot } from \"./bridge\";\nimport { localizeFarmHref, resolveFarmLocalePath } from \"./routing\";\nimport type {\n  FarmI18nClientSnapshot,\n  FarmI18nLocale,\n  FarmI18nMessageArgs,\n  FarmI18nMessageKey,\n  FarmTranslator,\n} from \"./types\";\n\ntype Listener = () => void;\n\nconst listeners = new Set<Listener>();\nconst compiled = new Map<string, IntlMessageFormat>();\nlet currentSnapshot: FarmI18nClientSnapshot | undefined;\n\nexport function getFarmI18nClientState(): FarmI18nClientSnapshot | undefined {\n  return currentSnapshot || getActiveFarmI18nSnapshot();\n}\n\nexport function subscribeFarmI18n(listener: Listener): () => void {\n  listeners.add(listener);\n  return () => listeners.delete(listener);\n}\n\nexport function _hydrateFarmI18n(snapshot: FarmI18nClientSnapshot | undefined): void {\n  if (!snapshot) return;\n  const changed = currentSnapshot?.locale !== snapshot.locale;\n  currentSnapshot = snapshot;\n  if (typeof window !== \"undefined\") window.__FARM_I18N__ = snapshot;\n  if (typeof document !== \"undefined\") {\n    document.documentElement.lang = snapshot.locale;\n    document.documentElement.dir = snapshot.direction;\n  }\n  if (changed) compiled.clear();\n  for (const listener of listeners) listener();\n}\n\n// Only own catalog entries count. `snapshot.messages` is a spread object that\n// inherits Object.prototype, so a bare lookup for a key like \"toString\" or\n// \"constructor\" would resolve to a native method. The server side guards the\n// same way (readOwnMessage), so without this the client diverges: the server\n// renders the literal key while the client feeds a function to IntlMessageFormat\n// and throws during hydration.\nconst readOwnMessage = (messages: Record<string, string>, key: string): string | undefined =>\n  Object.prototype.hasOwnProperty.call(messages, key) ? messages[key] : undefined;\n\nconst translate = (key: string, values?: Record<string, unknown>, rich = false): unknown => {\n  const snapshot = requireSnapshot();\n  const message = readOwnMessage(snapshot.messages, key);\n  if (message === undefined) return key;\n  const cacheKey = `${snapshot.locale}\\u0000${key}\\u0000${message}`;\n  let formatter = compiled.get(cacheKey);\n  if (!formatter) {\n    formatter = new IntlMessageFormat(message, snapshot.locale);\n    compiled.set(cacheKey, formatter);\n  }\n  const result = formatter.format(values as any);\n  if (rich) return Array.isArray(result) && result.length === 1 ? result[0] : result;\n  if (Array.isArray(result) && result.some((part) => typeof part !== \"string\")) {\n    throw new Error(`Farm i18n message \"${key}\" contains rich content. Render it with t.rich().`);\n  }\n  return Array.isArray(result) ? result.join(\"\") : String(result);\n};\n\nexport const t = ((key: string, values?: Record<string, unknown>) =>\n  translate(key, values)) as FarmTranslator;\nt.rich = (key: string, values?: Record<string, unknown>) => translate(key, values, true);\nt.raw = (key: string) => readOwnMessage(requireSnapshot().messages, key) ?? key;\nt.has = (key: string) => Object.prototype.hasOwnProperty.call(requireSnapshot().messages, key);\n\nexport function localizeActiveFarmHref(href: string, locale?: FarmI18nLocale): string {\n  const snapshot = getFarmI18nClientState();\n  if (!snapshot) return href;\n  return localizeFarmHref(href, locale || snapshot.locale, snapshot);\n}\n\nexport function isFarmLocaleChangeHref(href: string): boolean {\n  const snapshot = getFarmI18nClientState();\n  if (!snapshot || typeof window === \"undefined\") return false;\n  if (snapshot.routing === \"none\") return false;\n  const target = new URL(href, window.location.origin);\n  const match = resolveFarmLocalePath(target.pathname, snapshot);\n  const targetLocale = match.locale || snapshot.defaultLocale;\n  return targetLocale !== snapshot.locale;\n}\n\nexport function createFarmClientTranslator(): FarmTranslator {\n  return (<TKey extends FarmI18nMessageKey>(key: TKey, ...args: FarmI18nMessageArgs<TKey>) =>\n    t(key, ...args)) as FarmTranslator;\n}\n\nfunction requireSnapshot(): FarmI18nClientSnapshot {\n  const snapshot = getFarmI18nClientState();\n  if (!snapshot) {\n    throw new Error(\"Farm i18n is not configured or has not been hydrated.\");\n  }\n  return snapshot;\n}\n","import type { FarmI18nClientSnapshot } from \"./types\";\n\ntype SnapshotResolver = () => FarmI18nClientSnapshot | undefined;\n\nconst FARM_I18N_SNAPSHOT_RESOLVER = Symbol.for(\"farm.i18n.snapshotResolver\");\ntype GlobalWithI18nResolver = typeof globalThis & {\n  [FARM_I18N_SNAPSHOT_RESOLVER]?: SnapshotResolver;\n};\n\nexport function _setFarmI18nSnapshotResolver(resolver: SnapshotResolver | undefined): void {\n  (globalThis as GlobalWithI18nResolver)[FARM_I18N_SNAPSHOT_RESOLVER] = resolver;\n}\n\nexport function getActiveFarmI18nSnapshot(): FarmI18nClientSnapshot | undefined {\n  if (typeof window !== \"undefined\" && window.__FARM_I18N__) {\n    return window.__FARM_I18N__;\n  }\n  return (globalThis as GlobalWithI18nResolver)[FARM_I18N_SNAPSHOT_RESOLVER]?.();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA8C;;;ACF9C,IAAM,iBAAiB,uBAAO,IAAI,eAAe;AAEjD,SAAS,qBAAmD;AAC1D,SAAO;AACT;AAFS;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