@jgb-solutions/kit 0.4.2 → 0.4.3
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/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/dist/i18n.d.ts +6 -0
- package/dist/i18n.js +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@jgb-solutions/kit`. Versions follow semver.
|
|
4
4
|
|
|
5
|
+
## 0.4.3
|
|
6
|
+
|
|
7
|
+
- `@jgb-solutions/kit/i18n`: `defaultLocaleRedirect(path)` gives the unprefixed address for a path that spells out English (`/en/privacy?x=1` → `/privacy?x=1`, `/en` → `/`), for the site's 301; null for every other path.
|
|
8
|
+
|
|
5
9
|
## 0.4.2
|
|
6
10
|
|
|
7
11
|
- Dependency update: `jose` 6.2.18 to 6.2.19 (patch).
|
package/README.md
CHANGED
|
@@ -184,7 +184,7 @@ const offer = suggestLocale({ acceptLanguage: request.headers.get('accept-langua
|
|
|
184
184
|
// null: no bar. 'es': show "View this page in Español?", and on a click set the LOCALE_COOKIE cookie and go to localizedPath(path, 'es').
|
|
185
185
|
```
|
|
186
186
|
|
|
187
|
-
Also: `localeFromPath`, `stripLocale`, `isLocale`, `negotiate`, `LOCALES`, `LOCALE_NAMES` (each language in its own words). Placeholders are `{name}`; a plural leaf has `one` and `other` (plus `zero`, `two`, `few`, `many` where a language needs them) and takes `count`. Keep the catalogs honest in a test with `checkCatalog(en, fr)`: it lists missing and extra keys, empty strings, plurals without `other`, and placeholders that differ from English.
|
|
187
|
+
Also: `localeFromPath`, `stripLocale`, `defaultLocaleRedirect` (the 301 target for an `/en/…` address), `isLocale`, `negotiate`, `LOCALES`, `LOCALE_NAMES` (each language in its own words). Placeholders are `{name}`; a plural leaf has `one` and `other` (plus `zero`, `two`, `few`, `many` where a language needs them) and takes `count`. Keep the catalogs honest in a test with `checkCatalog(en, fr)`: it lists missing and extra keys, empty strings, plurals without `other`, and placeholders that differ from English.
|
|
188
188
|
|
|
189
189
|
### `@jgb-solutions/kit/admin`: the admin panel (React 19)
|
|
190
190
|
|
package/dist/i18n.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ export declare function isLocale(value: unknown): value is Locale;
|
|
|
18
18
|
export declare function localeFromPath(path: string): Locale;
|
|
19
19
|
/** The path without its /fr, /es or /ht prefix (query and hash kept). Always starts with "/". */
|
|
20
20
|
export declare function stripLocale(path: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Where an address that spells out English should go: "/en/privacy?x=1" → "/privacy?x=1", "/en" → "/".
|
|
23
|
+
* English has no prefix, so a site answers /en/… with a 301 to this address. Null for every other
|
|
24
|
+
* path ("/fr/a", "/english", "/"), which needs no redirect.
|
|
25
|
+
*/
|
|
26
|
+
export declare function defaultLocaleRedirect(path: string): string | null;
|
|
21
27
|
/** The path in another language: any prefix is replaced; English has none. Query and hash kept. */
|
|
22
28
|
export declare function localizedPath(path: string, locale: Locale): string;
|
|
23
29
|
/** hreflang alternates for a page's <head>: one per language, then x-default (English). */
|
package/dist/i18n.js
CHANGED
|
@@ -34,6 +34,12 @@ function stripLocale(path) {
|
|
|
34
34
|
return pathname + rest;
|
|
35
35
|
return (pathname.slice(segment.length + 1) || "/") + rest;
|
|
36
36
|
}
|
|
37
|
+
function defaultLocaleRedirect(path) {
|
|
38
|
+
const { pathname, rest } = splitPath(path);
|
|
39
|
+
if (firstSegment(pathname) !== DEFAULT_LOCALE)
|
|
40
|
+
return null;
|
|
41
|
+
return (pathname.slice(DEFAULT_LOCALE.length + 1) || "/") + rest;
|
|
42
|
+
}
|
|
37
43
|
function localizedPath(path, locale) {
|
|
38
44
|
const stripped = stripLocale(path);
|
|
39
45
|
if (locale === DEFAULT_LOCALE)
|
|
@@ -208,6 +214,7 @@ export {
|
|
|
208
214
|
alternates,
|
|
209
215
|
checkCatalog,
|
|
210
216
|
createTranslator,
|
|
217
|
+
defaultLocaleRedirect,
|
|
211
218
|
defineCatalog,
|
|
212
219
|
isLocale,
|
|
213
220
|
localeFromPath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jgb-solutions/kit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "One package for JGB Solutions apps, in tree-shakable namespaces: Cloudflare Access, Better Auth (kit/access, kit/auth\u2026) and the admin panel kit (kit/admin, React 19). An app bundles only the subpaths it imports.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "JGB Solutions",
|