-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setting language route based on http request header now
- Loading branch information
Showing
5 changed files
with
41 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { defineConfig } from "astro/config"; | ||
|
||
import node from "@astrojs/node"; | ||
import react from "@astrojs/react"; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [react()], | ||
redirects: { | ||
"/legal": "/legal/privacy", | ||
}, | ||
integrations: [react()], | ||
redirects: { | ||
"/legal": "/legal/privacy", | ||
}, | ||
output: "server", | ||
adapter: node({ | ||
mode: "standalone", | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
--- | ||
const AVAILABLE_TRANSLATIONS = ["de", "en"]; | ||
const language = Astro.request.headers.get("accept-language"); | ||
// Split the language string into an array of languages | ||
const languages = language | ||
?.split(",") | ||
.map((lang) => lang.split(";")[0].trim().split("-")[0]); | ||
// Find the first language in the header that matches one of the available languages | ||
const pageLang = | ||
languages?.find((lang) => AVAILABLE_TRANSLATIONS.includes(lang)) || "en"; | ||
--- | ||
|
||
<meta http-equiv="refresh" content="0;url=/en" /> | ||
<meta http-equiv="refresh" content=`0;url=/${pageLang}` /> |