Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions app/app/src/components/LocalesPicker/LocalesPicker.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
import { getRelativeLocaleUrl } from 'astro:i18n'

export interface Props
{
lang?: string | undefined
}

const {
lang = Astro.currentLocale,
} = Astro.props
---

<ul class="lang-list">
<li>
<a
href={getRelativeLocaleUrl('fr', Astro.url.pathname)}
class:list={[ lang === 'fr' && 'active' ]}
>
<span class="icon icon-[twemoji--flag-france] icon-align"></span>
</a>
</li>
<li>
<a
href={getRelativeLocaleUrl('en', Astro.url.pathname)}
class:list={[ lang === 'en' && 'active' ]}
>
<span class="icon icon-[twemoji--flag-united-kingdom] icon-align"></span>
</a>
</li>
</ul>

<style lang="scss">
@reference "tailwindcss/theme";

.lang-list {
@apply flex items-center mb-4 gap-2;

.icon {
@apply text-2xl;
}

a {
@apply opacity-50;

&:hover {
@apply opacity-75;
}

&:active, &.active {
@apply opacity-100;
}
}
}
</style>
26 changes: 26 additions & 0 deletions app/app/src/components/LocalesPicker/LocalesPicker.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { experimental_AstroContainer as AstroContainer } from 'astro/container'
import { expect, test } from 'vitest'
import LocalesPicker from './LocalesPicker.astro'

test('LocalesPicker with defaults', async () =>
{
const container = await AstroContainer.create()
const result = await container.renderToString(LocalesPicker)

expect(result).toBeTruthy()
expect(result).not.toContain('active')
})

test('LocalesPicker with FR language', async () =>
{
const container = await AstroContainer.create()
const result = await container.renderToString(LocalesPicker, {
props: {
lang: 'fr',
}
})

expect(result).toBeTruthy()
expect(result).toContain('active')
expect(result).toMatch(/<a href="\/fr"[^>]+class="active"[^>]*>/)
})
5 changes: 0 additions & 5 deletions app/app/src/pages/en/index.astro

This file was deleted.

3 changes: 3 additions & 0 deletions app/app/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import { getCollection } from 'astro:content'
import LocalesPicker from '~/components/LocalesPicker/LocalesPicker.astro'
import Layout from '~/layouts/Layout.astro'

import logosrc from '~/assets/logo.png?url'
Expand Down Expand Up @@ -37,6 +38,8 @@ function getTitleFromBody(body: string | undefined): string | undefined

<div class="main">

<LocalesPicker lang={Astro.currentLocale} />

<p>
<span class="icon icon-[mdi--hand-wave] icon-align icon-fw"></span>
{_({
Expand Down
Loading