@stacksjs/stx 0.2.37 → 0.2.38
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/dist/cli.js +533 -529
- package/dist/index.d.ts +8 -0
- package/dist/index.js +576 -572
- package/dist/site-builder/i18n.d.ts +66 -0
- package/dist/site-builder/index.d.ts +10 -0
- package/dist/site-builder/types.d.ts +10 -0
- package/package.json +2 -2
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
* `/` stays `/` for the default locale; otherwise it's `/<code>/`.
|
|
37
|
+
* `/about` becomes `/<code>/about` for non-default locales.
|
|
38
|
+
*/
|
|
39
|
+
export declare function localizePath(path: string, locale: string, defaultLocale: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Reverse of `localizePath`: strip a locale prefix off a path so we
|
|
42
|
+
* can compute the equivalent path in another locale.
|
|
43
|
+
*/
|
|
44
|
+
export declare function stripLocalePrefix(path: string, locales: string[]): { locale: string | null, path: string };
|
|
45
|
+
/**
|
|
46
|
+
* `<link rel="alternate" hreflang>` block + `<link rel="canonical">`
|
|
47
|
+
* for the page being rendered. Search engines treat each as the
|
|
48
|
+
* authoritative copy for its locale.
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildAlternateLinks(siteUrl: string, pagePath: string, i18n: ResolvedI18n): string;
|
|
51
|
+
/**
|
|
52
|
+
* Inline script that wires up the language picker.
|
|
53
|
+
*
|
|
54
|
+
* Per-page logic: each `<button data-lang="…">` inside the configured
|
|
55
|
+
* picker selector navigates to the equivalent path in the chosen
|
|
56
|
+
* locale, using the locale list shipped in `window.__stxI18n`. Marks
|
|
57
|
+
* the active button with `aria-current="true"` for styling.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildLangPickerScript(i18n: ResolvedI18n, currentLocale: string): string;
|
|
60
|
+
export declare interface ResolvedI18n {
|
|
61
|
+
locales: string[]
|
|
62
|
+
defaultLocale: string
|
|
63
|
+
labels: Record<string, string>
|
|
64
|
+
translations: Record<string, Record<string, string>>
|
|
65
|
+
pickerSelector: string
|
|
66
|
+
}
|
|
@@ -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.
|
|
4
|
+
"version": "0.2.38",
|
|
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.
|
|
124
|
+
"stx-router": "0.2.38",
|
|
125
125
|
"ts-broadcasting": "^0.0.4",
|
|
126
126
|
"ts-syntax-highlighter": "^0.2.1"
|
|
127
127
|
}
|