From 5c7ef917a82ae8f020fea852082edb01d926d06d Mon Sep 17 00:00:00 2001 From: Hal Seki Date: Sat, 16 Dec 2023 18:12:18 +0900 Subject: [PATCH 1/5] add astro-i18n --- astro-i18n.config.ts | 14 +++++ package-lock.json | 12 ++++ package.json | 121 +++++++++++++++++++++------------------- src/i18n/common/en.json | 6 ++ src/middleware/index.ts | 9 +++ 5 files changed, 104 insertions(+), 58 deletions(-) create mode 100644 astro-i18n.config.ts create mode 100644 src/i18n/common/en.json create mode 100644 src/middleware/index.ts diff --git a/astro-i18n.config.ts b/astro-i18n.config.ts new file mode 100644 index 0000000..ca2829b --- /dev/null +++ b/astro-i18n.config.ts @@ -0,0 +1,14 @@ +import { defineAstroI18nConfig } from "astro-i18n" + +export default defineAstroI18nConfig({ + primaryLocale: "ja-JP", // default app locale + secondaryLocales: ['en'], // other supported locales + fallbackLocale: "ja-JP", // fallback locale (on missing translation) + trailingSlash: "never", // "never" or "always" + run: "client+server", // "client+server" or "server" + showPrimaryLocale: false, // "/en/about" vs "/about" + translationLoadingRules: [], // per page group loading + translationDirectory: {}, // translation directory names + translations: {}, // { [translation_group1]: { [locale1]: {}, ... } } + routes: {}, // { [secondary_locale1]: { about: "about-translated", ... } } +}) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 53ad283..fe317d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@astrojs/tailwind": "^5.0.2", "astro": "^3.6.4", "astro-auto-import": "^0.4.1", + "astro-i18n": "^2.1.18", "date-fns": "^2.30.0", "date-fns-tz": "^2.0.0", "disqus-react": "^1.1.5", @@ -2235,6 +2236,17 @@ "undici-types": "~5.26.4" } }, + "node_modules/astro-i18n": { + "version": "2.1.18", + "resolved": "https://registry.npmjs.org/astro-i18n/-/astro-i18n-2.1.18.tgz", + "integrity": "sha512-yuJnoZoPOhP62p4qBIPYqUuBX0qdQoaoxK7E96aQp2epQWhYQzwDbgOkf5qBTbxZlRvguVc0s3P+68wGQSTYXg==", + "bin": { + "astro-i18n": "dist/src/bin.cjs" + }, + "peerDependencies": { + "esbuild": "0.x" + } + }, "node_modules/astro/node_modules/@esbuild/android-arm": { "version": "0.18.20", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz", diff --git a/package.json b/package.json index cc37fff..46da7ca 100755 --- a/package.json +++ b/package.json @@ -1,60 +1,65 @@ { - "name": "astroplate", - "version": "2.5.0", - "description": "Astro and Tailwindcss boilerplate", - "author": "zeon.studio", - "license": "MIT", - "packageManager": "yarn@1.22.19", - "scripts": { - "dev": "yarn generate-json && astro dev", - "build": "yarn generate-json && astro build", - "preview": "astro preview", - "format": "prettier -w ./src", - "generate-json": "node scripts/jsonGenerator.js", - "remove-darkmode": "node scripts/removeDarkmode.js && yarn format" - }, - "dependencies": { - "@astrojs/mdx": "^1.1.5", - "@astrojs/react": "^3.0.6", - "@astrojs/rss": "^3.0.0", - "@astrojs/sitemap": "^3.0.3", - "@astrojs/tailwind": "^5.0.2", - "astro": "^3.6.4", - "astro-auto-import": "^0.4.1", - "date-fns": "^2.30.0", - "date-fns-tz": "^2.0.0", - "disqus-react": "^1.1.5", - "github-slugger": "^2.0.0", - "gray-matter": "^4.0.3", - "marked": "^11.0.0", - "prettier-plugin-astro": "^0.12.2", - "prettier-plugin-tailwindcss": "^0.5.7", - "prop-types": "^15.8.1", - "react": "^18.2.0", - "react-dom": "^18.2.0", - "react-icons": "^4.12.0", - "react-lite-youtube-embed": "^2.4.0", - "remark-collapse": "^0.1.2", - "remark-toc": "^9.0.0", - "sharp": "^0.33.0", - "swiper": "^11.0.5" - }, - "devDependencies": { - "@tailwindcss/forms": "^0.5.7", - "@tailwindcss/typography": "^0.5.10", - "@types/marked": "^5.0.2", - "@types/node": "20.10.2", - "@types/react": "18.2.41", - "@types/react-dom": "18.2.17", - "autoprefixer": "^10.4.16", - "eslint": "^8.55.0", - "postcss": "^8.4.32", - "prettier": "^3.1.0", - "prettier-plugin-astro": "^0.12.2", - "prettier-plugin-tailwindcss": "^0.5.7", - "sass": "^1.69.5", - "tailwindcss": "^3.3.5", - "tailwind-bootstrap-grid": "^5.1.0", - "typescript": "5.3.2" - } + "name": "astroplate", + "version": "2.5.0", + "description": "Astro and Tailwindcss boilerplate", + "author": "zeon.studio", + "license": "MIT", + "packageManager": "yarn@1.22.19", + "scripts": { + "dev": "yarn generate-json && astro dev", + "build": "yarn generate-json && astro build", + "preview": "astro preview", + "format": "prettier -w ./src", + "generate-json": "node scripts/jsonGenerator.js", + "remove-darkmode": "node scripts/removeDarkmode.js && yarn format", + "i18n:extract": "astro-i18n extract", + "i18n:generate:pages": "astro-i18n generate:pages --purge", + "i18n:generate:types": "astro-i18n generate:types", + "i18n:sync": "npm run i18n:generate:pages && npm run i18n:generate:types" + }, + "dependencies": { + "@astrojs/mdx": "^1.1.5", + "@astrojs/react": "^3.0.6", + "@astrojs/rss": "^3.0.0", + "@astrojs/sitemap": "^3.0.3", + "@astrojs/tailwind": "^5.0.2", + "astro": "^3.6.4", + "astro-auto-import": "^0.4.1", + "astro-i18n": "^2.1.18", + "date-fns": "^2.30.0", + "date-fns-tz": "^2.0.0", + "disqus-react": "^1.1.5", + "github-slugger": "^2.0.0", + "gray-matter": "^4.0.3", + "marked": "^11.0.0", + "prettier-plugin-astro": "^0.12.2", + "prettier-plugin-tailwindcss": "^0.5.7", + "prop-types": "^15.8.1", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-icons": "^4.12.0", + "react-lite-youtube-embed": "^2.4.0", + "remark-collapse": "^0.1.2", + "remark-toc": "^9.0.0", + "sharp": "^0.33.0", + "swiper": "^11.0.5" + }, + "devDependencies": { + "@tailwindcss/forms": "^0.5.7", + "@tailwindcss/typography": "^0.5.10", + "@types/marked": "^5.0.2", + "@types/node": "20.10.2", + "@types/react": "18.2.41", + "@types/react-dom": "18.2.17", + "autoprefixer": "^10.4.16", + "eslint": "^8.55.0", + "postcss": "^8.4.32", + "prettier": "^3.1.0", + "prettier-plugin-astro": "^0.12.2", + "prettier-plugin-tailwindcss": "^0.5.7", + "sass": "^1.69.5", + "tailwind-bootstrap-grid": "^5.1.0", + "tailwindcss": "^3.3.5", + "typescript": "5.3.2" + } } diff --git a/src/i18n/common/en.json b/src/i18n/common/en.json new file mode 100644 index 0000000..098ffde --- /dev/null +++ b/src/i18n/common/en.json @@ -0,0 +1,6 @@ +{ + "your_common": "translations here", + "they": { + "can": "be nested" + } +} diff --git a/src/middleware/index.ts b/src/middleware/index.ts new file mode 100644 index 0000000..3eb6e78 --- /dev/null +++ b/src/middleware/index.ts @@ -0,0 +1,9 @@ +import { sequence } from "astro/middleware" +import { useAstroI18n } from "astro-i18n" + +const astroI18n = useAstroI18n( + undefined /* config */, + undefined /* custom formatters */, +) + +export const onRequest = sequence(astroI18n) \ No newline at end of file From 22cd70ca24139ff1c21b71d0fce003d09ef18b1b Mon Sep 17 00:00:00 2001 From: Hal Seki Date: Sat, 16 Dec 2023 19:00:56 +0900 Subject: [PATCH 2/5] add language selector --- astro-i18n.config.ts | 4 +- src/content/homepage/-index-en.md | 34 ++++++ .../homepage/{-index.md => -index-ja.md} | 0 src/i18n/common/en.json | 6 +- src/i18n/common/ja.json | 6 + src/layouts/components/LanguageSwitcher.astro | 13 +++ src/layouts/components/pages/HomePage.astro | 107 ++++++++++++++++++ src/layouts/partials/Header.astro | 13 ++- src/pages/en/index.astro | 9 ++ src/pages/index.astro | 101 +---------------- 10 files changed, 188 insertions(+), 105 deletions(-) create mode 100755 src/content/homepage/-index-en.md rename src/content/homepage/{-index.md => -index-ja.md} (100%) create mode 100644 src/i18n/common/ja.json create mode 100644 src/layouts/components/LanguageSwitcher.astro create mode 100644 src/layouts/components/pages/HomePage.astro create mode 100755 src/pages/en/index.astro diff --git a/astro-i18n.config.ts b/astro-i18n.config.ts index ca2829b..2bac80a 100644 --- a/astro-i18n.config.ts +++ b/astro-i18n.config.ts @@ -1,9 +1,9 @@ import { defineAstroI18nConfig } from "astro-i18n" export default defineAstroI18nConfig({ - primaryLocale: "ja-JP", // default app locale + primaryLocale: "ja", // default app locale secondaryLocales: ['en'], // other supported locales - fallbackLocale: "ja-JP", // fallback locale (on missing translation) + fallbackLocale: "ja", // fallback locale (on missing translation) trailingSlash: "never", // "never" or "always" run: "client+server", // "client+server" or "server" showPrimaryLocale: false, // "/en/about" vs "/about" diff --git a/src/content/homepage/-index-en.md b/src/content/homepage/-index-en.md new file mode 100755 index 0000000..2bdc92e --- /dev/null +++ b/src/content/homepage/-index-en.md @@ -0,0 +1,34 @@ +--- +# Banner +banner: + title: "Dig DAO: web3 Research Community" + content: "社会の健全な発展に活用されるためのWeb3.0のエコシステムや整備すべき環境について議論・研究・実践し、公開していくことを目的に活動しています。" + image: "/images/banner.png" + button: + enable: false + label: "Get Started For Free" + link: "https://github.com/zeon-studio/astroplate" + +# Features +features: + - title: "Dig DAO とは" + image: "/images/digdao-photo.jpg" + content: "Dig DAO は、デジタル庁のWeb3.0 研究会 をきっかけに生まれたDAOで、web3 についての研究開発を行うコミュニティです。" + button: + enable: false + label: "Get Started Now" + link: "#" + + - title: "プロジェクト" + image: "/images/verifier.png" + content: "Dig DAO は、web3 の発展に関係する様々なリサーチや開発を行っています。" + bulletpoints: + - "DID/VC SBT プロジェクト" + - "DAO リサーチプロジェクト" + - "デジタル公共資本基金" + button: + enable: false + label: "Get Started Now" + link: "https://github.com/zeon-studio/astroplate" + +--- diff --git a/src/content/homepage/-index.md b/src/content/homepage/-index-ja.md similarity index 100% rename from src/content/homepage/-index.md rename to src/content/homepage/-index-ja.md diff --git a/src/i18n/common/en.json b/src/i18n/common/en.json index 098ffde..5f68857 100644 --- a/src/i18n/common/en.json +++ b/src/i18n/common/en.json @@ -1,6 +1,6 @@ { - "your_common": "translations here", + "your_common": "コモン", "they": { - "can": "be nested" + "can": "できる" } -} +} \ No newline at end of file diff --git a/src/i18n/common/ja.json b/src/i18n/common/ja.json new file mode 100644 index 0000000..098ffde --- /dev/null +++ b/src/i18n/common/ja.json @@ -0,0 +1,6 @@ +{ + "your_common": "translations here", + "they": { + "can": "be nested" + } +} diff --git a/src/layouts/components/LanguageSwitcher.astro b/src/layouts/components/LanguageSwitcher.astro new file mode 100644 index 0000000..323ff77 --- /dev/null +++ b/src/layouts/components/LanguageSwitcher.astro @@ -0,0 +1,13 @@ +--- +import { astroI18n } from "astro-i18n"; +--- + + diff --git a/src/layouts/components/pages/HomePage.astro b/src/layouts/components/pages/HomePage.astro new file mode 100644 index 0000000..4393e7f --- /dev/null +++ b/src/layouts/components/pages/HomePage.astro @@ -0,0 +1,107 @@ +--- +import { astroI18n, t } from "astro-i18n"; + +import { markdownify } from "@/lib/utils/textConverter"; +import CallToAction from "@/partials/CallToAction.astro"; +import Testimonial from "@/partials/Testimonial.astro"; +import type { Button, Feature } from "@/types"; +import { Image } from "astro:assets"; +import { getEntry } from "astro:content"; +import { FaCheck } from "react-icons/fa/index.js"; + +console.log(); + +interface Homepage { + banner: { + title: string; + content: string; + image: string; + button: Button; + }; + features: Feature[]; +} + +const homepage = await getEntry("homepage", `-index-${astroI18n.locale}`); + +const testimonial = await getEntry("sections", "testimonial"); +const call_to_action = await getEntry("sections", "call-to-action"); +const { banner, features }: Homepage = homepage!.data; +--- + + +
+
+
+
+

+

+ { + banner.button.enable && ( + + {banner.button.label} + + ) + } +

+ { + banner.image && ( +
+ banner image +
+ ) + } +
+
+
+ + + +{ + features.map((feature, index: number) => ( +
+
+
+
+ {feature.title} +
+
+

+

+

    + {feature.bulletpoints && + feature.bulletpoints.map((bullet: string) => ( +
  • + + +
  • + ))} +
+ {feature.button.enable && ( + + {feature.button.label} + + )} +

+
+
+
+ )) +} + + + + diff --git a/src/layouts/partials/Header.astro b/src/layouts/partials/Header.astro index 1f70aad..38c2d14 100755 --- a/src/layouts/partials/Header.astro +++ b/src/layouts/partials/Header.astro @@ -1,4 +1,6 @@ --- +import { astroI18n } from "astro-i18n"; +import LanguageSwitcher from "@/components/LanguageSwitcher.astro"; import Logo from "@/components/Logo.astro"; import ThemeSwitcher from "@/components/ThemeSwitcher.astro"; import config from "@/config/config.json"; @@ -20,6 +22,8 @@ export interface NavigationLink { const { main }: { main: NavigationLink[] } = menu; const { navigation_button, settings } = config; const { pathname } = Astro.url; +const langPrefix = + astroI18n.locale === astroI18n.primaryLocale ? "" : `/${astroI18n.locale}`; ---
@@ -74,7 +78,7 @@ const { pathname } = Astro.url; {menu.children?.map((child) => (