@stacksjs/stx 0.2.37 → 0.2.39

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.
@@ -0,0 +1,75 @@
1
+ import type { SiteConfig, SiteI18nOptions } from './types';
2
+ export type { SiteI18nOptions };
3
+ /**
4
+ * Resolve i18n config into the runtime shape used by the build.
5
+ *
6
+ * Translations are merged from two sources, in priority order:
7
+ * 1. `i18n.translations[<locale>]` — inline strings from `site.config.ts`
8
+ * 2. `<translationsDir>/<locale>.<format>` on disk — JSON or YAML files
9
+ *
10
+ * Inline strings win on key conflicts, so config-level overrides don't
11
+ * require editing the shared translation files. Missing locales/files
12
+ * are silently tolerated; the file loader returns `{}` for anything it
13
+ * can't read so the default locale's table can still serve as a
14
+ * fallback at translate-time.
15
+ */
16
+ export declare function resolveI18n(site: SiteConfig, projectRoot?: string): ResolvedI18n | null;
17
+ /**
18
+ * Translate a key for a locale, falling back to the default locale's
19
+ * value, then to the key itself. The fallback chain keeps prototypes
20
+ * shippable even when only a subset of strings is translated.
21
+ */
22
+ export declare function translate(i18n: ResolvedI18n, locale: string, key: string): string;
23
+ /**
24
+ * Replace `{t:key}` markers in HTML with the translated string for
25
+ * the given locale. The key syntax sidesteps stx's `{{ ... }}`
26
+ * templating (which evaluates as JS at build time and would render
27
+ * `t(...)` calls as empty when no `t` binding exists in scope).
28
+ *
29
+ * Keys may use letters, digits, `_`, `.`, `-`. Anything that doesn't
30
+ * match the pattern is left alone — runs after stx has finished its
31
+ * own templating pass.
32
+ */
33
+ export declare function applyTranslations(html: string, i18n: ResolvedI18n, locale: string): string;
34
+ /**
35
+ * URL path for a built page in the given locale.
36
+ *
37
+ * - `/` stays `/` for the default locale; for non-default locales it
38
+ * becomes `/<code>/` (with the trailing slash). The slash matters
39
+ * because most static hosts (S3+CloudFront, GitHub Pages, etc.)
40
+ * only serve the directory's `index.html` when the URL ends in `/`
41
+ * — `/de` 404s, `/de/` resolves. Linking with the slash avoids a
42
+ * client-side redirect dance and lets SPA hops succeed without
43
+ * falling back to a full page load.
44
+ * - `/about` becomes `/<code>/about` for non-default locales (no
45
+ * trailing slash — those map to `<code>/about.html`).
46
+ * - `/404.html` keeps its filename and lives under the locale prefix.
47
+ */
48
+ export declare function localizePath(path: string, locale: string, defaultLocale: string): string;
49
+ /**
50
+ * Reverse of `localizePath`: strip a locale prefix off a path so we
51
+ * can compute the equivalent path in another locale.
52
+ */
53
+ export declare function stripLocalePrefix(path: string, locales: string[]): { locale: string | null, path: string };
54
+ /**
55
+ * `<link rel="alternate" hreflang>` block + `<link rel="canonical">`
56
+ * for the page being rendered. Search engines treat each as the
57
+ * authoritative copy for its locale.
58
+ */
59
+ export declare function buildAlternateLinks(siteUrl: string, pagePath: string, i18n: ResolvedI18n): string;
60
+ /**
61
+ * Inline script that wires up the language picker.
62
+ *
63
+ * Per-page logic: each `<button data-lang="…">` inside the configured
64
+ * picker selector navigates to the equivalent path in the chosen
65
+ * locale, using the locale list shipped in `window.__stxI18n`. Marks
66
+ * the active button with `aria-current="true"` for styling.
67
+ */
68
+ export declare function buildLangPickerScript(i18n: ResolvedI18n, currentLocale: string): string;
69
+ export declare interface ResolvedI18n {
70
+ locales: string[]
71
+ defaultLocale: string
72
+ labels: Record<string, string>
73
+ translations: Record<string, Record<string, string>>
74
+ pickerSelector: string
75
+ }
@@ -2,6 +2,7 @@ export type {
2
2
  BuildOptions,
3
3
  PageMeta,
4
4
  SiteConfig,
5
+ SiteI18nOptions,
5
6
  SiteRouterOptions,
6
7
  SiteSeo,
7
8
  SiteSocial,
@@ -13,3 +14,12 @@ export { generateSitemap, type SitemapEntry } from './sitemap';
13
14
  export { generateRobots } from './robots';
14
15
  export { injectRouterScript, type RouterOptions } from './router';
15
16
  export { injectThemeBootstrap, type ThemeOptions } from './theme';
17
+ export {
18
+ applyTranslations,
19
+ buildAlternateLinks,
20
+ buildLangPickerScript,
21
+ localizePath,
22
+ resolveI18n,
23
+ stripLocalePrefix,
24
+ translate,
25
+ } from './i18n';
@@ -31,6 +31,16 @@ export declare interface SiteConfig {
31
31
  spa?: boolean
32
32
  router?: SiteRouterOptions
33
33
  theme?: false | SiteThemeOptions
34
+ i18n?: SiteI18nOptions
35
+ }
36
+ export declare interface SiteI18nOptions {
37
+ locales: string[]
38
+ labels?: Record<string, string>
39
+ defaultLocale?: string
40
+ translations?: Record<string, Record<string, string>>
41
+ translationsDir?: string | false
42
+ format?: 'json' | 'yaml' | 'yml'
43
+ pickerSelector?: string
34
44
  }
35
45
  export declare interface SiteThemeOptions {
36
46
  default?: 'dark' | 'light' | 'auto'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.37",
4
+ "version": "0.2.39",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -121,7 +121,7 @@
121
121
  "@stacksjs/ts-craft": "^0.0.2",
122
122
  "bun-plugin-stx": "0.2.35",
123
123
  "bunfig": "^0.15.6",
124
- "stx-router": "0.2.36",
124
+ "stx-router": "0.2.38",
125
125
  "ts-broadcasting": "^0.0.4",
126
126
  "ts-syntax-highlighter": "^0.2.1"
127
127
  }