diff --git a/bun.lockb b/bun.lockb index e7dda1b..b3f56f2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 2aff2f1..ab9639d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "upgrade": "ncu", "script:download-payload-sdk": "bun run scripts/download-payload-sdk.ts", "script:download-currencies": "bun run scripts/download-currencies.ts", - "script:download-wording-keys": "bun run scripts/download-wording-keys.ts" + "script:download-wording-keys": "bun run scripts/download-wording-keys.ts", + "precommit": "bun run script:download-wording-keys && bun run script:download-payload-sdk && bun run astro check" }, "engines": { "npm": ">=10.0.0", @@ -27,8 +28,7 @@ "astro-icon": "^1.1.0", "node-cache": "^5.1.2", "tippy.js": "^6.3.7", - "ua-parser-js": "^1.0.37", - "zod": "^3.22.4" + "ua-parser-js": "^1.0.37" }, "devDependencies": { "@iconify-json/material-symbols": "^1.1.73", diff --git a/scripts/download-wording-keys.ts b/scripts/download-wording-keys.ts new file mode 100644 index 0000000..0212721 --- /dev/null +++ b/scripts/download-wording-keys.ts @@ -0,0 +1,19 @@ +import { writeFileSync } from "fs"; +import { payload } from "src/shared/payload/payload-sdk"; + +const TRANSLATION_FOLDER = `${process.cwd()}/src/i18n`; + +try { + const wordings = await payload.getWordings(); + const keys = wordings.map(({ name }) => name); + + let result = ""; + result += "export type WordingKey =\n"; + result += ` | "` + keys.join(`"\n | "`) + `";\n`; + + writeFileSync(`${TRANSLATION_FOLDER}/wordings-keys.ts`, result, { + encoding: "utf-8", + }); +} catch (e) { + console.error("Failed to get the sdk", e); +} diff --git a/src/components/AppLayout/components/Footer.astro b/src/components/AppLayout/components/Footer.astro index 0e2dac8..283d80c 100644 --- a/src/components/AppLayout/components/Footer.astro +++ b/src/components/AppLayout/components/Footer.astro @@ -1,6 +1,6 @@ --- import { Icon } from "astro-icon/components"; -import { getI18n } from "translations/translations"; +import { getI18n } from "src/i18n/i18n"; interface Props { withLinks: boolean; diff --git a/src/components/AppLayout/components/Topbar/Topbar.astro b/src/components/AppLayout/components/Topbar/Topbar.astro index 5c82c0c..74bafe4 100644 --- a/src/components/AppLayout/components/Topbar/Topbar.astro +++ b/src/components/AppLayout/components/Topbar/Topbar.astro @@ -4,9 +4,9 @@ import Button from "components/Button.astro"; import ThemeSelector from "./components/ThemeSelector.astro"; import LanguageSelector from "./components/LanguageSelector.astro"; import CurrencySelector from "./components/CurrencySelector.astro"; -import { getI18n } from "translations/translations"; import type { ParentPage } from "src/shared/payload/payload-sdk"; import ParentPagesButton from "./components/ParentPagesButton.astro"; +import { getI18n } from "src/i18n/i18n"; interface Props { parentPages?: ParentPage[] | undefined; diff --git a/src/components/AppLayout/components/Topbar/components/CurrencySelector.astro b/src/components/AppLayout/components/Topbar/components/CurrencySelector.astro index 44e67e9..88cd9bb 100644 --- a/src/components/AppLayout/components/Topbar/components/CurrencySelector.astro +++ b/src/components/AppLayout/components/Topbar/components/CurrencySelector.astro @@ -1,8 +1,8 @@ --- import Button from "components/Button.astro"; import Tooltip from "components/Tooltip.astro"; +import { getI18n } from "src/i18n/i18n"; import { cache } from "src/utils/cachedPayload"; -import { getI18n } from "translations/translations"; import { formatCurrency } from "src/utils/currencies"; interface Props { diff --git a/src/components/AppLayout/components/Topbar/components/LanguageSelector.astro b/src/components/AppLayout/components/Topbar/components/LanguageSelector.astro index 2e6fd2b..27a6330 100644 --- a/src/components/AppLayout/components/Topbar/components/LanguageSelector.astro +++ b/src/components/AppLayout/components/Topbar/components/LanguageSelector.astro @@ -1,8 +1,9 @@ --- import Button from "components/Button.astro"; import Tooltip from "components/Tooltip.astro"; +import { getI18n } from "src/i18n/i18n"; import { cache } from "src/utils/cachedPayload"; -import { getI18n } from "translations/translations"; +import { formatLocale } from "src/utils/format"; interface Props { withTitle?: boolean | undefined; @@ -12,7 +13,7 @@ interface Props { const { withTitle, class: className } = Astro.props; const { currentLocale } = Astro.locals; -const { t, formatLocale } = await getI18n(currentLocale); +const { t } = await getI18n(currentLocale); --- { diff --git a/src/components/AppLayout/components/Topbar/components/ParentPageLink.astro b/src/components/AppLayout/components/Topbar/components/ParentPageLink.astro index 95a5a3f..3a03726 100644 --- a/src/components/AppLayout/components/Topbar/components/ParentPageLink.astro +++ b/src/components/AppLayout/components/Topbar/components/ParentPageLink.astro @@ -1,6 +1,6 @@ --- +import { getI18n } from "src/i18n/i18n"; import { Collections, type ParentPage } from "src/shared/payload/payload-sdk"; -import { getI18n } from "translations/translations"; interface Props { parentPage: ParentPage; @@ -11,9 +11,7 @@ const { getLocalizedMatch, getLocalizedUrl } = await getI18n( Astro.locals.currentLocale ); -const translation = getLocalizedMatch(parentPage.translations, { - name: parentPage.slug, -}); +const translation = getLocalizedMatch(parentPage.translations); let href = ""; switch (parentPage.collection) { diff --git a/src/components/AppLayout/components/Topbar/components/ParentPagesButton.astro b/src/components/AppLayout/components/Topbar/components/ParentPagesButton.astro index dae4c82..2189d4b 100644 --- a/src/components/AppLayout/components/Topbar/components/ParentPagesButton.astro +++ b/src/components/AppLayout/components/Topbar/components/ParentPagesButton.astro @@ -3,7 +3,7 @@ import Tooltip from "components/Tooltip.astro"; import type { ParentPage } from "src/shared/payload/payload-sdk"; import ParentPageLink from "./ParentPageLink.astro"; import { Icon } from "astro-icon/components"; -import { getI18n } from "translations/translations"; +import { getI18n } from "src/i18n/i18n"; interface Props { parentPages: ParentPage[]; diff --git a/src/components/AppLayout/components/Topbar/components/ThemeSelector.astro b/src/components/AppLayout/components/Topbar/components/ThemeSelector.astro index 9854f90..a464747 100644 --- a/src/components/AppLayout/components/Topbar/components/ThemeSelector.astro +++ b/src/components/AppLayout/components/Topbar/components/ThemeSelector.astro @@ -1,7 +1,7 @@ --- import Button from "components/Button.astro"; import Tooltip from "components/Tooltip.astro"; -import { getI18n } from "translations/translations"; +import { getI18n } from "src/i18n/i18n"; const { currentLocale, currentTheme } = Astro.locals; const { t } = await getI18n(currentLocale); @@ -15,15 +15,15 @@ const { t } = await getI18n(currentLocale);
{t("header.topbar.theme.dark")}{t("global.theme.dark")} {t("header.topbar.theme.auto")}{t("global.theme.auto")} {t("header.topbar.theme.light")}{t("global.theme.light")}