FTL (Fluent)

Languine supports FTL files, Mozilla's Fluent localization system. This powerful format handles complex translations including variables, selectors, attributes, and terms while maintaining a human-readable syntax.


Setting Up

First, make sure you've got a languine.json config file in your project root. Here's an example:

languine.json
{
  "locale": {
    "source": "en",
    "targets": ["sv", "de", "fr"]
  },
  "files": {
    "ftl": {
      "include": ["locales/[locale].ftl"]
    }
  }
}

Translating

With your config set, run:

typescript
npx languine@latest translate

When you run this command, Languine will:

  • Load your source FTL file (e.g., locales/en.ftl)
  • Detect any new or modified translation strings
  • Generate translations for your target languages
  • Create or update the target language FTL files (e.g., locales/sv.ftl)
  • Preserve all FTL features including:
    • Variables and placeholders
    • Selectors for plurals and other variants
    • Attributes
    • Terms and references
    • Comments and metadata

FTL Features

Basic Messages

locales/en.ftl
welcome = Welcome!
with-var = Welcome, { $name }!

Selectors (including plurals)

locales/en.ftl
emails =
    { $unreadEmails ->
        [one] You have one unread email.
       *[other] You have { $unreadEmails } unread emails.
    }

Attributes

locales/en.ftl
login-input = Predefined value
    .placeholder = email@example.com
    .aria-label = Login input value

Terms (Reusable Elements)

locales/en.ftl
-brand-name = Umbrella
about = About { -brand-name }.

Multiline Text

locales/en.ftl
description =
    This is a long description that
    spans multiple lines. The indentation
    will be handled automatically.

Comments

locales/en.ftl
# Regular comment
## Section comment
### Resource comment

# Describing variables
# $title (String) - The title of the bookmark
remove-bookmark = Remove { $title }?