@riebeckite/plugin-l10n 0.0.15 → 0.0.16
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_ja.md +2 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -5
- package/dist/src/l10n.d.ts +1 -0
- package/package.json +3 -3
package/README_ja.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getLocalization, getLocalizedContent, type L10nContent, type L10nDetectorContext, type L10nDetectorResult, type L10nOptions, type L10nUiOptions, type LanguageSwitcherRenderContext, type LocalizedContent, l10n, l10nPlugin, renderLanguageSwitcher, } from "./src/l10n.js";
|
|
1
|
+
export { getLanguageFromPath, getLocalization, getLocalizedContent, type L10nContent, type L10nDetectorContext, type L10nDetectorResult, type L10nOptions, type L10nUiOptions, type LanguageSwitcherRenderContext, type LocalizedContent, l10n, l10nPlugin, renderLanguageSwitcher, } from "./src/l10n.js";
|
package/dist/index.js
CHANGED
|
@@ -138,6 +138,13 @@ function getLocalizedContent(manifest, slug, lang) {
|
|
|
138
138
|
);
|
|
139
139
|
return candidates.length === 1 ? candidates[0] ?? null : null;
|
|
140
140
|
}
|
|
141
|
+
function getLanguageFromPath(manifest, pathname) {
|
|
142
|
+
const firstSegment = pathname.split("/").filter(Boolean)[0];
|
|
143
|
+
if (!firstSegment) return void 0;
|
|
144
|
+
return manifest.discoverableEntries.map((entry) => entry.publicLocation.metadata?.[LANGUAGE_METADATA_KEY]).find(
|
|
145
|
+
(language) => language?.toLocaleLowerCase() === firstSegment.toLocaleLowerCase()
|
|
146
|
+
);
|
|
147
|
+
}
|
|
141
148
|
function resolveOptions(options) {
|
|
142
149
|
const validation = validateOptions(options);
|
|
143
150
|
if (validation.length > 0) throw new Error(validation.join("\n"));
|
|
@@ -336,14 +343,14 @@ function readTranslationId(value) {
|
|
|
336
343
|
return value.trim();
|
|
337
344
|
}
|
|
338
345
|
function withLocalization(location, content, options) {
|
|
339
|
-
const
|
|
340
|
-
location.permalink,
|
|
341
|
-
content
|
|
342
|
-
);
|
|
343
|
-
const permalink = content.lang === options.defaultLang ? unlocalizedPermalink : prefixLanguage(unlocalizedPermalink, content.lang);
|
|
346
|
+
const permalink = localizePath(location.permalink, content, options);
|
|
344
347
|
return {
|
|
345
348
|
...location,
|
|
346
349
|
permalink,
|
|
350
|
+
redirects: location.redirects?.map((redirect) => ({
|
|
351
|
+
...redirect,
|
|
352
|
+
path: localizePath(redirect.path, content, options)
|
|
353
|
+
})),
|
|
347
354
|
metadata: {
|
|
348
355
|
...location.metadata,
|
|
349
356
|
[LANGUAGE_METADATA_KEY]: content.lang,
|
|
@@ -351,6 +358,10 @@ function withLocalization(location, content, options) {
|
|
|
351
358
|
}
|
|
352
359
|
};
|
|
353
360
|
}
|
|
361
|
+
function localizePath(pathname, content, options) {
|
|
362
|
+
const unlocalizedPath = removeLocalePathSegments(pathname, content);
|
|
363
|
+
return content.lang === options.defaultLang ? unlocalizedPath : prefixLanguage(unlocalizedPath, content.lang);
|
|
364
|
+
}
|
|
354
365
|
function removeLocalePathSegments(permalink, content) {
|
|
355
366
|
let result = permalink;
|
|
356
367
|
const filenameLanguage = content.signals.filename;
|
|
@@ -499,6 +510,7 @@ function emptyState() {
|
|
|
499
510
|
};
|
|
500
511
|
}
|
|
501
512
|
export {
|
|
513
|
+
getLanguageFromPath,
|
|
502
514
|
getLocalization,
|
|
503
515
|
getLocalizedContent,
|
|
504
516
|
l10n,
|
package/dist/src/l10n.d.ts
CHANGED
|
@@ -47,4 +47,5 @@ export declare const l10nPlugin: typeof l10n;
|
|
|
47
47
|
export declare function getLocalization(manifest: ContentManifest, slug: string): LocalizedContent | null;
|
|
48
48
|
/** Resolves an existing translation; missing translations return `null`. */
|
|
49
49
|
export declare function getLocalizedContent(manifest: ContentManifest, slug: string, lang: string): ContentManifestEntry | null;
|
|
50
|
+
export declare function getLanguageFromPath(manifest: ContentManifest, pathname: string): string | undefined;
|
|
50
51
|
export { renderLanguageSwitcher } from "./language-switcher.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-l10n",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"yaml": "^2.9.0",
|
|
19
|
-
"@riebeckite/core": "0.0.
|
|
19
|
+
"@riebeckite/core": "0.0.16"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"tsx": "^4.22.4",
|
|
23
|
-
"@riebeckite/plugin-obsidian-markdown": "0.0.
|
|
23
|
+
"@riebeckite/plugin-obsidian-markdown": "0.0.16"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|