@riebeckite/plugin-l10n 0.0.8 → 0.0.9

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/index.js CHANGED
@@ -2,11 +2,28 @@
2
2
  import {
3
3
  appendContentBodySlot,
4
4
  createStyleAsset,
5
- definePlugin,
6
- escapeHtml,
7
- escapeHtmlAttribute
5
+ definePlugin
8
6
  } from "@riebeckite/core";
9
7
  import { parse } from "yaml";
8
+
9
+ // src/language-switcher.ts
10
+ import { escapeHtml, escapeHtmlAttribute } from "@riebeckite/core";
11
+ function renderLanguageSwitcher({
12
+ localization
13
+ }) {
14
+ if (localization.availableLanguages.length < 2) return null;
15
+ const links = localization.availableLanguages.map((lang) => {
16
+ const href = localization.translations[lang];
17
+ if (!href) return "";
18
+ const current = lang === localization.lang ? ' aria-current="page"' : "";
19
+ const escaped = escapeHtml(lang);
20
+ return `<li><a class="l10n-switcher__link" href="${escapeHtmlAttribute(href)}" hreflang="${escapeHtmlAttribute(lang)}" lang="${escapeHtmlAttribute(lang)}"${current}>${escaped}</a></li>`;
21
+ }).join("");
22
+ if (!links) return null;
23
+ return `<nav class="l10n-switcher" aria-label="Language"><span class="l10n-switcher__label">Language</span><ul class="l10n-switcher__list">${links}</ul></nav>`;
24
+ }
25
+
26
+ // src/l10n.ts
10
27
  var LANGUAGE_METADATA_KEY = "l10n.lang";
11
28
  var TRANSLATION_METADATA_KEY = "l10n.translationId";
12
29
  function l10n(options) {
@@ -360,20 +377,6 @@ function addLanguageSwitchers(manifest, ui) {
360
377
  if (html) appendContentBodySlot(entry, ui.slot, html);
361
378
  }
362
379
  }
363
- function renderLanguageSwitcher({
364
- localization
365
- }) {
366
- if (localization.availableLanguages.length < 2) return null;
367
- const links = localization.availableLanguages.map((lang) => {
368
- const href = localization.translations[lang];
369
- if (!href) return "";
370
- const current = lang === localization.lang ? ' aria-current="page"' : "";
371
- const escaped = escapeHtml(lang);
372
- return `<li><a class="l10n-switcher__link" href="${escapeHtmlAttribute(href)}" hreflang="${escapeHtmlAttribute(lang)}" lang="${escapeHtmlAttribute(lang)}"${current}>${escaped}</a></li>`;
373
- }).join("");
374
- if (!links) return null;
375
- return `<nav class="l10n-switcher" aria-label="Language"><span class="l10n-switcher__label">Language</span><ul class="l10n-switcher__list">${links}</ul></nav>`;
376
- }
377
380
  function uniqueLanguageEntries(entries) {
378
381
  return entries.filter((entry) => {
379
382
  const lang = entry.publicLocation.metadata?.[LANGUAGE_METADATA_KEY];
@@ -47,5 +47,4 @@ 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
- /** Framework-neutral default renderer for the standard LanguageSwitcher. */
51
- export declare function renderLanguageSwitcher({ localization, }: LanguageSwitcherRenderContext): string | null;
50
+ export { renderLanguageSwitcher } from "./language-switcher.js";
@@ -0,0 +1,3 @@
1
+ import type { LanguageSwitcherRenderContext } from "./l10n.js";
2
+ /** Framework-neutral default renderer for the standard LanguageSwitcher. */
3
+ export declare function renderLanguageSwitcher({ localization, }: LanguageSwitcherRenderContext): string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-l10n",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "yaml": "^2.9.0",
19
- "@riebeckite/core": "0.0.8"
19
+ "@riebeckite/core": "0.0.9"
20
20
  },
21
21
  "devDependencies": {
22
22
  "tsx": "^4.22.4"