language fix
All checks were successful
Rebuild signaller for deprived.dev to rebuild site / Rebuild Signaller (push) Successful in 25s
All checks were successful
Rebuild signaller for deprived.dev to rebuild site / Rebuild Signaller (push) Successful in 25s
This commit is contained in:
parent
71f59696fc
commit
72e3eb92ba
1 changed files with 34 additions and 9 deletions
|
|
@ -32,20 +32,36 @@
|
||||||
|
|
||||||
// Print detection setup
|
// Print detection setup
|
||||||
import onMount from "@e/onMount";
|
import onMount from "@e/onMount";
|
||||||
|
import { goto } from "$app/navigation";
|
||||||
let debug = false;
|
let debug = false;
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
// Check if the query parameter exists in the URL
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const hideOnPrintParam = urlParams.get("hideOnPrint");
|
let needsUrlUpdate = false;
|
||||||
const locale = urlParams.get("locale");
|
|
||||||
|
|
||||||
// If the query parameter is not detected, reload the page with the parameter added
|
// 1. Safely handle hideOnPrint without reloading
|
||||||
if (!hideOnPrintParam) {
|
if (!urlParams.has("hideOnPrint")) {
|
||||||
window.location.href = `${window.location.href}${window.location.href.indexOf("?") > 0 ? "&" : "?"}hideOnPrint=1`;
|
urlParams.set("hideOnPrint", "1");
|
||||||
|
needsUrlUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locale && locale != getLocale()) {
|
// 2. Check for locale in URL, fallback to localStorage
|
||||||
setLocale(locale);
|
const urlLocale = urlParams.get("locale");
|
||||||
|
const savedLocale = localStorage.getItem("cv_locale");
|
||||||
|
|
||||||
|
const targetLocale = urlLocale || savedLocale;
|
||||||
|
|
||||||
|
if (targetLocale && targetLocale !== getLocale()) {
|
||||||
|
setLocale(targetLocale as any); // Update Paraglide
|
||||||
|
if (!urlLocale) {
|
||||||
|
urlParams.set("locale", targetLocale);
|
||||||
|
needsUrlUpdate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Update the URL silently if we changed anything
|
||||||
|
if (needsUrlUpdate) {
|
||||||
|
const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
|
||||||
|
window.history.replaceState({}, "", newUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
|
@ -54,6 +70,14 @@
|
||||||
loadMotivation();
|
loadMotivation();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function changeLanguage(tag: string) {
|
||||||
|
setLocale(tag as any);
|
||||||
|
localStorage.setItem("cv_locale", tag);
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
url.searchParams.set("locale", tag);
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
let motivationInput: HTMLTextAreaElement;
|
let motivationInput: HTMLTextAreaElement;
|
||||||
let motivation: string | null = "";
|
let motivation: string | null = "";
|
||||||
function loadMotivation() {
|
function loadMotivation() {
|
||||||
|
|
@ -115,7 +139,8 @@
|
||||||
? 'btn-filled btn-primary text-primary-content'
|
? 'btn-filled btn-primary text-primary-content'
|
||||||
: 'btn-outline'}"
|
: 'btn-outline'}"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
setLocale(tag);
|
changeLanguage(tag);
|
||||||
|
// window.location.reload();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{tag.toUpperCase()}
|
{tag.toUpperCase()}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue