-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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)
- Loading branch information
Showing
78 changed files
with
2,012 additions
and
1,587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
676798e
There was a problem hiding this comment.
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