Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-language test #2

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ export default defineConfig({
rehypePlugins: [responsiveTablesRehypePlugin],
},

i18n: {
defaultLocale: 'fr',
locales: ['fr', 'en'],
routing: {
prefixDefaultLocale: true,
},
},

vite: {
resolve: {
alias: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@ import Pagination from '~/components/blog/Pagination.astro';

import dataProvider from '~/config/dataProvider';

export const getStaticPaths = (async ({ paginate }) => {
export const getStaticPaths = async ({ paginate }) => {
const allLocales = ['fr', 'en'];
const { data } = await dataProvider.getList('BlogPost');
return paginate(data, {
pageSize: 8,
return allLocales.flatMap((locale) => {
const dataByLocale = data.filter((post) => locale === 'fr');
return paginate(dataByLocale, {
params: { locale },
pageSize: 8,
});
});
}) satisfies GetStaticPaths;
}; /*satisfies GetStaticPaths*/

type Props = InferGetStaticPropsType<typeof getStaticPaths>;
// type Props = InferGetStaticPropsType<typeof getStaticPaths>;

const { page } = Astro.props as Props;
const { page } = Astro.props; /*as Props*/

const metadata = {
title: 'The Blog',
};

---

<Layout metadata={metadata}>
<section class="px-6 sm:px-6 py-12 sm:py-16 lg:py-20 mx-auto max-w-4xl">
<Headline
subtitle="Les dernières actualités de l'Assemblée Virtuelle et des projets qu'elle porte"
>
<Headline subtitle="Les dernières actualités de l'Assemblée Virtuelle et des projets qu'elle porte">
Le Blog de l'AV
</Headline>
<BlogList posts={page.data} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
import Layout from '~/layouts/PageLayout.astro';
import SinglePost from '~/components/blog/SinglePost.astro';
import ToBlogLink from '~/components/blog/ToBlogLink.astro';
import dataProvider from '../../config/dataProvider';
import dataProvider from '~/config/dataProvider';

export const prerender = true;

export async function getStaticPaths() {
const { data: posts } = await dataProvider.getList('BlogPost');
return posts.map((post) => ({
params: { slug: post.id },
props: post,
}));
const { data: posts } = await dataProvider.getList('BlogPost');
return posts.map((post) => ({
params: { slug: post.id },
props: post,
}));
}

const post = Astro.props;

const metadata = {
title: post['pair:label'],
description: post['pair:comment']
}

title: post['pair:label'],
description: post['pair:comment'],
};
---

<Layout metadata={metadata}>
Expand Down
6 changes: 6 additions & 0 deletions src/pages/pricing.astro → src/pages/[locale]/pricing.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import Steps from '~/components/widgets/Steps.astro';
import Features3 from '~/components/widgets/Features3.astro';
import CallToAction from '~/components/widgets/CallToAction.astro';

export async function getStaticPaths() {
return [{ params: { locale: 'en' } }, { params: { locale: 'fr' } }];
}

const metadata = {
title: 'Pricing',
};

const { locale } = Astro.params;
---

<Layout metadata={metadata}>
Expand Down