Skip to content

Replace Localization Tables with Fluent #1496

@iamteapot422

Description

@iamteapot422

Summary

Fluent will allow us to properly apply grammar rules, which we would otherwise need to code in C# every time. We might be able to handle the grammar in the English language, but other languages with more complex rules for word forms would have a hard time. We can also use Fluent to store status texts and perform fancy formatting.

Examples

en-US.ftl

coins =
    { $count ->
        [one] { $count } coin
       *[other] { $count } coins
    }

C#

loc.Get("coins", ("count", 1));
loc.Get("coins", ("count", 5));

Output

1 coin
5 coins


en-US.ftl

player-joined =
    { $gender ->
        [male] He joined the game.
        [female] She joined the game.
       *[other] They joined the game.
    }

C# Usage
loc.Get("player-joined", ("gender", "female"));

Output
She joined the game.


en-US.ftl

quest-status =
    { $completed ->
        [true] Quest Completed!
       *[false] Quest In Progress...
    }

C# Usage
loc.Get("quest-status", ("completed", true));

Output
Quest Completed!


en-US.ftl

start-button =
    .label = Start Game
    .tooltip = Begin a new adventure

C# Usage

var message = bundle.GetMessage("start-button");
var tooltip = bundle.FormatPattern(message.Attributes["tooltip"]);

Output
Begin a new adventure


en-US.ftl
score = Score: { NUMBER($points) }

C#
loc.Get("score", ("points", 12345));

Output
Score: 12,345

Links

https://firefox-source-docs.mozilla.org/l10n/fluent/index.html
https://docs.spacestation14.com/en/ss14-by-example/fluent-and-localization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: medium 🥼For those that already have some understanding of the code base.FeatureA new system or other feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions