Skip to content

Commit

Permalink
switch from svelte-i18n to svelte-fluent (#106)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
c-leri authored Jun 14, 2024
1 parent a7da8b5 commit 676798e
Show file tree
Hide file tree
Showing 78 changed files with 2,012 additions and 1,587 deletions.
92 changes: 92 additions & 0 deletions l10n/en.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
application-title = Quilt Developer Wiki
## Locales

en = English
fr = French
## Sidebar

menu = Menu
articles = Articles
## Lang Dropdown

language = Language
## Notices

# $wiki_source (String) - The url of the wiki's repo
dev-notice = Notice: This website is still under development. Please report any issues at <a data-l10n-name="link">{ $wiki_source }</a>.
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>.
# $wiki_source (String) - The url of the wiki's repo
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>.
# $current_locale (String) - The translated name of the current selected locale
# $fallback_locale (String) - The translated name of the selected fallback locale
article-not-translated-notice = This article isn't yet translated in { $current_locale }, but we found a version in { $fallback_locale }.
## Errors

# $error_code (String) - The status code of the error
error-title = Error { $error_code }
# $page_path (String) - The path to the page, without the locale
not-found-error = No page found at <code>{ $page_path }</code>.
# $article_path (String) - The path to the article, without the locale
article-not-found-error = No article found at <code>{ $article_path }</code>.
server-error = The server encountered an internal error, please try again.
## Wiki

# Blocks
blocks = Blocks
.first-block = Adding a Simple Block
.oriented-block = Adding an Oriented Block
.redstone-interaction = Adding Redstone Functionnality to your Block
# Concepts
concepts = Concepts
.events = Events
.libraries = List of Third Party Libraries
.lifecycles-ticks = Lifecycles and Ticks
.minecraft-code-structure = Minecraft's Code Structure
.mixins = Mixins
.nbt = NBT and Data in Minecraft
.networking = Networking
.qsl-qfapi = QSL and QFAPI Overview
.registries = Registries
.sideness = Server-Side and Client-Side
# Data
data = Data
.adding-recipes = Adding Recipes
.rea = Using Registry Entry Attachements (REA)
.recipe-api = Recipe API
.recipe-type = Adding a Recipe Type
.resource-loader = Resource Loader
# Introduction
introduction = Introduction
.getting-started = Getting Started with Quilt
.setting-up = Setting Up a Development Environment
# Items
items = Items
.armor = Adding an Armor Set
.first-item = Creating your First Item
.food = Adding Food
.tools = Adding Custom Tools
# Configuration
configuration = Configuration
.getting-started = Getting Started with Quilt Config
.advanced-configuring = Advanced Configuring
.config-screen = Setting up a Config Screen
.metadata = Annotations and Metadata Reference
# Misc
misc = Misc
.commands = Adding Commands
.sounds = Adding Sounds
.mappings = Customizing your Mappings
.world_types = Adding World Types
91 changes: 91 additions & 0 deletions l10n/fr.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
application-title = Wiki pour Développeur·euse·s Quilt
## Locales

en = Anglais
fr = Français
## Sidebar

menu = Menu
articles = Articles
## Lang Dropdown

language = Langue
## Notices

# $wiki_source (String) - The url of the wiki's repo
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>.
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>.
# $wiki_source (String) - The url of the wiki's repo
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>.
# $current_locale (String) - The translated name of the current selected locale
# $fallback_locale (String) - The translated name of the selected fallback locale
article-not-translated-notice = Cet article n'est pas encore traduit en { $current_locale }, mais nous avons trouvé une version en { $fallback_locale }.
## Errors

# $error_code (String) - The status code of the error
error-title = Erreur { $error_code }
# $page_path (String) - The path to the page, without the locale
not-found-error = Aucune page trouvée à l'adresse <code>{ $page_path }</code>.
# $article_path (String) - The path to the article, without the locale
article-not-found-error = Aucun article trouvé à l'adresse <code>{ $article_path }</code>.
server-error = Le server a rencontré une erreur, veuillez réessayer.
## Wiki

# Blocks
blocks = Blocs
.first-block = Ajouter un Bloc Simple
.oriented-block = Ajouter un Bloc Orienté
.redstone-interaction = Ajouter des fonctionnalités Redstone à votre Bloc
# Concepts
concepts = Concepts
.events = Événements
.libraries = Liste de Librairies Tiers
.lifecycles-ticks = Cycles de Vie et Ticks
.minecraft-code-structure = Structure du Code de Minecraft
.mixins = Mixins
.nbt = NBT et Données dans Minecaft
.networking = Réseau
.qsl-qfapi = Aperçu des QSL et de la QFAPI
.registries = Registres
.sideness = Côté Serveur et Côté Client
# Data
data = Données
.adding-recipes = Ajouter des Recettes
.rea = Utiliser le "Registry Entry Attachments" (REA)
.recipe-api = API des Recettes
.recipe-type = Ajouter un Type de Recette
.resource-loader = "Resource Loader"
# Introduction
introduction = Introduction
.getting-started = Débuter avec Quilt
.setting-up = Mettre en place un Environement de Développement
# Items
items = Items
.armor = Ajouter une Armure
.first-item = Créer votre Premier Ite
.food = Ajouter de la Nourriture
.tools = Ajouter des Outils Personnalisés
# Configuration
configuration = Configuration
.getting-started = Débuter avec Quilt Config
.advanced-configuring = Configuration Avancée
.config-screen = Mettre en place un Écran de Configuration
.metadata = Référence pour les Annotations et les Métadonnées
# Misc
misc = Divers
.commands = Ajouter des Commandes
.sounds = Ajouter des Sons
.mappings = Personnaliser vos Mappings
.world_types = Ajouter des Types de Monde
85 changes: 85 additions & 0 deletions l10n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import translationsEn from "./en.ftl?raw";
import translationsFr from "./fr.ftl?raw";

import { FluentResource, FluentBundle } from "@fluent/bundle";
import { negotiateLanguages } from "@fluent/langneg";
import { derived, writable, type Readable, type Writable } from "svelte/store";

import { browser } from "$app/environment";

/**
* List of all supported locales
* (see also kit.prerender.entries in svelte.config.js when adding locales)
*/
export const supportedLocales = ["en", "fr"] as const;

export type Locale = (typeof supportedLocales)[number];

export function isLocale(maybeLocale: string): maybeLocale is Locale {
return supportedLocales.includes(maybeLocale as Locale);
}

export const defaultLocale: Locale = "en";

export const currentLocale: Writable<Locale> = writable(defaultLocale);

/**
* List of supported locales that are rtl (none for now)
*/
const rtlLocales: Locale[] = [];

export function isRtl(locale: Locale): boolean {
return rtlLocales.includes(locale);
}

export const currentDir: Readable<"ltr" | "rtl"> = derived(currentLocale, ($currentLocale, set) => {
set(isRtl($currentLocale) ? "rtl" : "ltr");
});

/**
* The prefered locales of the user
* with the current locale as the first element
*/
export const currentLocales: Readable<Locale[]> = derived(currentLocale, ($currentLocale, set) => {
if (browser) {
const fallbackLocales = negotiateLanguages(navigator.languages, supportedLocales, {
defaultLocale
}).filter((locale) => locale !== $currentLocale) as Locale[]; // Remove the current locale to not add it twice

set([
$currentLocale,
// Add the user's prefered languages as fallback
...fallbackLocales
]);
} else if ($currentLocale != defaultLocale) {
// Only add the default locale when generating on the server
set([$currentLocale, defaultLocale]);
} else {
set([defaultLocale]);
}
});

/**
* All the translations as fluent resources
*/
const resources: { [L in Locale]: FluentResource } = {
en: new FluentResource(translationsEn),
fr: new FluentResource(translationsFr)
};

/**
* The bundle with the translations resource
* of the current locales
*/
export const currentBundle: Readable<FluentBundle> = derived(
[currentLocales],
([$currentLocales], set) => {
const bundle = new FluentBundle($currentLocales);

$currentLocales.forEach((locale) => {
bundle.addResource(resources[locale]);
});

set(bundle);
}
);
37 changes: 19 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@
"format": "prettier --plugin-search-dir . --write . && eslint . --fix"
},
"devDependencies": {
"@fluent/bundle": "^0.18.0",
"@fluent/langneg": "^0.7.0",
"@hbsnow/rehype-sectionize": "^1.0.7",
"@iconify-json/fa6-brands": "^1.1.18",
"@iconify-json/fa6-solid": "^1.1.20",
"@iconify-json/tabler": "^1.1.103",
"@iconify-json/fa6-brands": "^1.1.19",
"@iconify-json/fa6-solid": "^1.1.21",
"@iconify-json/tabler": "^1.1.113",
"@jsdevtools/rehype-toc": "^3.0.2",
"@nubolab-ffwd/svelte-fluent": "^0.8.0",
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.4.3",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"@sveltekit-i18n/base": "^1.3.7",
"@sveltekit-i18n/parser-default": "^1.1.1",
"@types/node": "^20.11.0",
"@types/prismjs": "^1.26.3",
"@sveltejs/kit": "^2.5.10",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@types/node": "^20.14.0",
"@types/prismjs": "^1.26.4",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@unocss/extractor-svelte": "^0.57.7",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-svelte": "^2.35.1",
"eslint-plugin-svelte": "^2.39.0",
"jsdom": "^24.1.0",
"mdsvex": "^0.11.0",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.1",
Expand All @@ -39,14 +41,13 @@
"rehype-autolink-headings": "^6.1.1",
"rehype-rewrite": "^3.0.6",
"rehype-slug": "^6.0.0",
"svelte": "^4.2.8",
"svelte-check": "^3.6.3",
"svelte-markdown": "^0.4.1",
"svelte": "^4.2.17",
"svelte-check": "^3.8.0",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"typescript": "^5.4.5",
"unocss": "^0.57.7",
"vite": "^5.0.12",
"yaml": "^2.3.4"
"vite": "^5.2.12",
"yaml": "^2.4.3"
},
"type": "module"
}
}
Loading

1 comment on commit 676798e

@Cozy-GitHub
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See preview on Cloudflare Pages: https://31a39358.developer-wiki.pages.dev

Please sign in to comment.