Skip to content

Commit 91c4e3a

Browse files
authored
Enable spanish and fix mobile language selector (#3454)
* Enable spanish and fix mobile language selector. * Fix summary icons on Safari.
1 parent 4c5e725 commit 91c4e3a

File tree

6 files changed

+77
-6
lines changed

6 files changed

+77
-6
lines changed

src/frontend/src/lib/components/layout/Footer.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import type { HTMLAttributes } from "svelte/elements";
33
import { SOURCE_CODE_URL, SUPPORT_URL } from "$lib/config";
44
import { t } from "$lib/stores/locale.store";
5+
import Header from "$lib/components/layout/Header.svelte";
6+
import { LanguageSelector } from "$lib/components/locale";
7+
import LanguageSelectorFooter from "$lib/components/locale/LanguageSelectorFooter.svelte";
58
69
type Props = HTMLAttributes<HTMLElement>;
710
@@ -17,6 +20,7 @@
1720
>
1821
<div class="text-text-tertiary text-xs font-medium">© Internet Identity</div>
1922
<nav class="text-text-primary flex gap-4 text-xs font-semibold">
23+
<LanguageSelectorFooter />
2024
<a
2125
href={SUPPORT_URL}
2226
target="_blank"

src/frontend/src/lib/components/locale/LanguageSelector.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77
import Button from "$lib/components/ui/Button.svelte";
88
import Popover from "$lib/components/ui/Popover.svelte";
99
import { ChevronDownIcon } from "@lucide/svelte";
10+
import type { HTMLAttributes } from "svelte/elements";
11+
12+
const { class: className, ...props }: HTMLAttributes<HTMLElement> = $props();
1013
1114
let buttonRef = $state<HTMLElement>();
1215
let isOpen = $state(false);
1316
</script>
1417

1518
{#if $locales.length > 1}
1619
<Button
20+
{...props}
1721
bind:element={buttonRef}
1822
onclick={() => (isOpen = true)}
1923
variant="tertiary"
2024
class="uppercase"
2125
>
2226
{$localeStore}
23-
<ChevronDownIcon class="size-5" />
27+
<ChevronDownIcon class="size-4" />
2428
</Button>
2529
{/if}
2630
{#if isOpen}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<script lang="ts">
2+
import {
3+
availableBrowserLocale,
4+
locales,
5+
localeStore,
6+
} from "$lib/stores/locale.store";
7+
import Button from "$lib/components/ui/Button.svelte";
8+
import Popover from "$lib/components/ui/Popover.svelte";
9+
import { ChevronDownIcon } from "@lucide/svelte";
10+
import type { HTMLAttributes } from "svelte/elements";
11+
12+
let buttonRef = $state<HTMLElement>();
13+
let isOpen = $state(false);
14+
</script>
15+
16+
{#if $locales.length > 1}
17+
<button
18+
bind:this={buttonRef}
19+
onclick={() => (isOpen = true)}
20+
class="uppercase outline-0 focus-visible:underline"
21+
>
22+
{$localeStore}
23+
</button>
24+
{/if}
25+
{#if isOpen}
26+
<Popover
27+
anchor={buttonRef}
28+
onClose={() => (isOpen = false)}
29+
direction="up"
30+
align="start"
31+
distance="0.5rem"
32+
responsive={false}
33+
class="-ml-5 !w-18 !p-1.5"
34+
>
35+
<ul class="flex flex-col">
36+
{#each $locales as locale}
37+
<li class="contents">
38+
<Button
39+
onclick={() => {
40+
isOpen = false;
41+
// Switch back to locale auto-detection if locale matches browser
42+
if (locale === availableBrowserLocale) {
43+
localeStore.reset();
44+
} else {
45+
localeStore.set(locale);
46+
}
47+
}}
48+
variant="tertiary"
49+
size="sm"
50+
class={[
51+
"justify-start text-start uppercase",
52+
locale === $localeStore &&
53+
"[ul:not(:hover)_&]:bg-bg-primary_hover",
54+
]}
55+
>
56+
{locale}
57+
</Button>
58+
</li>
59+
{/each}
60+
</ul>
61+
</Popover>
62+
{/if}

src/frontend/src/lib/components/ui/Popover.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
popoverRef.style.left = {
6161
up: {
6262
start: `${anchorRect.left}px`,
63-
center: `${anchorRect.right + anchorRect.width * 0.5 - popoverRect.width * 0.5}px`,
63+
center: `${anchorRect.left + anchorRect.width * 0.5 - popoverRect.width * 0.5}px`,
6464
end: `${anchorRect.right - popoverRect.width}px`,
6565
}[align],
6666
right: `calc(${anchorRect.right}px + ${distance})`,

src/frontend/src/lib/constants/locale.constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
export const availableLocales = ["en", "de", "es", "id"];
33

44
// List of languages that are actually enabled
5-
export const enabledLocales = ["en"];
5+
export const enabledLocales = ["en", "es"];

src/frontend/src/routes/(new-styling)/+page.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
<div
7575
class="border-border-secondary flex w-full flex-1 flex-row items-center justify-center gap-5 border-y py-3 md:justify-end md:border-0"
7676
>
77-
<LanguageSelector />
77+
<!-- TODO: Re-position language selector for now on mobile till updated design is implemented -->
78+
<LanguageSelector class="max-md:absolute max-md:top-3 max-md:right-3" />
7879
<Button variant="secondary" href={II_DEVELOPER_DOCS_URL} target="_blank">
7980
{$t`For developers`}
8081
</Button>
@@ -205,8 +206,8 @@
205206
"[&_summary]:text-text-primary [&_summary]:cursor-pointer [&_summary]:font-medium [&_summary]:select-none md:[&_summary]:text-xl",
206207
// Summary icons
207208
"[&_summary_svg]:text-text-placeholder [&_summary_svg]:ml-auto [&_summary_svg]:size-6 [&_summary_svg]:shrink-0",
208-
// Toggle summary icons
209-
"[&_details:not(:open)_summary_svg:first-child]:hidden [&_details:open_summary_svg:last-child]:hidden",
209+
// Toggle summary icons, uses [open] instead of :open due to Safari not supporting the latter
210+
"[&_details:not([open])_summary_svg:first-child]:hidden [&_details[open]_summary_svg:last-child]:hidden",
210211
// Paragraph styling and spacing
211212
"[&_p]:text-text-secondary [&_p]:mb-4 [&_p]:text-base",
212213
// Paragraph + list spacing

0 commit comments

Comments
 (0)