From 46ad5aa597e568f4eec2856109febe08f27d6199 Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Tue, 5 Nov 2024 15:51:26 -0500 Subject: [PATCH 1/2] Set language via localStorage if set --- src/config/config.js | 1 + src/hooks.server.ts | 2 +- src/langs/i18n.js | 1 + src/langs/json/it.json | 6 +++--- .../components/navigation/LanguageMenu.svelte | 19 ++++++++++--------- src/routes/+layout.ts | 4 +++- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/config/config.js b/src/config/config.js index 040027a9a..b6e6795fe 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -44,6 +44,7 @@ export const LANGUAGES = [ ["Deutsche", "de", "๐Ÿ‡ฉ๐Ÿ‡ช"], ["ัƒะบั€ะฐั—ะฝััŒะบะฐ", "uk", "๐Ÿ‡บ๐Ÿ‡ฆ"], ["ั€ัƒััะบะธะน", "ru", "๐Ÿ‡ท๐Ÿ‡บ"], + ["Italiano", "it", "๐Ÿ‡ฎ๐Ÿ‡น"], ]; export const CSRF_COOKIE_NAME = "csrftoken"; diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 6c3e4982d..2108c89ca 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -22,7 +22,7 @@ export async function handleFetch({ event, request, fetch }) { if (request.url.startsWith(DC_BASE)) { // handle docker issues event.url.protocol = "https"; - request.headers.set("cookie", event.request.headers.get("cookie")); + request.headers.set("cookie", event.request.headers.get("cookie") ?? ""); } return fetch(request); diff --git a/src/langs/i18n.js b/src/langs/i18n.js index 49ac1c45d..d862ad546 100644 --- a/src/langs/i18n.js +++ b/src/langs/i18n.js @@ -13,6 +13,7 @@ for (let i = 0; i < langs.length; i++) { const lang = langs[i][1]; register(lang, () => import(`../langs/json/${lang}.json`)); langDict[lang] = true; + console.log(lang); } function resolveLocale(locale) { diff --git a/src/langs/json/it.json b/src/langs/json/it.json index 2e4758885..46b4346b2 100644 --- a/src/langs/json/it.json +++ b/src/langs/json/it.json @@ -497,7 +497,7 @@ "matchingNotes": "{n, plural, one {# note} other {# notes}} corrisponde all'espressione di ricerca", "page": "Pagine", "pageAbbrev": "p.", - "pageCount": "Signed in as {name}.", + "pageCount": "{n, plural, one {# pagina} other {# pagine}}", "select": "Scegliere", "noteCount": "{n, plural, uno {# note} altri {# notes}}" }, @@ -981,7 +981,7 @@ "none": "Non sono selezionati documenti. Chiudi questo form e seleziona almeno un documento prima." }, "data": { - "title": "{Edit} tagi e dati", + "title": "Modifica tag e dati", "key": "Chiave", "newkey": "Nuovo articolo", "value": "Valore", @@ -997,7 +997,7 @@ "title": "Modifica", "actions": { "edit": "Accesso e metadati", - "data": "{Add tags and data}", + "data": "Aggiungi tag e dati", "reprocess": "Riproposizione", "delete": "Cancella documenti", "project": "Aggiungi al progetto" diff --git a/src/lib/components/navigation/LanguageMenu.svelte b/src/lib/components/navigation/LanguageMenu.svelte index da82c6247..49cc074c9 100644 --- a/src/lib/components/navigation/LanguageMenu.svelte +++ b/src/lib/components/navigation/LanguageMenu.svelte @@ -4,18 +4,19 @@ import Dropdown, { type Placement, - } from "@/lib/components/common/Dropdown.svelte"; - import Menu from "@/lib/components/common/Menu.svelte"; + } from "$lib/components/common/Dropdown.svelte"; + import Flex from "../common/Flex.svelte"; + import Menu from "$lib/components/common/Menu.svelte"; import SidebarItem from "$lib/components/sidebar/SidebarItem.svelte"; - import langs from "@/langs/langs.json"; - import Flex from "../common/Flex.svelte"; + import { LANGUAGES } from "@/config/config.js"; export let position: Placement = "bottom-end"; - $: currentLang = langs.find(([_, code]) => code == $locale) ?? langs[0]; + $: currentLang = + LANGUAGES.find(([_, code]) => code === $locale) ?? LANGUAGES[0]; - function updateLanguage(code) { + function updateLanguage(code: string) { $locale = code; try { localStorage.setItem("dc-locale", code); @@ -23,7 +24,7 @@ } -{#if langs.length > 1} +{#if LANGUAGES.length > 1} @@ -38,10 +39,10 @@ - {#each langs as [name, code, flag]} + {#each LANGUAGES as [name, code, flag]} { - updateLanguage(code); + updateLanguage(code ?? ""); close(); }} hover diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index b0f6052f4..8d3ab4c84 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -7,7 +7,9 @@ export const trailingSlash = "always"; export async function load() { if (browser) { - locale.set(window.navigator.language); + const language = + localStorage.getItem("dc-locale") || window.navigator.language; + locale.set(language); } await waitLocale(); } From a845ace94fc88202729ce6a3568eb30545c727ac Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Tue, 5 Nov 2024 16:18:46 -0500 Subject: [PATCH 2/2] remove logging --- src/langs/i18n.js | 1 - src/lib/components/viewer/ViewerContext.svelte | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/langs/i18n.js b/src/langs/i18n.js index d862ad546..49ac1c45d 100644 --- a/src/langs/i18n.js +++ b/src/langs/i18n.js @@ -13,7 +13,6 @@ for (let i = 0; i < langs.length; i++) { const lang = langs[i][1]; register(lang, () => import(`../langs/json/${lang}.json`)); langDict[lang] = true; - console.log(lang); } function resolveLocale(locale) { diff --git a/src/lib/components/viewer/ViewerContext.svelte b/src/lib/components/viewer/ViewerContext.svelte index 69a94eabe..139dd82a0 100644 --- a/src/lib/components/viewer/ViewerContext.svelte +++ b/src/lib/components/viewer/ViewerContext.svelte @@ -181,7 +181,7 @@ layouts, stories, and tests. $progress = p; }; - task.promise.then(console.log).catch((error) => { + task.promise.catch((error) => { console.error(error); $currentErrors = [...$currentErrors, error]; throw error;