@astrojs/starlight 0.28.3 → 0.28.4

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @astrojs/starlight
2
2
 
3
+ ## 0.28.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2444](https://github.com/withastro/starlight/pull/2444) [`d585b3e`](https://github.com/withastro/starlight/commit/d585b3e0485dd55b2ffab985a6c06d267d22fe51) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes a UI string translation issue for languages with a region subtag.
8
+
9
+ - [#2518](https://github.com/withastro/starlight/pull/2518) [`0f69db8`](https://github.com/withastro/starlight/commit/0f69db8b806833a7160570a469ddcdc8c0dec5e0) Thanks [@morinokami](https://github.com/morinokami)! - Updates Japanese UI translations
10
+
11
+ - [#2507](https://github.com/withastro/starlight/pull/2507) [`bd6ced5`](https://github.com/withastro/starlight/commit/bd6ced5bc46310b217c7bfe83a0f68ba4a03da45) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes a table of contents highlighting issue after resizing the window.
12
+
13
+ - [#2444](https://github.com/withastro/starlight/pull/2444) [`d585b3e`](https://github.com/withastro/starlight/commit/d585b3e0485dd55b2ffab985a6c06d267d22fe51) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Refactors various components to use the new built-in localization system to access translated UI strings.
14
+
3
15
  ## 0.28.3
4
16
 
5
17
  ### Patch Changes
@@ -88,7 +88,10 @@ export class StarlightTOC extends HTMLElement {
88
88
  let timeout: NodeJS.Timeout;
89
89
  window.addEventListener('resize', () => {
90
90
  // Disable intersection observer while window is resizing.
91
- if (observer) observer.disconnect();
91
+ if (observer) {
92
+ observer.disconnect();
93
+ observer = undefined;
94
+ }
92
95
  clearTimeout(timeout);
93
96
  timeout = setTimeout(() => this.onIdle(observe), 200);
94
97
  });
@@ -17,9 +17,10 @@ import { visit } from 'unist-util-visit';
17
17
  import type { StarlightConfig } from '../types';
18
18
  import type { createTranslationSystemFromFs } from '../utils/translations-fs';
19
19
  import { pathToLocale } from './shared/pathToLocale';
20
+ import { localeToLang } from './shared/localeToLang';
20
21
 
21
22
  interface AsidesOptions {
22
- starlightConfig: { locales: StarlightConfig['locales'] };
23
+ starlightConfig: Pick<StarlightConfig, 'defaultLocale' | 'locales'>;
23
24
  astroConfig: { root: AstroConfig['root']; srcDir: AstroConfig['srcDir'] };
24
25
  useTranslations: ReturnType<typeof createTranslationSystemFromFs>;
25
26
  }
@@ -151,7 +152,8 @@ function remarkAsides(options: AsidesOptions): Plugin<[], Root> {
151
152
 
152
153
  const transformer: Transformer<Root> = (tree, file) => {
153
154
  const locale = pathToLocale(file.history[0], options);
154
- const t = options.useTranslations(locale);
155
+ const lang = localeToLang(options.starlightConfig, locale);
156
+ const t = options.useTranslations(lang);
155
157
  visit(tree, (node, index, parent) => {
156
158
  if (!parent || index === undefined || !isNodeDirective(node)) {
157
159
  return;
@@ -22,7 +22,7 @@ function addTranslationsForLocale(
22
22
  useTranslations: ReturnType<typeof createTranslationSystemFromFs>
23
23
  ) {
24
24
  const lang = localeToLang(config, locale);
25
- const t = useTranslations(locale);
25
+ const t = useTranslations(lang);
26
26
  const translationKeys = [
27
27
  'expressiveCode.copyButtonCopied',
28
28
  'expressiveCode.copyButtonTooltip',
@@ -5,7 +5,10 @@ import { BuiltInDefaultLocale } from '../../utils/i18n';
5
5
  * Get the BCP-47 language tag for the given locale.
6
6
  * @param locale Locale string or `undefined` for the root locale.
7
7
  */
8
- export function localeToLang(config: StarlightConfig, locale: string | undefined): string {
8
+ export function localeToLang(
9
+ config: Pick<StarlightConfig, 'defaultLocale' | 'locales'>,
10
+ locale: string | undefined
11
+ ): string {
9
12
  const lang = locale ? config.locales?.[locale]?.lang : config.locales?.root?.lang;
10
13
  const defaultLang = config.defaultLocale?.lang || config.defaultLocale?.locale;
11
14
  return lang || defaultLang || BuiltInDefaultLocale.lang;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/starlight",
3
- "version": "0.28.3",
3
+ "version": "0.28.4",
4
4
  "description": "Build beautiful, high-performance documentation websites with Astro",
5
5
  "keywords": [
6
6
  "docs",
@@ -3,7 +3,6 @@ import { getEntry } from 'astro:content';
3
3
  import config from 'virtual:starlight/user-config';
4
4
  import EmptyContent from '../../components/EmptyMarkdown.md';
5
5
  import type { Route, StarlightDocsEntry } from '../../utils/routing';
6
- import { useTranslations } from '../../utils/translations';
7
6
  import { BuiltInDefaultLocale } from '../../utils/i18n';
8
7
  import CommonPage from '../common.astro';
9
8
 
@@ -15,7 +14,6 @@ let locale = config.defaultLocale?.locale;
15
14
  if (locale === 'root') locale = undefined;
16
15
 
17
16
  const entryMeta = { dir, lang, locale };
18
- const t = useTranslations(locale);
19
17
 
20
18
  const fallbackEntry: StarlightDocsEntry = {
21
19
  slug: '404',
@@ -27,7 +25,7 @@ const fallbackEntry: StarlightDocsEntry = {
27
25
  template: 'splash',
28
26
  editUrl: false,
29
27
  head: [],
30
- hero: { tagline: t('404.text'), actions: [] },
28
+ hero: { tagline: Astro.locals.t('404.text'), actions: [] },
31
29
  pagefind: false,
32
30
  sidebar: { hidden: false, attrs: {} },
33
31
  draft: false,
@@ -18,12 +18,12 @@
18
18
  "page.lastUpdated": "最終更新日:",
19
19
  "page.previousLink": "前へ",
20
20
  "page.nextLink": "次へ",
21
- "page.draft": "This content is a draft and will not be included in production builds.",
21
+ "page.draft": "このコンテンツは下書きです。プロダクションビルドには含まれません。",
22
22
  "404.text": "ページが見つかりません。 URL を確認するか、検索バーを使用してみてください。",
23
23
  "aside.note": "ノート",
24
24
  "aside.tip": "ヒント",
25
25
  "aside.caution": "注意",
26
26
  "aside.danger": "危険",
27
27
  "fileTree.directory": "ディレクトリ",
28
- "builtWithStarlight.label": "Built with Starlight"
28
+ "builtWithStarlight.label": "Starlightで作成"
29
29
  }
@@ -1,7 +1,5 @@
1
1
  ---
2
2
  import { AstroError } from 'astro/errors';
3
- import { slugToLocaleData, urlToSlug } from '../utils/slugs';
4
- import { useTranslations } from '../utils/translations';
5
3
  import Icon from './Icon.astro';
6
4
 
7
5
  const asideVariants = ['note', 'tip', 'caution', 'danger'] as const;
@@ -23,8 +21,7 @@ if (!asideVariants.includes(type)) {
23
21
  }
24
22
 
25
23
  if (!title) {
26
- const { locale } = slugToLocaleData(urlToSlug(Astro.url));
27
- title = useTranslations(locale)(`aside.${type}`);
24
+ title = Astro.locals.t(`aside.${type}`);
28
25
  }
29
26
  ---
30
27
 
@@ -1,14 +1,8 @@
1
1
  ---
2
- import { stripLeadingAndTrailingSlashes } from '../utils/path';
3
- import { slugToLocaleData } from '../utils/slugs';
4
- import { useTranslations } from '../utils/translations';
5
2
  import { processFileTree } from './rehype-file-tree';
6
3
 
7
- const slug = stripLeadingAndTrailingSlashes(Astro.url.pathname);
8
- const t = useTranslations(slugToLocaleData(slug).locale);
9
-
10
4
  const fileTreeHtml = await Astro.slots.render('default');
11
- const html = processFileTree(fileTreeHtml, t('fileTree.directory'));
5
+ const html = processFileTree(fileTreeHtml, Astro.locals.t('fileTree.directory'));
12
6
  ---
13
7
 
14
8
  <starlight-file-tree set:html={html} class="not-content" data-pagefind-ignore />
@@ -49,14 +49,14 @@ export function createTranslationSystem<T extends i18nSchemaOutput>(
49
49
  });
50
50
 
51
51
  /**
52
- * Generate a utility function that returns UI strings for the given `locale`.
52
+ * Generate a utility function that returns UI strings for the given language.
53
53
  *
54
54
  * Also includes a few utility methods:
55
55
  * - `all()` method for getting the entire dictionary.
56
56
  * - `exists()` method for checking if a key exists in the dictionary.
57
57
  * - `dir()` method for getting the text direction of the locale.
58
58
  *
59
- * @param {string | undefined} [locale]
59
+ * @param {string | undefined} [lang]
60
60
  * @example
61
61
  * const t = useTranslations('en');
62
62
  * const label = t('search.label');
@@ -68,8 +68,8 @@ export function createTranslationSystem<T extends i18nSchemaOutput>(
68
68
  * const dir = t.dir();
69
69
  * // => 'ltr'
70
70
  */
71
- return (locale: string | undefined) => {
72
- const lang = localeToLang(locale, config.locales, config.defaultLocale);
71
+ return (lang: string | undefined) => {
72
+ lang ??= config.defaultLocale?.lang || BuiltInDefaultLocale.lang;
73
73
 
74
74
  const t = i18n.getFixedT(lang, I18nextNamespace) as I18nT;
75
75
  t.all = () => i18n.getResourceBundle(lang, I18nextNamespace);
@@ -62,7 +62,7 @@ export function generateRouteData({
62
62
  };
63
63
  }
64
64
 
65
- export function getToC({ entry, locale, headings }: PageProps) {
65
+ export function getToC({ entry, lang, headings }: PageProps) {
66
66
  const tocConfig =
67
67
  entry.data.template === 'splash'
68
68
  ? false
@@ -70,7 +70,7 @@ export function getToC({ entry, locale, headings }: PageProps) {
70
70
  ? entry.data.tableOfContents
71
71
  : config.tableOfContents;
72
72
  if (!tocConfig) return;
73
- const t = useTranslations(locale);
73
+ const t = useTranslations(lang);
74
74
  return {
75
75
  ...tocConfig,
76
76
  items: generateToC(headings, { ...tocConfig, title: t('tableOfContents.overview') }),
@@ -31,8 +31,8 @@ async function loadTranslations() {
31
31
  }
32
32
 
33
33
  /**
34
- * Generate a utility function that returns UI strings for the given `locale`.
35
- * @param {string | undefined} [locale]
34
+ * Generate a utility function that returns UI strings for the given language.
35
+ * @param {string | undefined} [lang]
36
36
  * @example
37
37
  * const t = useTranslations('en');
38
38
  * const label = t('search.label'); // => 'Search'