fluent
Copyright(c) 2026 Institute for Digital Autonomy
LicenseEUPL-1.2
MaintainerIDA
Safe HaskellTrustworthy
LanguageHaskell2010

Language.Fluent

Description

Project Fluent is a localisation system designed to unleash the entire expressive power of natural language translations.

This library provides the core Fluent translation machinery to go from parsed Resources to translated messages:

  • the Locale typeclass which supplies locale-specific operations
  • the Bundle type which combines Locales with parsed Resources
  • the Translate typeclass which translates messages from a Bundle

This library does not provide any production-ready instances of Locale. Applications should instead use a dedicated backend for full localisation support, such as:

For quick evaluation or basic English translation, this library includes an example English locale. It implements a small subset of English rules and is not a replacement for a full-featured backend.

Synopsis

Documentation

data Identifier #

Instances

Instances details
Show Identifier # 
Instance details

Defined in Language.Fluent.AST

Eq Identifier # 
Instance details

Defined in Language.Fluent.AST

Ord Identifier # 
Instance details

Defined in Language.Fluent.AST

Hashable Identifier # 
Instance details

Defined in Language.Fluent.AST

Lift Identifier # 
Instance details

Defined in Language.Fluent.TH

Methods

lift :: Quote m => Identifier -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Identifier -> Code m Identifier #

data Resource #

Instances

Instances details
Generic Resource # 
Instance details

Defined in Language.Fluent.AST

Associated Types

type Rep Resource 
Instance details

Defined in Language.Fluent.AST

