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

Changes#44 #80

Merged
merged 8 commits into from
Dec 1, 2023
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
6 changes: 6 additions & 0 deletions .changeset/curvy-sheep-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
---

Consistently emit fallback routes in the correct folders, and emit routes that
consider `trailingSlash`
26 changes: 26 additions & 0 deletions .changeset/fluffy-dolls-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'astro': minor
---

Adds a new way to configure the `i18n.locales` array.

Developers can now assign a custom URL path prefix that can span multiple language codes:

```js
// astro.config.mjs
export default defineConfig({
experimental: {
i18n: {
defaultLocale: "english",
locales: [
"de",
{ path: "english", codes: ["en", "en-US"]},
"fr",
],
routingStrategy: "prefix-always"
}
}
})
```

With the above configuration, the URL prefix of the default locale will be `/english/`. When computing `Astro.preferredLocale`, Astro will use the `codes`.
5 changes: 5 additions & 0 deletions .changeset/gold-grapes-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': minor
---

Reworks Vite's logger to use Astro's logger to correctly log HMR messages
5 changes: 5 additions & 0 deletions .changeset/grumpy-turtles-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Improve highlight/tooltip positioning when in fixed positions
5 changes: 5 additions & 0 deletions .changeset/tasty-parents-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Adds instructions on how to hide the dev overlay
65 changes: 41 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,51 @@
"pnpm": ">=8.6.12"
},
"packageManager": "[email protected]",
"dependencies": {
"astro-benchmark": "workspace:*"
},
"devDependencies": {
"@astrojs/check": "^0.3.1",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@types/node": "^18.17.8",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"esbuild": "^0.19.6",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^5.0.0",
"only-allow": "^1.1.1",
"organize-imports-cli": "^0.10.0",
"prettier": "^3.1.0",
"prettier-plugin-astro": "^0.12.2",
"tiny-glob": "^0.2.9",
"turbo": "^1.10.12",
"typescript": "~5.2.2"
},
"pnpm": {
"packageExtensions": {
"vite-svg-loader": {
"peerDependenciesMeta": {
"vue": {
"optional": true
}
}
},
"svelte2tsx": {
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
}
},
"rehype-pretty-code": {
"peerDependenciesMeta": {
"shiki": {
"optional": true
}
}
}
},
"overrides": {
Expand All @@ -66,34 +103,14 @@
"vite",
"react",
"react-dom",
"@types/react"
"@types/react",
"tslib",
"quill-delta",
"rxjs"
],
"allowAny": [
"astro"
]
}
},
"dependencies": {
"astro-benchmark": "workspace:*"
},
"devDependencies": {
"@astrojs/check": "^0.3.1",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@types/node": "^18.17.8",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"esbuild": "^0.19.6",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^5.0.0",
"only-allow": "^1.1.1",
"organize-imports-cli": "^0.10.0",
"prettier": "^3.1.0",
"prettier-plugin-astro": "^0.12.2",
"tiny-glob": "^0.2.9",
"turbo": "^1.10.12",
"typescript": "~5.2.2"
}
}
63 changes: 63 additions & 0 deletions packages/astro/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,69 @@ declare module 'astro:i18n' {
* Works like `getAbsoluteLocaleUrl` but it emits the absolute URLs for ALL locales:
*/
export const getAbsoluteLocaleUrlList: (path?: string, options?: GetLocaleOptions) => string[];

/**
* A function that return the `path` associated to a locale (defined as code). It's particularly useful in case you decide
* to use locales that are broken down in paths and codes.
*
* @param {string} code The code of the locale
* @returns {string} The path associated to the locale
*
* ## Example
*
* ```js
* // astro.config.mjs
*
* export default defineConfig({
* i18n: {
* locales: [
* { codes: ["it", "it-VT"], path: "italiano" },
* "es"
* ]
* }
* })
* ```
*
* ```js
* import { getPathByLocale } from "astro:i18n";
* getPathByLocale("it"); // returns "italiano"
* getPathByLocale("it-VT"); // returns "italiano"
* getPathByLocale("es"); // returns "es"
* ```
*/
export const getPathByLocale: (code: string) => string;

/**
* A function that returns the preferred locale given a certain path. This is particularly useful if you configure a locale using
* `path` and `codes`. When you define multiple `code`, this function will return the first code of the array.
*
* Astro will treat the first code as the one that the user prefers.
*
* @param {string} path The path that maps to a locale
* @returns {string} The path associated to the locale
*
* ## Example
*
* ```js
* // astro.config.mjs
*
* export default defineConfig({
* i18n: {
* locales: [
* { codes: ["it-VT", "it"], path: "italiano" },
* "es"
* ]
* }
* })
* ```
*
* ```js
* import { getLocaleByPath } from "astro:i18n";
* getLocaleByPath("italiano"); // returns "it-VT" because that's the first code configured
* getLocaleByPath("es"); // returns "es"
* ```
*/
export const getLocaleByPath: (path: string) => string;
}

declare module 'astro:middleware' {
Expand Down
12 changes: 8 additions & 4 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1438,15 +1438,17 @@ export interface AstroUserConfig {
* @docs
* @kind h4
* @name experimental.i18n.locales
* @type {string[]}
* @type {Locales}
* @version 3.5.0
* @description
*
* A list of all locales supported by the website (e.g. `['en', 'es', 'pt-br']`). This list should also include the `defaultLocale`. This is a required field.
* A list of all locales supported by the website, including the `defaultLocale`. This is a required field.
*
* No particular language format or syntax is enforced, but your folder structure must match exactly the locales in the list.
* Languages can be listed either as individual codes (e.g. `['en', 'es', 'pt-br']`) or mapped to a shared `path` of codes (e.g. `{ path: "english", codes: ["en", "en-US"]}`). These codes will be used to determine the URL structure of your deployed site.
*
* No particular language code format or syntax is enforced, but your project folders containing your content files must match exactly the `locales` items in the list. In the case of multiple `codes` pointing to a custom URL path prefix, store your content files in a folder with the same name as the `path` configured.
*/
locales: string[];
locales: Locales;

/**
* @docs
Expand Down Expand Up @@ -2026,6 +2028,8 @@ export interface AstroInternationalizationFeature {
detectBrowserLanguage?: SupportsKind;
}

export type Locales = (string | { codes: string[]; path: string })[];

export interface AstroAdapter {
name: string;
serverEntrypoint?: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/core/app/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
Locales,
RouteData,
SerializedRouteData,
SSRComponentMetadata,
Expand Down Expand Up @@ -56,7 +57,7 @@ export type SSRManifest = {
export type SSRManifestI18n = {
fallback?: Record<string, string>;
routing?: 'prefix-always' | 'prefix-other-locales';
locales: string[];
locales: Locales;
defaultLocale: string;
};

Expand Down
Loading
Loading