Skip to content

Commit

Permalink
Added links to the english version
Browse files Browse the repository at this point in the history
- In the "the main version of the wiki is the english one" info message
- In the "this wiki is not yet translated in your locale" info message
  • Loading branch information
c-leri committed Mar 28, 2024
1 parent 879c572 commit 0fcb973
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 33 deletions.
29 changes: 4 additions & 25 deletions src/lib/NavbarLangDropdown.svelte
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
<script lang="ts">
import { browser } from "$app/environment";
import { page } from "$app/stores";
import { t, locales, locale } from "$lib/translations";
// Removes the current locale from the current route
// (only if the current route does contain the locale)
let current_route = "";
$: {
const routeExtractor = new RegExp(`^(/${$locale})?(/.+)?$`);
const routeMatch = $page.url.pathname.match(routeExtractor);
// prettier-ignore
if (
routeMatch &&
(
// We match the locale
routeMatch[1] ||
// We don't match the locale and a locale isn't in the route
routeMatch[2] && !$locales.includes(routeMatch[2].replace(/^\/([^/]+)(\/.+)?$/, "$1"))
)
) {
current_route = routeMatch[2] || "";
}
}
import { t, locales } from "$lib/translations";
import { current_route } from "./stores";
let is_dropdown_active = false;
function toggleNavbar() {
Expand Down Expand Up @@ -68,8 +47,8 @@
{#each $locales as locale}
<a
class="navbar-item"
href={`/${locale}${current_route}`}
data-sveltekit-preload-data="tap"
href={`/${locale}${$current_route}`}
data-sveltekit-preload-data="false"
on:blur={handleBlur}
>
{$t(`lang.${locale}`)}
Expand Down
25 changes: 25 additions & 0 deletions src/lib/stores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { locale, locales } from "./translations";

import { derived } from "svelte/store";

import { page } from "$app/stores";

// Removes the current locale from the current route
// (only if the current route does contain the locale)
export const current_route = derived([page, locale, locales], ([$page, $locale, $locales], set) => {
const routeExtractor = new RegExp(`^(/${$locale})?(/.+)?$`);

const routeMatch = $page.url.pathname.match(routeExtractor);
// prettier-ignore
if (
routeMatch &&
(
// We match the locale
routeMatch[1] ||
// We don't match the locale and a locale isn't in the route
routeMatch[2] && !$locales.includes(routeMatch[2].replace(/^\/([^/]+)(\/.+)?$/, "$1"))
)
) {
set(routeMatch[2] || "");
}
});
9 changes: 9 additions & 0 deletions src/lib/svelte-markdown/NoPreloadLink.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
export let href = "";
export let title = "";
export let text = "";
</script>

<a {href} {title} data-sveltekit-preload-data="false">
{text}
</a>
6 changes: 3 additions & 3 deletions src/lib/translations/en/application.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"title": "Quilt Developer Wiki :P",
"dev-notice": "Notice: This website is still under development. Please report any issues at <{{placeholder}}>",
"translation-notice": "Please note that the original language of this wiki is english and that translated versions might not be up to date with the english version",
"draft-notice": "You were linked to a page in the wiki that is planned, but not yet implemented. If you want to help building out this wiki, go and take a look at <{{placeholder}}>",
"dev-notice": "Notice: This website is still under development. Please report any issues at <{{placeholder}}>.",
"translation-notice": "Please note that the original language of this wiki is english and that translated versions might not be up to date with the [english version]({{placeholder}}).",
"draft-notice": "You were linked to a page in the wiki that is planned, but not yet implemented. If you want to help building out this wiki, go and take a look at <{{placeholder}}>.",
"sidebar": {
"menu": "Menu",
"articles": "Articles"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/translations/en/wiki.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"not-translated": "This wiki page isn't yet translated in {{placeholder}}",
"not-found": "No wiki page found at: `{{placeholder}}`",
"not-translated": "This wiki page isn't yet translated in your language. [Go to the english version]({{placeholder}})",
"not-found": "No wiki page found at: `{{placeholder}}`.",
"blocks": {
"title": "Blocks",
"first-block": {
Expand Down
7 changes: 7 additions & 0 deletions src/lib/translations/fr/application.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
<<<<<<< HEAD
"title": "Wiki pour Développeur·euse·s de Quilt :P",
"dev-notice": "Attention : Ce site est encore en cours de développement. Veuillez signaler les problèmes (en anglais) ici : <{{placeholder}}>",
"translation-notice": "Veuillez noter que la langue originale de ce wiki est l'anglais et que les versions traduites peuvent ne pas être à jour en comparaison à la version anglaise",
"draft-notice": "Cette page du wiki est prévue mais n'a pas encore été implémentée. Vous pouvez participer à la création de ce wiki ici : <{{placeholder}}>",
=======
"title": "Wiki pour Développeur·euse·s Quilt :P",
"dev-notice": "Attention : Ce site est encore en cours de développement. Veuillez signaler les problèmes (en anglais) ici : <{{placeholder}}>.",
"translation-notice": "Veuillez noter que la langue originale de ce wiki est l'anglais et que les versions traduites peuvent ne pas être à jour en comparaison à la [version anglaise]({{placeholder}}).",
"draft-notice": "Cette page du wiki est prévue mais n'a pas encore été implémentée. Vous pouvez participer à la création de ce wiki ici : <{{placeholder}}>.",
>>>>>>> 18907d8 (Added links to the english version)
"sidebar": {
"menu": "Menu",
"articles": "Articles"
Expand Down
5 changes: 5 additions & 0 deletions src/lib/translations/fr/wiki.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
<<<<<<< HEAD
"not-translated": "Cette page du wiki n'est pas encore été traduite en {{placeholder}}",
"not-found": "Aucune page du wiki trouvée à l'adresse : `{{placeholder}}`",
=======
"not-translated": "Cette page du wiki n'a pas encore été traduite en français. [Accéder à la version anglaise]({{placeholder}})",
"not-found": "Aucune page du wiki trouvée à l'adresse : `{{placeholder}}`.",
>>>>>>> 18907d8 (Added links to the english version)
"blocks": {
"title": "Blocs",
"first-block": {
Expand Down
7 changes: 6 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import HtmlHead from "$lib/HtmlHead.svelte";
import Header from "$lib/Header.svelte";
import Sidebar from "$lib/Sidebar.svelte";
import NoPreloadLink from "$lib/svelte-markdown/NoPreloadLink.svelte";
import { locale, t } from "$lib/translations/index";
import { current_route } from "$lib/stores.js";
onMount(async () => {
const lowContrast = document.getElementById("low-contrast") as HTMLInputElement;
Expand Down Expand Up @@ -49,7 +51,10 @@
<article class="message is-danger mx-3 mt-3 mb-3">
<div class="message-body has-text-centered">
<h1>
{$t("application.translation-notice")}
<SvelteMarkdown
source={$t("application.translation-notice", { placeholder: `/en${$current_route}` })}
renderers={{ link: NoPreloadLink }}
/>
</h1>
</div>
</article>
Expand Down
2 changes: 2 additions & 0 deletions src/routes/[[locale=locale]]/[category]/[[slug]]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import NoPreloadLink from "$lib/svelte-markdown/NoPreloadLink.svelte";
import { t } from "$lib/translations/index.js";
import SvelteMarkdown from "svelte-markdown";
Expand All @@ -15,6 +16,7 @@
<h1>
<SvelteMarkdown
source={$t(data.warningMessage.key, { placeholder: data.warningMessage.placeholder })}
renderers={{ link: NoPreloadLink }}
/>
</h1>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/routes/[[locale=locale]]/[category]/[[slug]]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import YAML from "yaml";

import type { ComponentType, SvelteComponent } from "svelte";

import { defaultLocale, t } from "$lib/translations";
import { defaultLocale } from "$lib/translations";

export async function load({ params }): Promise<{
content?: ComponentType<SvelteComponent>;
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function load({ params }): Promise<{
title: post_metadata.title,
warningMessage: {
key: "wiki.not-translated",
placeholder: t.get(`lang.${params.locale}`)
placeholder: `/en/${params.category}/${params.slug}`
}
};
} else if (post_metadata.draft) {
Expand Down

0 comments on commit 0fcb973

Please sign in to comment.