aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/AppHeader.svelte4
-rw-r--r--src/components/LandingHeader.svelte26
-rw-r--r--src/components/LocaleSelector.svelte9
-rw-r--r--src/components/index.js1
-rw-r--r--src/lib/i18n.js43
-rw-r--r--src/locales/en.json8
-rw-r--r--src/locales/fr.json8
-rw-r--r--src/routes/__layout.svelte1
8 files changed, 88 insertions, 12 deletions
diff --git a/src/components/AppHeader.svelte b/src/components/AppHeader.svelte
index d0123650..242e6924 100644
--- a/src/components/AppHeader.svelte
+++ b/src/components/AppHeader.svelte
@@ -3,7 +3,7 @@
import { user } from '$lib/store';
import { goto } from '$app/navigation';
- import { Icon } from '$comp';
+ import { Icon, LocaleSelector } from '$comp';
export let avatarPosition = 'left-[calc(50vw-48px)]';
@@ -28,6 +28,7 @@
<header class="bg-gradient-to-r from-primary to-gradient h-[175px] w-full relative">
<nav class="flex justify-end items-center space-x-4 p-5">
+ <LocaleSelector />
{#if $user}
<a href={`/${$user.username}/receive`}>
<button class="bg-white p-2 rounded-full w-12 h-12"
@@ -71,6 +72,7 @@
<button class="bg-white px-5 py-2 rounded-xl font-semibold text-sm">Sign in </button>
</a>
{/if}
+>>>>>>> master
</nav>
<div
class="absolute top-[calc(175px-48px)] {avatarPosition} rounded-full border-4 border-white p-4 bg-gradient-to-r from-primary to-gradient w-24 h-24"
diff --git a/src/components/LandingHeader.svelte b/src/components/LandingHeader.svelte
index 65ea607c..352b200c 100644
--- a/src/components/LandingHeader.svelte
+++ b/src/components/LandingHeader.svelte
@@ -1,8 +1,9 @@
<script>
import { goto } from '$app/navigation';
import { scroll } from '$lib/utils';
- import { Icon } from '$comp';
+ import { Icon, LocaleSelector } from '$comp';
import { user } from '$lib/store';
+ import { _ } from 'svelte-i18n';
export let howItWorks;
export let faq;
@@ -24,20 +25,22 @@
</a>
<Icon icon="logo" style="block md:hidden ml-5 w-48" />
+ <LocaleSelector />
+
<!-- desktop nav -->
<div class="hidden space-x-10 md:flex flex-wrap justify-center items-center font-bold">
- <button on:click={() => scroll(howItWorks)}>How It Works</button>
- <button on:click={() => scroll(faq)}>FAQ</button>
- <button on:click={() => scroll(about)}>About</button>
+ <button on:click={() => scroll(howItWorks)}>{$_('howItWorks')}</button>
+ <button on:click={() => scroll(faq)}>{$_('FAQ')}</button>
+ <button on:click={() => scroll(about)}>{$_('about')}</button>
{#if !$user}
<button class="border rounded-full px-6 py-2 font-bold" on:click={() => goto('/register')}
- >Start in Seconds
+ >{$_('startInSeconds')}
</button>
<button
class="bg-black text-white border rounded-full px-6 py-2 font-bold"
on:click={() => goto('/login')}
>
- Sign in
+ {$_('signIn')}
</button>
{:else}
<button
@@ -68,21 +71,21 @@
>
<div class="space-y-8 mt-24 ml-10 font-bold text-xl">
<button on:click={() => mobileMenuButtonClick(howItWorks)} class="block"
- >How It Works</button
+ >{$_('howItWorks')}</button
>
- <button on:click={() => mobileMenuButtonClick(faq)} class="block">FAQ</button>
- <button on:click={() => mobileMenuButtonClick(about)} class="block">About</button>
+ <button on:click={() => mobileMenuButtonClick(faq)} class="block">{$_('FAQ')}</button>
+ <button on:click={() => mobileMenuButtonClick(about)} class="block">{$_('about')}</button>
{#if !$user}
<button
class="border rounded-full px-6 py-2 font-bold block"
on:click={() => goto('/register')}
- >Start in Seconds
+ >{$_('startInSeconds')}
</button>
<button
class="bg-black text-white border rounded-full px-6 py-2 font-bold block"
on:click={() => goto('/login')}
>
- Sign in
+ {$_('startInSeconds')}
</button>
{:else}
<button
@@ -98,6 +101,7 @@
</button>
{/if}
</div>
+>>>>>>> master
</div>
</nav>
</header>
diff --git a/src/components/LocaleSelector.svelte b/src/components/LocaleSelector.svelte
new file mode 100644
index 00000000..a3531ec5
--- /dev/null
+++ b/src/components/LocaleSelector.svelte
@@ -0,0 +1,9 @@
+<script>
+ import { _, locale, locales } from 'svelte-i18n';
+</script>
+
+<select bind:value={$locale}>
+ {#each $locales as locale}
+ <option value={locale}>{locale}</option>
+ {/each}
+</select>
diff --git a/src/components/index.js b/src/components/index.js
index dade4c2c..1d5b369d 100644
--- a/src/components/index.js
+++ b/src/components/index.js
@@ -7,6 +7,7 @@ export { default as Icon } from './Icon.svelte';
export { default as Image } from './Image.svelte';
export { default as RegisterOrLogin } from './RegisterOrLogin.svelte';
export { default as AppHeader } from './AppHeader.svelte';
+export { default as LocaleSelector } from './LocaleSelector.svelte';
export { default as LoadingSplash } from './LoadingSplash.svelte';
export { default as PageNotFound } from './404.svelte';
export { default as About } from './About.svelte';
diff --git a/src/lib/i18n.js b/src/lib/i18n.js
new file mode 100644
index 00000000..0600a2a8
--- /dev/null
+++ b/src/lib/i18n.js
@@ -0,0 +1,43 @@
+import { register, init, getLocaleFromNavigator } from 'svelte-i18n';
+
+// The list of locales to look for
+const localeCodes = ['en', 'fr'];
+
+// The directory where locale files are stored
+const localeDirectory = "../locales";
+
+// Adds a new locale based on its code
+function addLocale(localeCode) {
+ register(localeCode, () => import(`${localeDirectory}/${localeCode}.json`));
+}
+
+// Picks the default locale based on navigator locale and the list of available locales
+function pickLocale(navigatorLocale, availableLocales) {
+ // determine langugage part of locale
+ // (e.g. if navigatorLocale is 'en-US', languageCode is 'en')
+ let dashIndex = navigatorLocale ? navigatorLocale.indexOf("-") : -1;
+ let languageCode; // navigator locale without the regional part
+ if (dashIndex === -1) {
+ languageCode = navigatorLocale;
+ } else {
+ languageCode = navigatorLocale.slice(0, dashIndex);
+ }
+
+ // get locale
+ if (availableLocales.includes(navigatorLocale)) {
+ return navigatorLocale;
+ } else if (availableLocales.includes(languageCode)) {
+ return languageCode;
+ } else {
+ return null;
+ }
+}
+
+// add locales
+localeCodes.forEach(addLocale);
+
+let initialLocale = pickLocale(getLocaleFromNavigator(), localeCodes);
+init({
+ fallbackLocale: 'en',
+ initialLocale: initialLocale,
+});
diff --git a/src/locales/en.json b/src/locales/en.json
new file mode 100644
index 00000000..97ae2cd3
--- /dev/null
+++ b/src/locales/en.json
@@ -0,0 +1,8 @@
+{
+ "langname": "English",
+ "howItWorks": "How It Works",
+ "faq": "FAQ",
+ "about": "About",
+ "startInSeconds": "Start in Seconds",
+ "signIn": "Sign In"
+}
diff --git a/src/locales/fr.json b/src/locales/fr.json
new file mode 100644
index 00000000..ec0b5016
--- /dev/null
+++ b/src/locales/fr.json
@@ -0,0 +1,8 @@
+{
+ "langname": "Français",
+ "howItWorks": "Comment Ça Fonctionne",
+ "faq": "FAQ",
+ "about": "À Propos",
+ "startInSeconds": "Commence en Secondes",
+ "signIn": "Connexion"
+}
diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte
index ef4ba1d4..9ec36c57 100644
--- a/src/routes/__layout.svelte
+++ b/src/routes/__layout.svelte
@@ -2,6 +2,7 @@
import { SvelteToast } from '@zerodevx/svelte-toast';
import { toast } from '@zerodevx/svelte-toast';
import '../app.css';
+ import '$lib/i18n';
import { onMount } from 'svelte';
import { connect } from '$lib/socket';
import { user, token } from '$lib/store';