1
0
Fork 0

Fix Astro Cookies for fallback

This commit is contained in:
Korbs 2024-06-21 21:34:31 -04:00
parent cdacf37c4a
commit 8da3c92291
No known key found for this signature in database

View file

@ -3,7 +3,14 @@
import i18next, { t } from "i18next"; import i18next, { t } from "i18next";
import { Trans, HeadHrefLangs } from "astro-i18next/components"; import { Trans, HeadHrefLangs } from "astro-i18next/components";
if (Astro.cookies.get("Language").value === undefined) {Astro.cookies.set("Language", "EN", {path: "/",sameSite: 'strict'})} // Cookies
/// Language
//// If the user is new to the site, set English as default
if (Astro.cookies.get("Language") === undefined) {
Astro.cookies.set("Language", "EN", {path: "/",sameSite: 'strict'})
}
//// Check what language the user has set it to and switch to it
var UserLanguage = Astro.cookies.get("Language").value var UserLanguage = Astro.cookies.get("Language").value
if (UserLanguage === "JP") {i18next.changeLanguage("jp")} if (UserLanguage === "JP") {i18next.changeLanguage("jp")}
else if (UserLanguage === "EN") {i18next.changeLanguage("en")} else if (UserLanguage === "EN") {i18next.changeLanguage("en")}
@ -13,11 +20,16 @@ const {
Title, Title,
Description Description
} = Astro.props } = Astro.props
// Components
import { ViewTransitions } from 'astro:transitions';
import { fade } from "astro/virtual-modules/transitions.js";
--- ---
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<ViewTransitions transition:animate={fade} />
<title>{Title}</title> <title>{Title}</title>
<link href=/favicon.ico rel=icon> <link href=/favicon.ico rel=icon>
<link rel="manifest" href="/manifest.json"> <link rel="manifest" href="/manifest.json">