@riebeckite/plugin-l10n 0.0.16 → 0.0.17
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 +1 -1
- package/README_ja.md +1 -1
- package/dist/index.js +9 -12
- package/dist/src/l10n.d.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ No fallback pages are generated. `getLocalization(manifest, slug)` returns `avai
|
|
|
52
52
|
|
|
53
53
|
## Standard LanguageSwitcher
|
|
54
54
|
|
|
55
|
-
`l10n(...)` publishes the built-in, styled LanguageSwitcher in the standard `article.
|
|
55
|
+
`l10n(...)` publishes the built-in, styled LanguageSwitcher in the standard `article.metadata` layout slot. A standard Site consumer renders that slot, so no l10n-specific article integration is needed. It is omitted when a page has fewer than two real translations.
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
58
|
// Keep URLs and metadata but do not publish UI.
|
package/README_ja.md
CHANGED
|
@@ -37,7 +37,7 @@ translation: getting-started
|
|
|
37
37
|
|
|
38
38
|
## 標準 LanguageSwitcher
|
|
39
39
|
|
|
40
|
-
`l10n(...)` は標準記事レイアウトの `article.
|
|
40
|
+
`l10n(...)` は標準記事レイアウトの `article.metadata` スロットへ、組み込みの LanguageSwitcher を登録します。標準 Site consumer がこのスロットを描画するため、l10n 専用の記事レイアウト実装は不要です。実在する翻訳が 2 つ未満のページには表示されません。
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
43
|
// URL とメタデータは維持し、UI だけを無効化します。
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,6 @@ function renderLanguageSwitcher({
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// src/l10n.ts
|
|
27
|
-
var LANGUAGE_METADATA_KEY = "l10n.lang";
|
|
28
27
|
var TRANSLATION_METADATA_KEY = "l10n.translationId";
|
|
29
28
|
function l10n(options) {
|
|
30
29
|
const resolved = resolveOptions(options);
|
|
@@ -109,7 +108,7 @@ function splitLinkUrl(url) {
|
|
|
109
108
|
function getLocalization(manifest, slug) {
|
|
110
109
|
const entry = manifest.bySlug.get(slug);
|
|
111
110
|
if (!entry) return null;
|
|
112
|
-
const lang = entry.publicLocation.
|
|
111
|
+
const lang = entry.publicLocation.language;
|
|
113
112
|
const translationId = entry.publicLocation.metadata?.[TRANSLATION_METADATA_KEY];
|
|
114
113
|
if (!lang || !translationId) return null;
|
|
115
114
|
const candidates = manifest.discoverableEntries.filter(
|
|
@@ -117,7 +116,7 @@ function getLocalization(manifest, slug) {
|
|
|
117
116
|
);
|
|
118
117
|
const translations = Object.fromEntries(
|
|
119
118
|
uniqueLanguageEntries(candidates).map((candidate) => [
|
|
120
|
-
candidate.publicLocation.
|
|
119
|
+
candidate.publicLocation.language ?? "",
|
|
121
120
|
candidate.permalink
|
|
122
121
|
])
|
|
123
122
|
);
|
|
@@ -134,14 +133,14 @@ function getLocalizedContent(manifest, slug, lang) {
|
|
|
134
133
|
const localization = getLocalization(manifest, slug);
|
|
135
134
|
if (!localization) return null;
|
|
136
135
|
const candidates = manifest.publicEntries.filter(
|
|
137
|
-
(entry) => entry.publicLocation.metadata?.[TRANSLATION_METADATA_KEY] === localization.translationId && entry.publicLocation.
|
|
136
|
+
(entry) => entry.publicLocation.metadata?.[TRANSLATION_METADATA_KEY] === localization.translationId && entry.publicLocation.language === lang
|
|
138
137
|
);
|
|
139
138
|
return candidates.length === 1 ? candidates[0] ?? null : null;
|
|
140
139
|
}
|
|
141
140
|
function getLanguageFromPath(manifest, pathname) {
|
|
142
141
|
const firstSegment = pathname.split("/").filter(Boolean)[0];
|
|
143
142
|
if (!firstSegment) return void 0;
|
|
144
|
-
return manifest.discoverableEntries.map((entry) => entry.publicLocation.
|
|
143
|
+
return manifest.discoverableEntries.map((entry) => entry.publicLocation.language).find(
|
|
145
144
|
(language) => language?.toLocaleLowerCase() === firstSegment.toLocaleLowerCase()
|
|
146
145
|
);
|
|
147
146
|
}
|
|
@@ -208,7 +207,7 @@ function validateOptions(options) {
|
|
|
208
207
|
function resolveUiOptions(ui) {
|
|
209
208
|
if (ui === false) return false;
|
|
210
209
|
return {
|
|
211
|
-
slot: ui?.slot ?? "article.
|
|
210
|
+
slot: ui?.slot ?? "article.metadata",
|
|
212
211
|
render: ui?.render ?? renderLanguageSwitcher
|
|
213
212
|
};
|
|
214
213
|
}
|
|
@@ -347,13 +346,13 @@ function withLocalization(location, content, options) {
|
|
|
347
346
|
return {
|
|
348
347
|
...location,
|
|
349
348
|
permalink,
|
|
349
|
+
language: content.lang,
|
|
350
350
|
redirects: location.redirects?.map((redirect) => ({
|
|
351
351
|
...redirect,
|
|
352
352
|
path: localizePath(redirect.path, content, options)
|
|
353
353
|
})),
|
|
354
354
|
metadata: {
|
|
355
355
|
...location.metadata,
|
|
356
|
-
[LANGUAGE_METADATA_KEY]: content.lang,
|
|
357
356
|
[TRANSLATION_METADATA_KEY]: content.translationId
|
|
358
357
|
}
|
|
359
358
|
};
|
|
@@ -411,7 +410,7 @@ function addLocalizationHeadTags(manifest, state) {
|
|
|
411
410
|
tag: "link",
|
|
412
411
|
attrs: {
|
|
413
412
|
rel: "alternate",
|
|
414
|
-
hreflang: translation.publicLocation.
|
|
413
|
+
hreflang: translation.publicLocation.language ?? "",
|
|
415
414
|
href: translation.permalink
|
|
416
415
|
}
|
|
417
416
|
})
|
|
@@ -440,10 +439,8 @@ function sameHeadTag(left, right) {
|
|
|
440
439
|
}
|
|
441
440
|
function uniqueLanguageEntries(entries) {
|
|
442
441
|
return entries.filter((entry) => {
|
|
443
|
-
const lang = entry.publicLocation.
|
|
444
|
-
return lang !== void 0 && entries.filter(
|
|
445
|
-
(other) => other.publicLocation.metadata?.[LANGUAGE_METADATA_KEY] === lang
|
|
446
|
-
).length === 1;
|
|
442
|
+
const lang = entry.publicLocation.language;
|
|
443
|
+
return lang !== void 0 && entries.filter((other) => other.publicLocation.language === lang).length === 1;
|
|
447
444
|
});
|
|
448
445
|
}
|
|
449
446
|
function compactSignals(signals) {
|
package/dist/src/l10n.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type L10nOptions = {
|
|
|
25
25
|
ui?: L10nUiOptions;
|
|
26
26
|
};
|
|
27
27
|
export type L10nUiOptions = false | {
|
|
28
|
-
/** Defaults to the standard `article.
|
|
28
|
+
/** Defaults to the standard `article.metadata` slot. */
|
|
29
29
|
slot?: ContentBodySlot;
|
|
30
30
|
/** Replaces the built-in server-rendered LanguageSwitcher. */
|
|
31
31
|
render?: (context: LanguageSwitcherRenderContext) => string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-l10n",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
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.17"
|
|
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.17"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|