Guidelines for Working with Fluent Files
This document is intended as a guideline for developers and reviewers when working with FTL (Fluent) files. As such, it’s not meant to replace the existing extensive documentation about Fluent.
Herald is used to set the group fluent-reviewers as blocking reviewer for any patch modifying FTL files committed to Phabricator.
Hint
In case of doubt, you should always reach out to the l10n team for clarifications.
Message Identifiers
While in Fluent it’s possible to use both lowercase and uppercase characters in
message identifiers, the naming convention in Gecko is to use lowercase and
hyphens (kebab-case), avoiding CamelCase and underscores. For example,
allow-button should be preferred to allow_button or
allowButton, unless there are technical constraints — like identifiers
generated at run-time from external sources — that make this impractical.
All the messages loaded in a document share the same namespace, and in case of
a conflicting identifier only one message will be used. For this reason, add
scope to the message identifier itself, and try to use a consistent prefix for
all the messages in a file: using cancel as an identifier increases the
chances of having a conflict, save-dialog-cancel-button would make it
less likely. See Message Identifiers Share a Namespace
for more details.
Message identifiers are also used as the ultimate fallback in case of run-time errors. Having a descriptive message ID would make such fallback more useful for the user.
Avoid Generating Identifiers at Run-time
Message identifiers should be spelled out in full in the source code, instead of
being generated at run-time, for example with `bar-tooltip-${type}`.
Generated identifiers can’t be found by searching the code, still require
a mapping when one of the strings changes, and can end up requesting messages
that don’t exist. See Avoid Generating Identifiers at Run-time
for more details and an example of the preferred approach.
Changes to Existing Messages
Messages are identified in the entire localization toolchain by their ID. You must use a new identifier when the existing translations need to be updated, that is if:
The meaning of the sentence has changed.
You’re changing the morphology of the message, by adding or removing attributes.
You’re renaming or removing a variable, or a
data-l10n-nameused in the message, since existing translations would still reference the old name.
In some of these cases, existing translations can still be preserved with a migration, but a new identifier is needed anyway.
The updated message will be treated as a brand new string, and reported as missing in all tools, forcing localizers to update their translations. You must also update all instances where the identifier is used in the source code, including localization comments. This is the only reliable method to ensure that existing localizations are updated, and that run-time code stops using obsolete translations. For more details, see this document.
Changes in Meaning
The meaning of a sentence changes when what the message conveys, how it conveys it, or who it addresses changes. This generally covers most message changes, where an English string is reworded even if the general meaning doesn’t change much. For example:
# Before
cookie-banner-blocker-message = { -brand-short-name } blocked a cookie
# After
cookie-banner-blocker-message2 = { -brand-short-name } declined a cookie
If your changes are relevant only for English — for example, to correct a typographical error or to make letter case consistent — then there is generally no need to update the message identifier.
There is a grey area between needing a new ID or not. In some cases, it will be necessary to look at all the existing translations to determine if a new ID would be beneficial.
Changes in Morphology
The morphology of a sentence changes typically in three common patterns:
Adding a new attribute
# Before
back-nav-button =
.title = Go back
# After
back-nav-button2 =
.title = Go back
.aria-label = Go back
Removing an attribute
# Before
onboarding-panel =
.title = Welcome
.aria-label = Welcome
.style = min-width: 23em
# After
onboarding-panel2 =
.title = Welcome
This applies to any attribute, whether it’s a localizable string or an
attribute like .accesskey or .style.
Text moving between a value and an attribute
# Before
about-logins-icon = Warning icon
.title = Breached website
# After
about-logins-breach-icon =
.alt = Warning icon
.title = Breached website
Since messages are identified by their ID, there’s no need to change attribute names when updating a message.
Migrating Strings
In many cases, translations can be preserved even if the message identifier changes, by including a migration recipe in the patch. This is expected if a patch:
Moves legacy strings (.properties, .DTD) to Fluent.
Moves existing Fluent messages to a different file.
Changes the morphology of existing messages without actual changes to the content, like in the examples above.
Renames a variable or a
data-l10n-namewithout other changes to the content.
Documentation on how to write and test migration recipes is available in this page.
Non-text Elements in Messages
When a message includes non text-elements, like anchors or images, make sure
that they have a data-l10n-name associated to them. Additional
attributes, like the URL for an anchor or CSS classes, should not be exposed
for localization in the FTL file. See Markup Localization
for more details.
This information is not relevant if your code is using fluent-react, where DOM overlays work differently.
Message References
Consider the following example:
newtab-search-box-search-the-web-text = Search the Web
newtab-search-box-search-the-web-input =
.placeholder = { newtab-search-box-search-the-web-text }
.title = { newtab-search-box-search-the-web-text }
This might seem to reduce the work for localizers, but it actually doesn’t help:
A change to the referenced message (
newtab-search-box-search-the-web-text) would require a new ID also for all messages referencing it.Translation memory can help with matching text, not with message references.
On the other hand, this approach is helpful if, for example, you want to reference another element of the UI in your message:
help-button = Help
help-explanation = Click the { help-button } to access support
This enforces consistency and, if help-button changes, all other messages
will need to be updated anyway.
Terms
Fluent supports a specific type of message, called term. Terms are similar to regular messages but they can only be used as references in other messages. They are best used to define vocabulary and glossary items which can be used consistently across the localization of the entire product.
Terms are typically used for brand names, like Firefox or Mozilla:
it keeps them in one easily identifiable place, and raises warnings
when a localization is not using them. It helps enforcing consistency and brand
protection. If you simply need to reference a message from another message, you
don’t need a term: cross references between messages are allowed, but they
should not be abused, as already described.
Variants and plurals
Consider the following example:
items-selected =
{ $num ->
[0] Select items.
[one] One item selected.
*[other] { $num } items selected.
}
In this example, there’s no guarantee that all localizations will have this
variant covered, since variants are private by design. The correct approach for
the example would be to have a separate message for the 0 case:
# Separate messages which serve different purposes.
items-select = Select items
# The default variant works for all values of the selector.
items-selected =
{ $num ->
[one] One item selected.
*[other] { $num } items selected.
}
As a rule of thumb:
Use variants only if the default variant makes sense for all possible values of the selector.
The code shouldn’t depend on the availability of a specific variant.
Numeric variants like [1] should only be used in case you want to cover
the literal number. If it’s a standard plural, you should use the one
category for singular. Also make sure to always pass the variable to these
messages as a number, not as a string.
More examples about selector and variant abuses can be found in this wiki.
In general, also avoid putting a selector in the middle of a sentence, like in the example below:
items-selected =
{ $num ->
[one] One item.
*[other] { $num } items
} selected.
Access Keys
The following is a simple potential example of an access key:
example-menu-item =
.label = Menu Item
.accesskey = M
Access keys are used in menus in order to help provide easy keyboard shortcut access. They are useful for both power users, and for users who have accessibility needs. It is helpful to first read the Access keys guide in the Windows Developer documentation, as it outlines the best practices for Windows applications.
There are some differences between operating systems. Linux mostly follows the same practices as Windows. However, macOS in general does not have good support for accesskeys, especially in menus.
The access key should be a character included in the label, so that it can be
underlined. When choosing an access key, it’s important that it’s unique relative
to the current level of UI. It’s preferable to avoid letters with descending parts,
such as g, j, p, and q as these will not be
underlined nicely in Windows or Linux. Other problematic characters are ones which
are narrow, such as l, i and I. The underline may not be
as visible as other letters in sans-serif fonts.
Linters
mach lint includes two linters for Fluent files, which run locally
and on Treeherder. In the Build Status section of the diff on Phabricator,
open the Treeherder Jobs link and look for the jobs in the l10n group:
l1nt and l1nt-conflicts for the l10n linter, fluent for
fluent-lint.
The l10n linter, called
moz-l10n-lint. Besides displaying errors and warnings due to syntax errors, it’s particularly important because it also checks for message changes without new IDs, and conflicts with the firefox-l10n-source repository used to ship localized versions of Firefox. Checks can be run locally using./mach lint -l l10n -W.fluent-lint, which checks for style issues, like the use of straight quotes or ellipses, hard-coded brand names, missing comments for variables, and unknown attributes without a comment. Checks can be run locally using
./mach lint -l fluent-lint.
Comments
Comments are fundamental for localizers. Their work happens on a message at a time: in Pontoon, they can’t see the messages around the one they’re translating, the code, or the bug, and the context is only provided by comments. The resource comment, the group comment, and the message comment are all displayed next to the message being translated, so they need to make sense on their own.
Fluent supports several types of comments, depending on the number of
#used as prefix and the spacing around the comment itself:#– Message comment: applies to the message immediately following it. There must be no empty lines between the comment and the message, otherwise it becomes a standalone comment, which is not displayed to localizers. Examples of standalone comment are the license header at the beginning of a file, as well as developer comments.##– Group comment: applies to all the messages following it, until the next group comment or the end of the file. An empty group comment (##without any text) closes the group, and should be used if the following messages are not related to it.###– Resource comment: applies to the whole file, regardless of its position. It’s usually placed at the top of the file, after the license header.When a message includes placeables (variables), there should always be a comment explaining the format of the variable, and what kind of content it will be replaced with. This is enforced by fluent-lint, which checks that each variable is referenced in the message or group comment.
Similarly, attributes should be the ones designed for localized content, like
.label,.title,.placeholderor.aria-label, and applied directly to the element. If a message uses an attribute that fluent-lint doesn’t recognize, for example because it’s read by a script or by CSS, a warning is reported unless the comment mentions the attribute and explains why it’s needed:Note that, at run-time, attributes that are not localizable by default are only applied to the element if the markup allows them explicitly, for example with
data-l10n-attrs="data-after". See Markup Localization for more details.The following example shows the expected style for comments in Firefox FTL files, including the format for variables:
A few rules to keep in mind:
Use a single space between the
#prefix and the comment text. Indent variable descriptions by three spaces, as in the example above.Use one empty line before and after a group comment, and before and after a resource comment.
Don’t add an empty line between a message comment and its message, otherwise it becomes a standalone comment, and it won’t be displayed to localizers.
Group comments are a good way to provide context shared by a set of messages, like the section of the UI they appear in, or variables used by all of them. Don’t use them as visual separators.
Comments should be written for localizers, not developers: describe where and how the string is used, not implementation details.
Comments are not mandatory: if the string is clear and the identifier is descriptive, a comment might not be needed.