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

feat: support astro 5 #43

Merged
merged 1 commit into from
Dec 5, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/four-parrots-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrolicious/i18n": minor
---

Bumps peer dependencies to support Astro 5. In order to use the integration with Astro 4, you now need to use at least `4.14.0`
5 changes: 5 additions & 0 deletions .changeset/new-bugs-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrolicious/i18n": patch
---

Fixes an issue with type generation when a project does not have a `src/env.d.ts` file
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
> [!WARNING]
> This integration is unmaintained due to lack of time. It should mostly work but do not expect fixes or new features.

# @astrolicious/i18n

Yet another i18n integration for [Astro](https://astro.build/) with server and client utilities, type safety and translations built-in.
Expand Down
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@tailwindcss/forms": "^0.5.7",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"astro": "^4.7.0",
"astro": "^4.14.0",
"i18next": "^23.11.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@astrojs/starlight-tailwind": "^2.0.2",
"@astrojs/tailwind": "^5.1.0",
"@expressive-code/plugin-line-numbers": "^0.33.5",
"astro": "^4.7.0",
"astro": "^4.14.0",
"sharp": "^0.33.3",
"tailwind": "^4.0.0",
"tailwindcss": "^3.4.3",
Expand Down
12 changes: 11 additions & 1 deletion docs/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { defineCollection } from "astro:content";
import { docsSchema } from "@astrojs/starlight/schema";
import { z } from "astro/zod";

export const collections = {
docs: defineCollection({ schema: docsSchema() }),
docs: defineCollection({
schema: docsSchema({
extend: z.object({
// Add a default value to the built-in `banner` field.
banner: z.object({ content: z.string() }).default({
content: "This integration is unmaintained due to lack of time. It should mostly work but do not expect fixes or new features.",
}),
}),
}),
}),
};
2 changes: 1 addition & 1 deletion docs/src/content/docs/getting-started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Installation
import { Tabs, TabItem } from '@astrojs/starlight/components';

:::caution[Prerequisites]
- `astro` must be at least on version `4.12.0`
- `astro` must be at least on version `4.14.0` or `5.0.0`
- `tsconfig.json` `compilerOptions.strict` should be set to `true`. If you're using Astro tsconfig presets, use either `astro/tsconfigs/strict` or `astro/tsconfigs/strictest`
:::

Expand Down
4 changes: 3 additions & 1 deletion docs/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@

:root {
--sl-font-system-mono: 'JetBrains Mono Variable', monospace;
}
--sl-color-banner-bg: var(--sl-color-orange);
--sl-color-banner-text: #000;
}
3 changes: 3 additions & 0 deletions package/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
> [!WARNING]
> This integration is unmaintained due to lack of time. It should mostly work but do not expect fixes or new features.

# `@astrolicious/i18n`

This is yet another i18n integration for [Astro](https://astro.build/) with server and client utilities, type safety and translations built-in.
Expand Down
2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"type": "module",
"peerDependencies": {
"astro": "^4.12.0",
"astro": "^4.14.0 || ^5.0.0",
"i18next": "^23.0.0"
},
"dependencies": {
Expand Down
14 changes: 12 additions & 2 deletions package/src/i18next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { normalizePath } from "vite";
import type { Options } from "../options.js";
import { getNamespaces } from "./namespaces.js";
import { getResources } from "./resources.js";
import { injectTypes } from "./types.js";

const getPaths = (root: URL, options: Options) => {
const localesDir = normalizePath(
Expand Down Expand Up @@ -39,11 +38,22 @@ export const handleI18next = defineUtility("astro:config:setup")(
logger,
);
const resources = getResources(logger, options, paths.localesDir);
injectTypes(params, options, resources[options.defaultLocale] ?? {});
const dtsContent = `
type Resources = ${JSON.stringify(resources[options.defaultLocale] ?? {})}

declare module "i18next" {
interface CustomTypeOptions {
defaultNS: "${options.defaultNamespace}";
resources: Resources;
}
}
export {}
`;

return {
namespaces,
resources,
dtsContent,
};
},
);
25 changes: 0 additions & 25 deletions package/src/i18next/types.ts

This file was deleted.

28 changes: 20 additions & 8 deletions package/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { readFileSync } from "node:fs";
import {
addDts,
addIntegration,
addVirtualImports,
createResolver,
Expand All @@ -20,13 +19,21 @@ export const integration = defineIntegration({
setup({ options, name }) {
const { resolve } = createResolver(import.meta.url);

let dtsContent: string;
let i18nextDtsContent: string;

return {
hooks: {
"astro:config:setup": (params) => {
const { addMiddleware, logger, updateConfig } = params;

const { routes } = handleRouting(params, options);
const { namespaces, resources } = handleI18next(params, options);
const {
namespaces,
resources,
dtsContent: _dtsContent,
} = handleI18next(params, options);
i18nextDtsContent = _dtsContent;

addMiddleware({
entrypoint: resolve("../assets/middleware.ts"),
Expand All @@ -48,7 +55,7 @@ export const integration = defineIntegration({
locales: '"@@_LOCALES_@@"',
};

let dtsContent = virtualTypesStub
dtsContent = virtualTypesStub
.replace(typesPlaceholders.id, VIRTUAL_MODULE_ID)
.replace(
typesPlaceholders.locale,
Expand Down Expand Up @@ -98,11 +105,6 @@ export const integration = defineIntegration({
dtsContent += virtualSitemapTypesStub;
}

addDts(params, {
name: "astro-i18n",
content: dtsContent,
});

const enabledClientFeatures = Object.entries(options.client)
.map(([name, enabled]) => ({ name, enabled }))
.filter((e) => e.enabled);
Expand Down Expand Up @@ -197,6 +199,16 @@ export const integration = defineIntegration({
});
}
},
"astro:config:done": (params) => {
params.injectTypes({
filename: "astro-i18n.d.ts",
content: dtsContent,
});
params.injectTypes({
filename: "i18next.d.ts",
content: i18nextDtsContent,
});
},
},
};
},
Expand Down
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@astrolicious/i18n": "workspace:*",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"astro": "^4.12.0",
"astro": "^4.14.0",
"i18next": "^23.11.3",
"react": "^18.2.0",
"react-dom": "^18.3.1",
Expand Down
25 changes: 21 additions & 4 deletions pnpm-lock.yaml

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

Loading