Skip to content

Commit

Permalink
Make default 404 text i18n-able
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis committed Jun 17, 2023
1 parent d8e3422 commit 8e41a7a
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 19 deletions.
21 changes: 10 additions & 11 deletions packages/starlight/404.astro
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
---
import { getEntry } from 'astro:content';
import config from 'virtual:starlight/user-config';
import * as default404 from './components/Default404.md';
import EmptyContent from './components/EmptyMarkdown.md';
import Page from './layout/Page.astro';
import type { StarlightDocsEntry } from './utils/routing';
import { useTranslations } from './utils/translations';
const { lang = 'en', dir = 'ltr', locale } = config.defaultLocale || {};
const entryMeta = { dir, lang, locale };
const t = useTranslations(locale);
const fallbackEntry: StarlightDocsEntry = {
slug: '404',
id: '404.md' as StarlightDocsEntry['id'],
body: default404.rawContent(),
body: '',
collection: 'docs',
data: {
title: 'Not found',
title: '404',
template: 'splash',
editUrl: false,
head: [],
hero: {
title: '404',
tagline: 'Houston we have a problem.',
actions: [],
},
hero: { tagline: t('404.text'), actions: [] },
},
render: async () => ({
Content: default404.Content,
headings: default404.getHeadings(),
Content: EmptyContent,
headings: [],
remarkPluginFrontmatter: {},
}),
};
const entry = (await getEntry('docs', '404')) || fallbackEntry;
const userEntry = await getEntry('docs', '404');
const entry = userEntry || fallbackEntry;
const { Content, headings } = await entry.render();
---

Expand Down
1 change: 0 additions & 1 deletion packages/starlight/components/Default404.md

This file was deleted.

Empty file.
4 changes: 4 additions & 0 deletions packages/starlight/schemas/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ function starlightI18nSchema() {
.describe(
'Label shown on the “next page” pagination arrow in the page footer.'
),

'404.text': z
.string()
.describe('Text shown on Starlight’s default 404 page'),
})
.partial();
}
Expand Down
3 changes: 2 additions & 1 deletion packages/starlight/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"page.editLink": "Seite bearbeiten",
"page.lastUpdated": "Zuletzt bearbeitet:",
"page.previousLink": "Vorherige Seite",
"page.nextLink": "Nächste Seite"
"page.nextLink": "Nächste Seite",
"404.text": "Seite nicht gefunden. Überprüfe die URL oder nutze die Suchleiste."
}
3 changes: 2 additions & 1 deletion packages/starlight/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"page.editLink": "Edit page",
"page.lastUpdated": "Last updated:",
"page.previousLink": "Previous",
"page.nextLink": "Next"
"page.nextLink": "Next",
"404.text": "Page not found. Check the URL or try using the search bar."
}
3 changes: 2 additions & 1 deletion packages/starlight/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"page.editLink": "Edita esta página",
"page.lastUpdated": "Última actualización:",
"page.previousLink": "Página anterior",
"page.nextLink": "Siguiente página"
"page.nextLink": "Siguiente página",
"404.text": "Página no encontrada. Verifique la URL o intente usar la barra de búsqueda."
}
3 changes: 2 additions & 1 deletion packages/starlight/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"page.editLink": "Editer la page",
"page.lastUpdated": "Dernière mise à jour :",
"page.previousLink": "Précédent",
"page.nextLink": "Suivant"
"page.nextLink": "Suivant",
"404.text": "Page non trouvée. Vérifiez l'URL ou essayez d'utiliser la barre de recherche."
}
3 changes: 2 additions & 1 deletion packages/starlight/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"page.editLink": "Modifica pagina",
"page.lastUpdated": "Ultimo aggiornamento:",
"page.previousLink": "Indietro",
"page.nextLink": "Avanti"
"page.nextLink": "Avanti",
"404.text": "Pagina non trovata. Verifica l'URL o prova a utilizzare la barra di ricerca."
}
3 changes: 2 additions & 1 deletion packages/starlight/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"page.editLink": "ページを編集",
"page.lastUpdated": "最終更新日:",
"page.previousLink": "前へ",
"page.nextLink": "次へ"
"page.nextLink": "次へ",
"404.text": "ページが見つかりません。 URL を確認するか、検索バーを使用してみてください。"
}
3 changes: 2 additions & 1 deletion packages/starlight/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"page.editLink": "Editar página",
"page.lastUpdated": "Última atualização:",
"page.previousLink": "Anterior",
"page.nextLink": "Próximo"
"page.nextLink": "Próximo",
"404.text": "Página não encontrada. Verifique o URL ou tente usar a barra de pesquisa."
}

0 comments on commit 8e41a7a

Please sign in to comment.