Skip to content

Messages and Terms

QuickWrite edited this page Sep 22, 2022 · 2 revisions

Messages and Terms are the base building block of every Fluent file as they are encompassing declaration of all of the other building blocks. Messages and Terms can be declared by having the key on the left side and the content on the right side of the =:

{{key}} = {{content}}

The key is the name by which it is being accessed.

hello = World 

This means that when the key hello is being accessed it would return World.

Differences between Messages and Terms

To convert a Message into a Term the key needs to be prepended with a -. This means that when hello should be a term, this should be done:

-hello = World 

Terms are similar to regular messages but they can only be used as references in other messages. The runtime cannot retrieve terms directly. They are best used to define vocabulary and glossary items which can be used consistently across the localization of the entire product:

-brand-name = Firefox

about = About { -brand-name }.
update-successful = { -brand-name } has been updated.

Term values follow the same rules as message values. They can be simple text, or they can interpolate other expressions, including variables. However, while messages receive data for variables directly from the accessing scope, terms receive such data from messages in which they are used. Such references take the form of -term(…) where the variables available inside of the term are defined between the parentheses, e.g. -term(param: "value").

# A contrived example to demonstrate how variables
# can be passed to terms.
-https = https://{ $host }
visit = Visit { -https(host: "example.com") } for more information.

Placeables

In Fluent, text can interpolate values of other messages, as well as external data passed into the translation from the app. Use the curly braces to start and end interpolating another expression inside of a pattern:

# $title (String) - The title of the bookmark to remove.
remove-bookmark = Are you sure you want to remove { $title }?

Multiline Text

Text can span multiple lines. In such cases, Fluent will calculate the common indent of all indented lines and remove it from the final text value.

multi = Text can also span multiple lines as long as
    each new line is indented by at least one space.
    Because all lines in this message are indented
    by the same amount, all indentation will be
    removed from the final value.

indents =
    Indentation common to all indented lines is removed
    from the final text value.
      This line has 2 spaces in front of it.
Clone this wiki locally