astro native i18n + i18n utils

This commit is contained in:
nico 2024-12-28 11:52:32 +01:00
parent 99ef7634e3
commit b7ce5b7f20
Signed by: Nicolas
SSH key fingerprint: SHA256:ELi8eDeNLl5PTn64G+o2Kx5+XVDfHF5um2tZigfwWkM
16 changed files with 266 additions and 163 deletions

View file

@ -1,6 +1,5 @@
---
import { astroI18n } from "astro-i18n";
astroI18n.init(Astro);
const locale = Astro.currentLocale;
import "../styles/style.css";
@ -11,7 +10,7 @@ import Footer from "../components/Footer.astro";
const { pageTitle } = Astro.props;
---
<html lang={astroI18n.langCode} dir="ltr">
<html lang={locale} dir="ltr">
<Head pageTitle={pageTitle} />
<body>
<div class="wrapper">

View file

@ -1,33 +1,27 @@
---
import { l, t, astroI18n } from "astro-i18n";
// import AstroImage from "../components/AstroImage.astro";
import BaseLayout from "../layouts/BaseLayout.astro";
import BaseLayout from '../layouts/BaseLayout.astro'
import { getLangFromUrl, useTranslations } from '../utils/i18n'
const { frontmatter, image, title } = Astro.props;
const publishedDate = new Date(frontmatter.pubDate);
const localizedDate = new Intl.DateTimeFormat(astroI18n.langCode, {
dateStyle: "long",
}).format(publishedDate);
const locale = getLangFromUrl(Astro.url)
const t = useTranslations(locale)
const { frontmatter, image, title } = Astro.props
const publishedDate = new Date(frontmatter.pubDate)
const localizedDate = new Intl.DateTimeFormat(locale, {
dateStyle: 'long'
}).format(publishedDate)
---
<BaseLayout pageTitle={title}>
<p>
Publié le&nbsp;: <time datetime={frontmatter.pubDate}>
{t('article.published')}&nbsp;: <time datetime={frontmatter.pubDate}>
{localizedDate}.
</time>
</p>
<p>
{
t("article.published", {
datetime: frontmatter.pubDate,
options: { dateStyle: "long" },
})
}
</p>
<div class="tags">
<div class='tags'>
{
frontmatter.tags.map((tag) => (
<p class="tag">
<p class='tag'>
<a href={l(`/tags/${[tag]}`)}>{tag}</a>
</p>
))