Skip to content

Commit

Permalink
rfc: i18n routing domain support
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Dec 21, 2023
1 parent 84bc61c commit 9488aab
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions proposals/0046-i18n-domain-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
- Start Date: 2023/12/21
- Reference Issues:
- Implementation PR: https://github.com/withastro/docs/pull/5469


# Summary

First-class support for domain support in i18n routing.


# Background & Motivation

Websites that support internationalisation have different requirements. Among these requirements, there's the need to
have localised content under different subdomains or domains.

# Goals

- Support different domains, all driven by the same Astro project;
- Mix locales that require a different domain, with locales that don't require a different domain;

# Non-Goals

- Force a redirect to users
- Change website/domain based on the language of the user's browser


# Detailed Design


A feature that allows to support different domains for certain locales.

Using the configuration `domains`, a user can specify which locales should benefit from a domain. This feature changes the behaviour of some of the APIs exported by the virtual module `astro:i18n`.

```js
// astro.config.mjs
import {defineConfig} from "astro/config"
export default defineConfig({
i18n: {
defaultLocaLe: 'en',
locales: ['en', 'es', 'pt_BR', 'pt', 'fr'],
domains: {
fr: "https://fr.example.com",
pt: "https://example.pt"
},
routingStrategy: "domain"
}
})
```

The following APIs will behave as follows:
- [`getRelativeLocaleUrl`](#getrelativelocaleurllocale-string-string): it won't prefix the locale to the URL. From `/en` to `/`;
- [`getAbsoluteLocaleUrl`](#getabsolutelocaleurllocale-string-string): it won't have the locale in the URL: From `example.com/fr` to `fr.example.com/`;

Adapters must have the capabilities to redirect a user from one domain to another based on the domains configured.

An adapter can signal Astro the feature support using the relative configuration:

In order to support this feature, Astro needs to know the origin of the server (the domain where the server is hosted). To achieve this, Astro will rely on the following headers:
- [`X-Forwarded-Host`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host) and [`Host`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host). Astro will use the former, and if not present will try the latter.
- [`X-Forwarded-Proto`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto) and [`URL#protocol`](https://developer.mozilla.org/en-US/docs/Web/API/URL/protocol) of the server request.

If any of this information is missing, Astro won't be able to map the route. This will result in a 404.

0 comments on commit 9488aab

Please sign in to comment.