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

Working with markdown pages (.md) #185

Open
neo7-studio-web opened this issue Jan 11, 2024 · 4 comments
Open

Working with markdown pages (.md) #185

neo7-studio-web opened this issue Jan 11, 2024 · 4 comments

Comments

@neo7-studio-web
Copy link

If anyone is wondering how to translate pages as .md files, here is a solution (example with a privacy policy page) :

  • Create where you want the .md files, located in their respective language folders. E.g. :
    image
    (you can use any folder structure as long as the files have the same name and are located in their language folder.)
  • Create an astro page that will be the entry point (e.g. privacy-policy.astro)
  • In this page, make use of the Astro.glob function to retreive the .md page content :
---
import i18next, { t, changeLanguage } from "i18next";
import { localizePath } from "astro-i18next";
changeLanguage("fr");
const pages = await Astro.glob("../i18n/**/privacy-policy.md");
let Content;
for (const page of pages) {
    if (page.file.includes(`/${i18next.language}/`))
        Content = page.Content;
}
---
  • Now you can make use of the <Content /> into your .astro file
<Layout title={t("menu.policy")} pageUrl={localizePath("/mentions-legales")}>
	<Content />
</Layout>
@koppk001
Copy link

I don't get it, you didn't put the translations in the public folder?

@neo7-studio-web
Copy link
Author

I don't get it, you didn't put the translations in the public folder?

Nope. Why ?

@koppk001
Copy link

What are the json files in the i18n folder? Are they not translations?

@neo7-studio-web
Copy link
Author

Yes they are. My personal preference is to put files used as sources at build time in /src rather than in /public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants