Skip to content

Commit 676798e

Browse files
authored
switch from svelte-i18n to svelte-fluent (#106)
Advantages: - Nicer interpolation - more explicit (named values) - allows to interpolates multiples values per string - No need for svelte-markdown for links/markup thanks to Overlays - Translations now fallback to the user's other prefered languages if a key is missing in its main language before defaulting to english - Arguably easier to understand and work with Disadvantages: - Maybe the translations keys are less clear ? since they can't be nested into groups locale fallback for wiki articles fluent cleanup + usage of fluent attributes for clearer article keys add support for rtl languages (needs to be tested with actual rtl languages)
1 parent a7da8b5 commit 676798e

File tree

78 files changed

+2012
-1587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2012
-1587
lines changed

l10n/en.ftl

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
application-title = Quilt Developer Wiki
2+
3+
## Locales
4+
5+
en = English
6+
fr = French
7+
8+
## Sidebar
9+
10+
menu = Menu
11+
articles = Articles
12+
13+
## Lang Dropdown
14+
15+
language = Language
16+
17+
## Notices
18+
19+
# $wiki_source (String) - The url of the wiki's repo
20+
dev-notice = Notice: This website is still under development. Please report any issues at <a data-l10n-name="link">{ $wiki_source }</a>.
21+
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 <a data-l10n-name="link">english version</a>.
22+
# $wiki_source (String) - The url of the wiki's repo
23+
draft-notice = You were linked to an article that is planned, but not yet implemented. If you want to help building out this wiki, go and take a look at <a data-l10n-name="link">{ $wiki_source }</a>.
24+
# $current_locale (String) - The translated name of the current selected locale
25+
# $fallback_locale (String) - The translated name of the selected fallback locale
26+
article-not-translated-notice = This article isn't yet translated in { $current_locale }, but we found a version in { $fallback_locale }.
27+
28+
## Errors
29+
30+
# $error_code (String) - The status code of the error
31+
error-title = Error { $error_code }
32+
# $page_path (String) - The path to the page, without the locale
33+
not-found-error = No page found at <code>{ $page_path }</code>.
34+
# $article_path (String) - The path to the article, without the locale
35+
article-not-found-error = No article found at <code>{ $article_path }</code>.
36+
server-error = The server encountered an internal error, please try again.
37+
38+
## Wiki
39+
40+
# Blocks
41+
blocks = Blocks
42+
.first-block = Adding a Simple Block
43+
.oriented-block = Adding an Oriented Block
44+
.redstone-interaction = Adding Redstone Functionnality to your Block
45+
46+
# Concepts
47+
concepts = Concepts
48+
.events = Events
49+
.libraries = List of Third Party Libraries
50+
.lifecycles-ticks = Lifecycles and Ticks
51+
.minecraft-code-structure = Minecraft's Code Structure
52+
.mixins = Mixins
53+
.nbt = NBT and Data in Minecraft
54+
.networking = Networking
55+
.qsl-qfapi = QSL and QFAPI Overview
56+
.registries = Registries
57+
.sideness = Server-Side and Client-Side
58+
59+
# Data
60+
data = Data
61+
.adding-recipes = Adding Recipes
62+
.rea = Using Registry Entry Attachements (REA)
63+
.recipe-api = Recipe API
64+
.recipe-type = Adding a Recipe Type
65+
.resource-loader = Resource Loader
66+
67+
# Introduction
68+
introduction = Introduction
69+
.getting-started = Getting Started with Quilt
70+
.setting-up = Setting Up a Development Environment
71+
72+
# Items
73+
items = Items
74+
.armor = Adding an Armor Set
75+
.first-item = Creating your First Item
76+
.food = Adding Food
77+
.tools = Adding Custom Tools
78+
79+
# Configuration
80+
configuration = Configuration
81+
.getting-started = Getting Started with Quilt Config
82+
.advanced-configuring = Advanced Configuring
83+
.config-screen = Setting up a Config Screen
84+
.metadata = Annotations and Metadata Reference
85+
86+
# Misc
87+
misc = Misc
88+
.commands = Adding Commands
89+
.sounds = Adding Sounds
90+
.mappings = Customizing your Mappings
91+
.world_types = Adding World Types
92+

l10n/fr.ftl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
application-title = Wiki pour Développeur·euse·s Quilt
2+
3+
## Locales
4+
5+
en = Anglais
6+
fr = Français
7+
8+
## Sidebar
9+
10+
menu = Menu
11+
articles = Articles
12+
13+
## Lang Dropdown
14+
15+
language = Langue
16+
17+
## Notices
18+
19+
# $wiki_source (String) - The url of the wiki's repo
20+
dev-notice = Attention : Ce site est encore en cours de développement. Veuillez signaler les problèmes (en anglais) ici : <a data-l10n-name="link">{ $wiki_source }</a>.
21+
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 <a data-l10n-name="link">version anglaise</a>.
22+
# $wiki_source (String) - The url of the wiki's repo
23+
draft-notice = Cet article est prévu mais n'a pas encore été implémentée. Vous pouvez participer à la création de ce wiki ici : <a data-l10n-name="link">{ $wiki_source }</a>.
24+
# $current_locale (String) - The translated name of the current selected locale
25+
# $fallback_locale (String) - The translated name of the selected fallback locale
26+
article-not-translated-notice = Cet article n'est pas encore traduit en { $current_locale }, mais nous avons trouvé une version en { $fallback_locale }.
27+
28+
## Errors
29+
30+
# $error_code (String) - The status code of the error
31+
error-title = Erreur { $error_code }
32+
# $page_path (String) - The path to the page, without the locale
33+
not-found-error = Aucune page trouvée à l'adresse <code>{ $page_path }</code>.
34+
# $article_path (String) - The path to the article, without the locale
35+
article-not-found-error = Aucun article trouvé à l'adresse <code>{ $article_path }</code>.
36+
server-error = Le server a rencontré une erreur, veuillez réessayer.
37+
38+
## Wiki
39+
40+
# Blocks
41+
blocks = Blocs
42+
.first-block = Ajouter un Bloc Simple
43+
.oriented-block = Ajouter un Bloc Orienté
44+
.redstone-interaction = Ajouter des fonctionnalités Redstone à votre Bloc
45+
46+
# Concepts
47+
concepts = Concepts
48+
.events = Événements
49+
.libraries = Liste de Librairies Tiers
50+
.lifecycles-ticks = Cycles de Vie et Ticks
51+
.minecraft-code-structure = Structure du Code de Minecraft
52+
.mixins = Mixins
53+
.nbt = NBT et Données dans Minecaft
54+
.networking = Réseau
55+
.qsl-qfapi = Aperçu des QSL et de la QFAPI
56+
.registries = Registres
57+
.sideness = Côté Serveur et Côté Client
58+
59+
# Data
60+
data = Données
61+
.adding-recipes = Ajouter des Recettes
62+
.rea = Utiliser le "Registry Entry Attachments" (REA)
63+
.recipe-api = API des Recettes
64+
.recipe-type = Ajouter un Type de Recette
65+
.resource-loader = "Resource Loader"
66+
67+
# Introduction
68+
introduction = Introduction
69+
.getting-started = Débuter avec Quilt
70+
.setting-up = Mettre en place un Environement de Développement
71+
72+
# Items
73+
items = Items
74+
.armor = Ajouter une Armure
75+
.first-item = Créer votre Premier Ite
76+
.food = Ajouter de la Nourriture
77+
.tools = Ajouter des Outils Personnalisés
78+
79+
# Configuration
80+
configuration = Configuration
81+
.getting-started = Débuter avec Quilt Config
82+
.advanced-configuring = Configuration Avancée
83+
.config-screen = Mettre en place un Écran de Configuration
84+
.metadata = Référence pour les Annotations et les Métadonnées
85+
86+
# Misc
87+
misc = Divers
88+
.commands = Ajouter des Commandes
89+
.sounds = Ajouter des Sons
90+
.mappings = Personnaliser vos Mappings
91+
.world_types = Ajouter des Types de Monde

l10n/index.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import translationsEn from "./en.ftl?raw";
2+
import translationsFr from "./fr.ftl?raw";
3+
4+
import { FluentResource, FluentBundle } from "@fluent/bundle";
5+
import { negotiateLanguages } from "@fluent/langneg";
6+
import { derived, writable, type Readable, type Writable } from "svelte/store";
7+
8+
import { browser } from "$app/environment";
9+
10+
/**
11+
* List of all supported locales
12+
* (see also kit.prerender.entries in svelte.config.js when adding locales)
13+
*/
14+
export const supportedLocales = ["en", "fr"] as const;
15+
16+
export type Locale = (typeof supportedLocales)[number];
17+
18+
export function isLocale(maybeLocale: string): maybeLocale is Locale {
19+
return supportedLocales.includes(maybeLocale as Locale);
20+
}
21+
22+
export const defaultLocale: Locale = "en";
23+
24+
export const currentLocale: Writable<Locale> = writable(defaultLocale);
25+
26+
/**
27+
* List of supported locales that are rtl (none for now)
28+
*/
29+
const rtlLocales: Locale[] = [];
30+
31+
export function isRtl(locale: Locale): boolean {
32+
return rtlLocales.includes(locale);
33+
}
34+
35+
export const currentDir: Readable<"ltr" | "rtl"> = derived(currentLocale, ($currentLocale, set) => {
36+
set(isRtl($currentLocale) ? "rtl" : "ltr");
37+
});
38+
39+
/**
40+
* The prefered locales of the user
41+
* with the current locale as the first element
42+
*/
43+
export const currentLocales: Readable<Locale[]> = derived(currentLocale, ($currentLocale, set) => {
44+
if (browser) {
45+
const fallbackLocales = negotiateLanguages(navigator.languages, supportedLocales, {
46+
defaultLocale
47+
}).filter((locale) => locale !== $currentLocale) as Locale[]; // Remove the current locale to not add it twice
48+
49+
set([
50+
$currentLocale,
51+
// Add the user's prefered languages as fallback
52+
...fallbackLocales
53+
]);
54+
} else if ($currentLocale != defaultLocale) {
55+
// Only add the default locale when generating on the server
56+
set([$currentLocale, defaultLocale]);
57+
} else {
58+
set([defaultLocale]);
59+
}
60+
});
61+
62+
/**
63+
* All the translations as fluent resources
64+
*/
65+
const resources: { [L in Locale]: FluentResource } = {
66+
en: new FluentResource(translationsEn),
67+
fr: new FluentResource(translationsFr)
68+
};
69+
70+
/**
71+
* The bundle with the translations resource
72+
* of the current locales
73+
*/
74+
export const currentBundle: Readable<FluentBundle> = derived(
75+
[currentLocales],
76+
([$currentLocales], set) => {
77+
const bundle = new FluentBundle($currentLocales);
78+
79+
$currentLocales.forEach((locale) => {
80+
bundle.addResource(resources[locale]);
81+
});
82+
83+
set(bundle);
84+
}
85+
);

package.json

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,27 @@
1212
"format": "prettier --plugin-search-dir . --write . && eslint . --fix"
1313
},
1414
"devDependencies": {
15+
"@fluent/bundle": "^0.18.0",
16+
"@fluent/langneg": "^0.7.0",
1517
"@hbsnow/rehype-sectionize": "^1.0.7",
16-
"@iconify-json/fa6-brands": "^1.1.18",
17-
"@iconify-json/fa6-solid": "^1.1.20",
18-
"@iconify-json/tabler": "^1.1.103",
18+
"@iconify-json/fa6-brands": "^1.1.19",
19+
"@iconify-json/fa6-solid": "^1.1.21",
20+
"@iconify-json/tabler": "^1.1.113",
1921
"@jsdevtools/rehype-toc": "^3.0.2",
22+
"@nubolab-ffwd/svelte-fluent": "^0.8.0",
2023
"@sveltejs/adapter-static": "^3.0.1",
21-
"@sveltejs/kit": "^2.4.3",
22-
"@sveltejs/vite-plugin-svelte": "^3.0.1",
23-
"@sveltekit-i18n/base": "^1.3.7",
24-
"@sveltekit-i18n/parser-default": "^1.1.1",
25-
"@types/node": "^20.11.0",
26-
"@types/prismjs": "^1.26.3",
24+
"@sveltejs/kit": "^2.5.10",
25+
"@sveltejs/vite-plugin-svelte": "^3.1.1",
26+
"@types/node": "^20.14.0",
27+
"@types/prismjs": "^1.26.4",
2728
"@typescript-eslint/eslint-plugin": "^5.62.0",
2829
"@typescript-eslint/parser": "^5.62.0",
2930
"@unocss/extractor-svelte": "^0.57.7",
30-
"eslint": "^8.56.0",
31+
"eslint": "^8.57.0",
3132
"eslint-config-prettier": "^8.10.0",
3233
"eslint-plugin-import": "^2.29.1",
33-
"eslint-plugin-svelte": "^2.35.1",
34+
"eslint-plugin-svelte": "^2.39.0",
35+
"jsdom": "^24.1.0",
3436
"mdsvex": "^0.11.0",
3537
"prettier": "^2.8.8",
3638
"prettier-plugin-svelte": "^2.10.1",
@@ -39,14 +41,13 @@
3941
"rehype-autolink-headings": "^6.1.1",
4042
"rehype-rewrite": "^3.0.6",
4143
"rehype-slug": "^6.0.0",
42-
"svelte": "^4.2.8",
43-
"svelte-check": "^3.6.3",
44-
"svelte-markdown": "^0.4.1",
44+
"svelte": "^4.2.17",
45+
"svelte-check": "^3.8.0",
4546
"tslib": "^2.6.2",
46-
"typescript": "^5.3.3",
47+
"typescript": "^5.4.5",
4748
"unocss": "^0.57.7",
48-
"vite": "^5.0.12",
49-
"yaml": "^2.3.4"
49+
"vite": "^5.2.12",
50+
"yaml": "^2.4.3"
5051
},
5152
"type": "module"
52-
}
53+
}

0 commit comments

Comments
 (0)