type Rep Resource = D1 ('MetaData "Resource" "Language.Fluent.AST" "fluent-syntax-1.1.0-inplace" 'True) (C1 ('MetaCons "Resource" 'PrefixI 'True) (S1 ('MetaSel ('Just "entries") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Entry])))

Methods

from :: Resource -> Rep Resource x #

to :: Rep Resource x -> Resource #

Show Resource # 
Instance details

Defined in Language.Fluent.AST

Eq Resource # 
Instance details

Defined in Language.Fluent.AST

Lift Resource # 
Instance details

Defined in Language.Fluent.TH

Methods

lift :: Quote m => Resource -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Resource -> Code m Resource #

type Rep Resource # 
Instance details

Defined in Language.Fluent.AST

type Rep Resource = D1 ('MetaData "Resource" "Language.Fluent.AST" "fluent-syntax-1.1.0-inplace" 'True) (C1 ('MetaCons "Resource" 'PrefixI 'True) (S1 ('MetaSel ('Just "entries") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Entry])))

bundle :: NonEmpty locale -> [Resource] -> Bundle locale Source #

A bundle of Resources for the given Locales, with the default configuration.

data Bundle locale Source #

A collection of Fluent resources and the configuration needed to resolve and format messages for a locale.

Constructors

Bundle 

Fields

Instances

Instances details
Locale locale => Show (Bundle locale) Source # 
Instance details

Defined in Language.Fluent.Bundle

Methods

showsPrec :: Int -> Bundle locale -> ShowS #

show :: Bundle locale -> String #

showList :: [Bundle locale] -> ShowS #

Locale locale => Eq (Bundle locale) Source #

Only the names of the functions are compared, since their implementations cannot be compared for equality.

Instance details

Defined in Language.Fluent.Bundle

Methods

(==) :: Bundle locale -> Bundle locale -> Bool #

(/=) :: Bundle locale -> Bundle locale -> Bool #

Locale locale => Translate (Bundle locale -> Either String Text) Source # 
Instance details

Defined in Language.Fluent.Translate

data Override Source #

A change to a Bundle.

Constructors

UseIsolating Bool

Whether to use isolation marks around placeables.

WithFunction Identifier ([Pattern] -> HashMap Identifier Value -> Either String Pattern)

Add a function, shadowing the builtin of the same name.

Instances

Instances details
Translate r => Translate (Override -> r) Source # 
Instance details

Defined in Language.Fluent.Translate

Methods

translate :: Reference -> Override -> r Source #

data Style Source #

What a number denotes, which determines how it is formatted.

Constructors

Decimal

A plain number: 12.5

Percent

A ratio, shown as a percentage: 1,250%

Currency Text

An amount of the currency with the given ISO 4217 code: Currency EUR gives €12.50

Unit Text

A measurement in the given CLDR unit: Unit "second" gives 12.5 s

Instances

Instances details
Show Style Source # 
Instance details

Defined in Language.Fluent.Number

Methods

showsPrec :: Int -> Style -> ShowS #

show :: Style -> String #

showList :: [Style] -> ShowS #

Eq Style Source # 
Instance details

Defined in Language.Fluent.Number

Methods

(==) :: Style -> Style -> Bool #

(/=) :: Style -> Style -> Bool #

newtype Pattern Source #

A Pattern with all the selections and interpolations resolved down to Value and isolation marks.

Instances

Instances details
Semigroup Pattern Source # 
Instance details

Defined in Language.Fluent.Pattern

IsString Pattern Source # 
Instance details

Defined in Language.Fluent.Pattern

Methods

fromString :: String -> Pattern #

Show Pattern Source # 
Instance details

Defined in Language.Fluent.Pattern

data PatternElement Source #

A single piece of a Pattern.

Constructors

Value Value

A value, ready to be formatted.

Isolated Pattern

A sequence of values surrounded by isolation marks (FSI, PDI).

Instances

Instances details
IsString PatternElement Source # 
Instance details

Defined in Language.Fluent.Pattern

Show PatternElement Source # 
Instance details

Defined in Language.Fluent.Pattern

data Digits Source #

How many digits a date or time field takes, e.g. the ninth month is 9 when Numeric and 09 when TwoDigit.

Constructors

Numeric 
TwoDigit 

Instances

Instances details
Bounded Digits Source # 
Instance details

Defined in Language.Fluent.Time

Enum Digits Source # 
Instance details

Defined in Language.Fluent.Time

Read Digits Source # 
Instance details

Defined in Language.Fluent.Time

Show Digits Source # 
Instance details

Defined in Language.Fluent.Time

Eq Digits Source # 
Instance details

Defined in Language.Fluent.Time

Methods

(==) :: Digits -> Digits -> Bool #

(/=) :: Digits -> Digits -> Bool #

class ToValue v where Source #

Types usable as arguments in Fluent message formatting.

Methods

toValue :: v -> Value Source #

Instances

Instances details
ToValue Value Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Value -> Value Source #

ToValue Int16 Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Int16 -> Value Source #

ToValue Int32 Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Int32 -> Value Source #

ToValue Int64 Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Int64 -> Value Source #

ToValue Int8 Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Int8 -> Value Source #

ToValue Word16 Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Word16 -> Value Source #

ToValue Word32 Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Word32 -> Value Source #

ToValue Word64 Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Word64 -> Value Source #

ToValue Word8 Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Word8 -> Value Source #

ToValue Scientific Source # 
Instance details

Defined in Language.Fluent.Value

ToValue Text Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Text -> Value Source #

ToValue UTCTime Source # 
Instance details

Defined in Language.Fluent.Value

ToValue Integer Source # 
Instance details

Defined in Language.Fluent.Value

ToValue Natural Source # 
Instance details

Defined in Language.Fluent.Value

ToValue String Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: String -> Value Source #

ToValue Double Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Double -> Value Source #

ToValue Float Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Float -> Value Source #

ToValue Int Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Int -> Value Source #

ToValue Word Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Word -> Value Source #

data Value Source #

The concrete representation of a Fluent value, along with any formatting options.

Instances

Instances details
ToValue Value Source # 
Instance details

Defined in Language.Fluent.Value

Methods

toValue :: Value -> Value Source #

IsString Value Source # 
Instance details

Defined in Language.Fluent.Value

Methods

fromString :: String -> Value #

Show Value Source # 
Instance details

Defined in Language.Fluent.Value

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

data Width Source #

How much of a name to write.

Constructors

Narrow

e.g. A, 5s

Short

e.g. Aug, 5 s

Long

e.g. August, 5 seconds

Instances

Instances details
Bounded Width Source # 
Instance details

Defined in Language.Fluent.Width

Enum Width Source # 
Instance details

Defined in Language.Fluent.Width

Read Width Source # 
Instance details

Defined in Language.Fluent.Width

Show Width Source # 
Instance details

Defined in Language.Fluent.Width

Methods

showsPrec :: Int -> Width -> ShowS #

show :: Width -> String #

showList :: [Width] -> ShowS #

Eq Width Source # 
Instance details

Defined in Language.Fluent.Width

Methods

(==) :: Width -> Width -> Bool #

(/=) :: Width -> Width -> Bool #