Skip to content

Commit

Permalink
Merge pull request #814 from MuckRock/784-language
Browse files Browse the repository at this point in the history
Set language via localStorage if set
  • Loading branch information
eyeseast authored Nov 6, 2024
2 parents da7640c + a845ace commit 8e71a87
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const LANGUAGES = [
["Deutsche", "de", "🇩🇪"],
["українська", "uk", "🇺🇦"],
["русский", "ru", "🇷🇺"],
["Italiano", "it", "🇮🇹"],
];

export const CSRF_COOKIE_NAME = "csrftoken";
Expand Down
2 changes: 1 addition & 1 deletion src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/langs/json/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
},
Expand Down Expand Up @@ -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",
Expand All @@ -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"
Expand Down
19 changes: 10 additions & 9 deletions src/lib/components/navigation/LanguageMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@
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);
} catch (e) {}
}
</script>

{#if langs.length > 1}
{#if LANGUAGES.length > 1}
<!-- Language Menu -->
<Dropdown {position}>
<SidebarItem slot="anchor">
Expand All @@ -38,10 +39,10 @@
</div>
</SidebarItem>
<Menu slot="default" let:close>
{#each langs as [name, code, flag]}
{#each LANGUAGES as [name, code, flag]}
<SidebarItem
on:click={() => {
updateLanguage(code);
updateLanguage(code ?? "");
close();
}}
hover
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/viewer/ViewerContext.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 8e71a87

Please sign in to comment.