@lovalingo/lovalingo 0.5.29 → 0.6.0
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/README.md +34 -0
- package/dist/chunk-2FZR2AKF.mjs +88 -0
- package/dist/chunk-7D5LBV45.mjs +46 -0
- package/dist/chunk-CJOSN7RA.mjs +90 -0
- package/dist/chunk-VAHA2TOX.mjs +3440 -0
- package/dist/chunk-ZMRCSUM7.mjs +26 -0
- package/dist/chunk-ZVYKEEUF.mjs +220 -0
- package/dist/core.d.mts +131 -0
- package/dist/core.d.ts +131 -0
- package/dist/core.js +3561 -0
- package/dist/core.mjs +19 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -25
- package/dist/index.js +3885 -28
- package/dist/index.mjs +33 -0
- package/dist/react-router.d.mts +101 -0
- package/dist/react-router.d.ts +101 -0
- package/dist/react-router.js +353 -0
- package/dist/react-router.mjs +14 -0
- package/dist/tanstack-router.d.mts +22 -0
- package/dist/tanstack-router.d.ts +22 -0
- package/dist/tanstack-router.js +162 -0
- package/dist/tanstack-router.mjs +8 -0
- package/package.json +34 -3
- package/dist/__tests__/languageFlags.test.d.ts +0 -1
- package/dist/__tests__/languageFlags.test.js +0 -42
- package/dist/__tests__/mergeEntitlements.test.d.ts +0 -1
- package/dist/__tests__/mergeEntitlements.test.js +0 -27
- package/dist/components/AixsterProvider.d.ts +0 -1
- package/dist/components/AixsterProvider.js +0 -1
- package/dist/components/LangLink.d.ts +0 -20
- package/dist/components/LangLink.js +0 -38
- package/dist/components/LangRouter.d.ts +0 -37
- package/dist/components/LangRouter.js +0 -191
- package/dist/components/LanguageSwitcher.d.ts +0 -17
- package/dist/components/LanguageSwitcher.js +0 -257
- package/dist/components/LovalingoProvider.d.ts +0 -10
- package/dist/components/LovalingoProvider.js +0 -413
- package/dist/components/NavigationOverlay.d.ts +0 -6
- package/dist/components/NavigationOverlay.js +0 -22
- package/dist/components/provider/__tests__/seoUtils.test.d.ts +0 -1
- package/dist/components/provider/__tests__/seoUtils.test.js +0 -13
- package/dist/components/provider/editModeUtils.d.ts +0 -6
- package/dist/components/provider/editModeUtils.js +0 -59
- package/dist/components/provider/localeUtils.d.ts +0 -8
- package/dist/components/provider/localeUtils.js +0 -46
- package/dist/components/provider/providerConstants.d.ts +0 -12
- package/dist/components/provider/providerConstants.js +0 -11
- package/dist/components/provider/seoUtils.d.ts +0 -8
- package/dist/components/provider/seoUtils.js +0 -118
- package/dist/components/provider/useEditModeOverlay.d.ts +0 -7
- package/dist/components/provider/useEditModeOverlay.js +0 -134
- package/dist/components/provider/useHistoryNavigationPatch.d.ts +0 -3
- package/dist/components/provider/useHistoryNavigationPatch.js +0 -47
- package/dist/components/provider/useProviderCache.d.ts +0 -12
- package/dist/components/provider/useProviderCache.js +0 -82
- package/dist/context/AixsterContext.d.ts +0 -3
- package/dist/context/AixsterContext.js +0 -2
- package/dist/context/LangContext.d.ts +0 -1
- package/dist/context/LangContext.js +0 -2
- package/dist/context/LangRoutingContext.d.ts +0 -8
- package/dist/context/LangRoutingContext.js +0 -7
- package/dist/context/LovalingoContext.d.ts +0 -1
- package/dist/context/LovalingoContext.js +0 -1
- package/dist/hooks/provider/useBundleLoading.d.ts +0 -33
- package/dist/hooks/provider/useBundleLoading.js +0 -380
- package/dist/hooks/provider/useDomRules.d.ts +0 -15
- package/dist/hooks/provider/useDomRules.js +0 -38
- package/dist/hooks/provider/useLinkAutoPrefix.d.ts +0 -12
- package/dist/hooks/provider/useLinkAutoPrefix.js +0 -146
- package/dist/hooks/provider/useNavigationPrefetch.d.ts +0 -12
- package/dist/hooks/provider/useNavigationPrefetch.js +0 -82
- package/dist/hooks/provider/usePageviewTracking.d.ts +0 -10
- package/dist/hooks/provider/usePageviewTracking.js +0 -44
- package/dist/hooks/provider/usePrehide.d.ts +0 -5
- package/dist/hooks/provider/usePrehide.js +0 -72
- package/dist/hooks/provider/useSitemapLinkTag.d.ts +0 -7
- package/dist/hooks/provider/useSitemapLinkTag.js +0 -28
- package/dist/hooks/provider/useStringMissReporting.d.ts +0 -14
- package/dist/hooks/provider/useStringMissReporting.js +0 -155
- package/dist/hooks/useAixster.d.ts +0 -6
- package/dist/hooks/useAixster.js +0 -14
- package/dist/hooks/useAixsterEdit.d.ts +0 -5
- package/dist/hooks/useAixsterEdit.js +0 -13
- package/dist/hooks/useAixsterTranslate.d.ts +0 -4
- package/dist/hooks/useAixsterTranslate.js +0 -12
- package/dist/hooks/useLang.d.ts +0 -16
- package/dist/hooks/useLang.js +0 -23
- package/dist/hooks/useLangNavigate.d.ts +0 -24
- package/dist/hooks/useLangNavigate.js +0 -40
- package/dist/hooks/useLovalingo.d.ts +0 -1
- package/dist/hooks/useLovalingo.js +0 -1
- package/dist/hooks/useLovalingoEdit.d.ts +0 -1
- package/dist/hooks/useLovalingoEdit.js +0 -1
- package/dist/hooks/useLovalingoTranslate.d.ts +0 -1
- package/dist/hooks/useLovalingoTranslate.js +0 -1
- package/dist/types.d.ts +0 -76
- package/dist/types.js +0 -1
- package/dist/utils/api.d.ts +0 -42
- package/dist/utils/api.js +0 -395
- package/dist/utils/apiTypes.d.ts +0 -78
- package/dist/utils/apiTypes.js +0 -1
- package/dist/utils/apiUtils.d.ts +0 -4
- package/dist/utils/apiUtils.js +0 -54
- package/dist/utils/domRules.d.ts +0 -2
- package/dist/utils/domRules.js +0 -150
- package/dist/utils/hash.d.ts +0 -9
- package/dist/utils/hash.js +0 -27
- package/dist/utils/languageFlags.d.ts +0 -7
- package/dist/utils/languageFlags.js +0 -90
- package/dist/utils/logger.d.ts +0 -3
- package/dist/utils/logger.js +0 -40
- package/dist/utils/markerEngine.d.ts +0 -12
- package/dist/utils/markerEngine.js +0 -109
- package/dist/utils/markerEngineApply.d.ts +0 -3
- package/dist/utils/markerEngineApply.js +0 -136
- package/dist/utils/markerEngineConstants.d.ts +0 -10
- package/dist/utils/markerEngineConstants.js +0 -12
- package/dist/utils/markerEngineCritical.d.ts +0 -2
- package/dist/utils/markerEngineCritical.js +0 -98
- package/dist/utils/markerEngineDomUtils.d.ts +0 -8
- package/dist/utils/markerEngineDomUtils.js +0 -74
- package/dist/utils/markerEngineFilters.d.ts +0 -2
- package/dist/utils/markerEngineFilters.js +0 -26
- package/dist/utils/markerEngineMisses.d.ts +0 -5
- package/dist/utils/markerEngineMisses.js +0 -81
- package/dist/utils/markerEngineOriginals.d.ts +0 -5
- package/dist/utils/markerEngineOriginals.js +0 -29
- package/dist/utils/markerEngineScan.d.ts +0 -5
- package/dist/utils/markerEngineScan.js +0 -162
- package/dist/utils/markerEngineState.d.ts +0 -4
- package/dist/utils/markerEngineState.js +0 -14
- package/dist/utils/markerEngineStats.d.ts +0 -3
- package/dist/utils/markerEngineStats.js +0 -28
- package/dist/utils/markerEngineTranslations.d.ts +0 -3
- package/dist/utils/markerEngineTranslations.js +0 -49
- package/dist/utils/markerEngineTypes.d.ts +0 -62
- package/dist/utils/markerEngineTypes.js +0 -1
- package/dist/utils/markerEngineViewport.d.ts +0 -2
- package/dist/utils/markerEngineViewport.js +0 -27
- package/dist/utils/mergeEntitlements.d.ts +0 -2
- package/dist/utils/mergeEntitlements.js +0 -7
- package/dist/utils/nonLocalizedPaths.d.ts +0 -12
- package/dist/utils/nonLocalizedPaths.js +0 -136
- package/dist/utils/pathNormalizer.d.ts +0 -49
- package/dist/utils/pathNormalizer.js +0 -115
- package/dist/version.d.ts +0 -1
- package/dist/version.js +0 -1
package/README.md
CHANGED
|
@@ -52,6 +52,40 @@ export function App() {
|
|
|
52
52
|
|
|
53
53
|
URLs look like: `/de/pricing`.
|
|
54
54
|
|
|
55
|
+
## TanStack Start / TanStack Router
|
|
56
|
+
|
|
57
|
+
Use the router-free core entry and TanStack rewrite helper. Do not add React Router to TanStack apps.
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
// src/router.tsx
|
|
61
|
+
import { createLovalingoTanStackRewrite } from "@lovalingo/lovalingo/tanstack-router";
|
|
62
|
+
|
|
63
|
+
const lovalingoLocales = ["en", "de", "fr"] as const;
|
|
64
|
+
|
|
65
|
+
const router = createRouter({
|
|
66
|
+
routeTree,
|
|
67
|
+
rewrite: createLovalingoTanStackRewrite({
|
|
68
|
+
defaultLocale: "en",
|
|
69
|
+
locales: [...lovalingoLocales],
|
|
70
|
+
prefixDefaultLocale: true,
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
// src/routes/__root.tsx
|
|
77
|
+
import { Outlet } from "@tanstack/react-router";
|
|
78
|
+
import { LovalingoProvider } from "@lovalingo/lovalingo/core";
|
|
79
|
+
|
|
80
|
+
function RootComponent() {
|
|
81
|
+
return (
|
|
82
|
+
<LovalingoProvider publicAnonKey="aix_your_public_anon_key" defaultLocale="en" locales={["de", "fr"]} routing="path" autoPrefixLinks={false}>
|
|
83
|
+
<Outlet />
|
|
84
|
+
</LovalingoProvider>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
55
89
|
## Next.js (App Router)
|
|
56
90
|
|
|
57
91
|
```tsx
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// src/utils/nonLocalizedPaths.ts
|
|
2
|
+
var GLOBAL_NON_LOCALIZED_APP_PATHS = /* @__PURE__ */ new Set(["/robots.txt", "/sitemap.xml"]);
|
|
3
|
+
function isGlobalNonLocalizedPath(pathname) {
|
|
4
|
+
const input = (pathname || "").toString();
|
|
5
|
+
if (!input.startsWith("/")) return false;
|
|
6
|
+
if (GLOBAL_NON_LOCALIZED_APP_PATHS.has(input)) return true;
|
|
7
|
+
if (input.startsWith("/.well-known/")) return true;
|
|
8
|
+
return /\.(?:png|jpg|jpeg|gif|svg|webp|avif|ico|css|js|map|json|xml|txt|pdf|zip|gz|br|woff2?|ttf|eot)$/i.test(input);
|
|
9
|
+
}
|
|
10
|
+
function matchesNonLocalizedRules(pathname, rules) {
|
|
11
|
+
const input = (pathname || "").toString();
|
|
12
|
+
if (!input.startsWith("/")) return false;
|
|
13
|
+
if (!Array.isArray(rules) || rules.length === 0) return false;
|
|
14
|
+
for (const rule of rules) {
|
|
15
|
+
const pattern = typeof rule?.pattern === "string" ? rule.pattern : "";
|
|
16
|
+
const matchType = rule?.match_type;
|
|
17
|
+
if (!pattern) continue;
|
|
18
|
+
if (matchType === "exact") {
|
|
19
|
+
if (input === pattern) return true;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (matchType === "prefix") {
|
|
23
|
+
if (input === pattern) return true;
|
|
24
|
+
const normalizedPrefix = pattern.endsWith("/") ? pattern.slice(0, -1) : pattern;
|
|
25
|
+
if (!normalizedPrefix || normalizedPrefix === "/") return true;
|
|
26
|
+
if (input.startsWith(`${normalizedPrefix}/`)) return true;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (matchType === "regex") {
|
|
30
|
+
try {
|
|
31
|
+
if (new RegExp(pattern).test(input)) return true;
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
function isNonLocalizedPath(pathname, rules) {
|
|
39
|
+
return isGlobalNonLocalizedPath(pathname) || matchesNonLocalizedRules(pathname, rules);
|
|
40
|
+
}
|
|
41
|
+
function stripLocalePrefix(pathname, locales) {
|
|
42
|
+
const input = (pathname || "").toString();
|
|
43
|
+
if (!input.startsWith("/")) return input;
|
|
44
|
+
const parts = input.split("/").filter(Boolean);
|
|
45
|
+
if (parts.length === 0) return "/";
|
|
46
|
+
const first = parts[0] || "";
|
|
47
|
+
if (!first || !Array.isArray(locales) || !locales.includes(first)) return input;
|
|
48
|
+
const rest = `/${parts.slice(1).join("/")}`;
|
|
49
|
+
return rest === "" ? "/" : rest;
|
|
50
|
+
}
|
|
51
|
+
function parseBootstrapNonLocalizedPaths(value) {
|
|
52
|
+
if (!Array.isArray(value)) return [];
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const row of value) {
|
|
55
|
+
if (!row || typeof row !== "object") continue;
|
|
56
|
+
const record = row;
|
|
57
|
+
const pattern = typeof record.pattern === "string" ? record.pattern.trim() : "";
|
|
58
|
+
const match_type = typeof record.match_type === "string" ? record.match_type.trim() : "";
|
|
59
|
+
if (!pattern) continue;
|
|
60
|
+
if (match_type !== "exact" && match_type !== "prefix" && match_type !== "regex") continue;
|
|
61
|
+
out.push({ pattern, match_type });
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
function parseBootstrapInactivePages(value) {
|
|
66
|
+
if (!Array.isArray(value)) return [];
|
|
67
|
+
const out = [];
|
|
68
|
+
for (const row of value) {
|
|
69
|
+
if (typeof row === "string") {
|
|
70
|
+
const pagePath2 = row.trim();
|
|
71
|
+
if (pagePath2 && pagePath2.startsWith("/")) out.push(pagePath2);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (!row || typeof row !== "object") continue;
|
|
75
|
+
const record = row;
|
|
76
|
+
const pagePath = typeof record.page_path === "string" ? record.page_path.trim() : "";
|
|
77
|
+
if (!pagePath || !pagePath.startsWith("/")) continue;
|
|
78
|
+
out.push(pagePath);
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
isNonLocalizedPath,
|
|
85
|
+
stripLocalePrefix,
|
|
86
|
+
parseBootstrapNonLocalizedPaths,
|
|
87
|
+
parseBootstrapInactivePages
|
|
88
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/context/LangRoutingContext.ts
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
var LangRoutingContext = createContext({
|
|
4
|
+
defaultLang: "",
|
|
5
|
+
nonLocalizedPaths: [],
|
|
6
|
+
inactivePages: [],
|
|
7
|
+
status: "unknown"
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// src/utils/logger.ts
|
|
11
|
+
function isDebugEnabled() {
|
|
12
|
+
if (typeof globalThis === "undefined") return false;
|
|
13
|
+
const value = globalThis.__lovalingoDebug;
|
|
14
|
+
if (value === true || value === "true" || value === 1) return true;
|
|
15
|
+
try {
|
|
16
|
+
const params = typeof window !== "undefined" ? new URLSearchParams(window.location.search) : null;
|
|
17
|
+
const query = params?.get("lovalingoDebug") || params?.get("lovalingo_debug") || "";
|
|
18
|
+
if (query === "1" || query === "true") return true;
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const stored = typeof window !== "undefined" ? window.localStorage?.getItem("Lovalingo_debug") : null;
|
|
23
|
+
if (stored === "1" || stored === "true") return true;
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
function logDebug(...args) {
|
|
29
|
+
if (!isDebugEnabled()) return;
|
|
30
|
+
console.log(...args);
|
|
31
|
+
}
|
|
32
|
+
function warnDebug(...args) {
|
|
33
|
+
if (!isDebugEnabled()) return;
|
|
34
|
+
console.warn(...args);
|
|
35
|
+
}
|
|
36
|
+
function errorDebug(...args) {
|
|
37
|
+
if (!isDebugEnabled()) return;
|
|
38
|
+
console.error(...args);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
LangRoutingContext,
|
|
43
|
+
logDebug,
|
|
44
|
+
warnDebug,
|
|
45
|
+
errorDebug
|
|
46
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LOCALE_STORAGE_KEY
|
|
3
|
+
} from "./chunk-ZMRCSUM7.mjs";
|
|
4
|
+
import {
|
|
5
|
+
isNonLocalizedPath,
|
|
6
|
+
stripLocalePrefix
|
|
7
|
+
} from "./chunk-2FZR2AKF.mjs";
|
|
8
|
+
|
|
9
|
+
// src/tanstack-router.ts
|
|
10
|
+
function normalizeLocale(value) {
|
|
11
|
+
return typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
12
|
+
}
|
|
13
|
+
function uniq(items) {
|
|
14
|
+
return Array.from(new Set(items));
|
|
15
|
+
}
|
|
16
|
+
function buildPathWithLocale(locale, pathname) {
|
|
17
|
+
const normalizedPath = pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
18
|
+
if (normalizedPath === "/") return `/${locale}`;
|
|
19
|
+
return `/${locale}${normalizedPath}`;
|
|
20
|
+
}
|
|
21
|
+
function cloneUrlWithPathname(url, pathname) {
|
|
22
|
+
const next = new URL(url.href);
|
|
23
|
+
next.pathname = pathname || "/";
|
|
24
|
+
return next;
|
|
25
|
+
}
|
|
26
|
+
function readStoredLocale(supportedLocales) {
|
|
27
|
+
if (typeof window === "undefined") return "";
|
|
28
|
+
try {
|
|
29
|
+
const stored = normalizeLocale(window.localStorage?.getItem(LOCALE_STORAGE_KEY));
|
|
30
|
+
return supportedLocales.includes(stored) ? stored : "";
|
|
31
|
+
} catch {
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function detectLocaleFromPath(pathname, supportedLocales) {
|
|
36
|
+
const first = pathname.split("/").filter(Boolean)[0] || "";
|
|
37
|
+
const normalized = normalizeLocale(first);
|
|
38
|
+
return supportedLocales.includes(normalized) ? normalized : "";
|
|
39
|
+
}
|
|
40
|
+
function createLovalingoTanStackRewrite({
|
|
41
|
+
defaultLocale,
|
|
42
|
+
locales,
|
|
43
|
+
prefixDefaultLocale = true,
|
|
44
|
+
nonLocalizedPaths = [],
|
|
45
|
+
getLocale
|
|
46
|
+
}) {
|
|
47
|
+
const normalizedDefaultLocale = normalizeLocale(defaultLocale);
|
|
48
|
+
const supportedLocales = uniq([normalizedDefaultLocale, ...(locales || []).map(normalizeLocale)].filter(Boolean));
|
|
49
|
+
const fallbackLocale = normalizedDefaultLocale || supportedLocales[0] || "en";
|
|
50
|
+
let activeLocale = fallbackLocale;
|
|
51
|
+
const resolveOutputLocale = (pathname) => {
|
|
52
|
+
const explicitLocale = normalizeLocale(getLocale?.());
|
|
53
|
+
if (supportedLocales.includes(explicitLocale)) {
|
|
54
|
+
activeLocale = explicitLocale;
|
|
55
|
+
return explicitLocale;
|
|
56
|
+
}
|
|
57
|
+
const pathLocale = detectLocaleFromPath(pathname, supportedLocales);
|
|
58
|
+
if (pathLocale) {
|
|
59
|
+
activeLocale = pathLocale;
|
|
60
|
+
return pathLocale;
|
|
61
|
+
}
|
|
62
|
+
const storedLocale = readStoredLocale(supportedLocales);
|
|
63
|
+
if (storedLocale) {
|
|
64
|
+
activeLocale = storedLocale;
|
|
65
|
+
return storedLocale;
|
|
66
|
+
}
|
|
67
|
+
return supportedLocales.includes(activeLocale) ? activeLocale : fallbackLocale;
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
input: ({ url }) => {
|
|
71
|
+
const pathLocale = detectLocaleFromPath(url.pathname, supportedLocales);
|
|
72
|
+
if (!pathLocale) return void 0;
|
|
73
|
+
activeLocale = pathLocale;
|
|
74
|
+
const stripped = stripLocalePrefix(url.pathname, supportedLocales);
|
|
75
|
+
return cloneUrlWithPathname(url, stripped || "/");
|
|
76
|
+
},
|
|
77
|
+
output: ({ url }) => {
|
|
78
|
+
const internalPath = stripLocalePrefix(url.pathname, supportedLocales);
|
|
79
|
+
if (isNonLocalizedPath(internalPath, nonLocalizedPaths)) return void 0;
|
|
80
|
+
if (detectLocaleFromPath(url.pathname, supportedLocales)) return void 0;
|
|
81
|
+
const locale = resolveOutputLocale(url.pathname);
|
|
82
|
+
if (!prefixDefaultLocale && locale === fallbackLocale) return void 0;
|
|
83
|
+
return cloneUrlWithPathname(url, buildPathWithLocale(locale, internalPath));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
createLovalingoTanStackRewrite
|
|
90
|
+
};
|