Skip to content

Commit

Permalink
feat(cli): add generate command to create localized astro pages
Browse files Browse the repository at this point in the history
- use yargs to build documented command
- use typescript compiler API to parse frontmatter & inject
locale change
- update dependencies to latest

closes #13
  • Loading branch information
yassinedoghri committed Aug 21, 2022
1 parent 6aee21d commit 17982cf
Show file tree
Hide file tree
Showing 18 changed files with 3,524 additions and 1,191 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ websites!

> **Status** [beta version]
>
> You can use it, and feedback is more than welcome! As integrations in Astro
> are still experimental, note that some breaking changes may still be
> You can use it, and feedback is more than welcome! As third-party integrations
> in Astro are still experimental, note that some breaking changes may still be
> introduced during this phase.
## Getting started
Expand Down
17 changes: 15 additions & 2 deletions build.js → build.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
require("esbuild")
.build({
bundle: true,
entryPoints: ["src/index.mts", "src/utils.ts", "src/components/index.mts"],
entryPoints: [
"src/index.mts",
"src/utils.ts",
"src/components/index.mts",
"src/cli/index.ts",
],
outdir: "dist",
outExtension: {
".js": ".mjs",
},
external: ["i18next", "locale-emoji"],
external: [
"i18next",
"locale-emoji",
"typescript",
"fdir",
"fs-extra",
"iso-639-1",
"iso-3166-1-alpha-2",
],
minify: false,
format: "esm",
platform: "node",
Expand Down
107 changes: 101 additions & 6 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "npm link .. && astro dev",
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"build:package": "cd .. && npm run build && cd example",
"preview": "astro preview"
"preview": "astro preview",
"i18n:generate": "astro-i18next generate -d en -l fr"
},
"devDependencies": {
"@astrojs/sitemap": "^0.3.0",
"@astrojs/tailwind": "^0.2.5",
"astro": "1.0.0-rc.7",
"astro-seo": "^0.5.1"
},
"dependencies": {
"@astrojs/sitemap": "^1.0.0",
"@astrojs/tailwind": "^1.0.0",
"astro": "^1.0.5",
"astro-i18next": "file:..",
"astro-seo": "^0.5.1",
"i18next-fs-backend": "^1.1.5"
}
}
24 changes: 0 additions & 24 deletions example/src/pages/[lang]/about.astro

This file was deleted.

24 changes: 0 additions & 24 deletions example/src/pages/[lang]/index.astro

This file was deleted.

24 changes: 20 additions & 4 deletions example/src/pages/about.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
---
import i18next from "i18next";
import About from "templates:About";
import { t, changeLanguage } from "i18next";
import { Trans } from "astro-i18next/components";
import BaseTemplate from "templates:BaseTemplate";
import Link from "atoms:Link";
i18next.changeLanguage(i18next.options.supportedLngs[0]);
changeLanguage("en");
---

<About />
<BaseTemplate>
<p class="mt-4 text-center text-xl max-w-xl">
<Trans i18nKey="about">
Created with love ❤️, cheese 🧀 and baguettes 🥖 during the <Link
href="https://hackathon-1-0-projects.vercel.app/"
title={t("astroHackathonTitle")}
>Astro hackathon
</Link> of April / May 2022 by <Link
href="https://twitter.com/yassinedoghri"
title={t("twitterTitle")}
>@yassinedoghri
</Link>.
</Trans>
</p>
</BaseTemplate>
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
---
import { t, changeLanguage } from "i18next";
import { Trans } from "astro-i18next/components";
import Link from "atoms:Link";
import { t } from "i18next";
import BaseTemplate from "templates:BaseTemplate";
import Link from "atoms:Link";
changeLanguage("fr");
---

<BaseTemplate>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
---
import Link from "atoms:Link";
import { t, changeLanguage } from "i18next";
import { Trans } from "astro-i18next/components";
import BaseTemplate from "templates:BaseTemplate";
import Link from "atoms:Link";
import { t } from "i18next";
changeLanguage("fr");
---

<BaseTemplate>
Expand Down
19 changes: 15 additions & 4 deletions example/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
---
import i18next from "i18next";
import Home from "templates:Home";
import Link from "atoms:Link";
import { t, changeLanguage } from "i18next";
import { Trans } from "astro-i18next/components";
import BaseTemplate from "templates:BaseTemplate";
i18next.changeLanguage(i18next.options.supportedLngs[0]);
changeLanguage("en");
---

<Home />
<BaseTemplate>
<p class="mt-4 text-center text-xl max-w-xl">
<Trans i18nKey="description">
An <Link href="https://astro.build" title={t("astroTitle")}>astro</Link> integration
of <Link href="https://www.i18next.com/" title={t("i18nextTitle")}
>i18next
</Link> and utility components to help you translate your astro websites!
</Trans>
</p>
</BaseTemplate>
Loading

0 comments on commit 17982cf

Please sign in to comment.