fluent_compiler.bundle
- class fluent_compiler.bundle.FluentBundle(locale, resources, use_isolating=True, functions=None, escapers=None)[source]
A bundle of compiled FTL resources for a specific locale, ready to format messages.
- Parameters:
locale – A BCP 47 locale string e.g.
'en'
,'de-DE'
resources – A list of
fluent_compiler.resource.FtlResource
objects containing the FTL to compile. Seefrom_string()
andfrom_files()
for convenient alternative constructors.
The remainder of the parameters are the same as for
compile_messages()
.- classmethod from_string(locale, text, use_isolation=True, functions=None, escapers=None)[source]
Create a bundle from FTL text. This is convenience constructor to avoid having to create a
FtlResource
manually.
- classmethod from_files(locale, filenames, use_isolation=True, functions=None, escapers=None)[source]
Create a bundle from a list of FTL filenames. This is convenience constructor to avoid having to create a
FtlResource
manually.
- format(message_id, args=None)[source]
Generates a translation of the message specified by the message ID, returning the formatted message and list of formatting errors, as per
fluent_compiler.compiler.CompiledFtl.message_functions
docs.message_id
can be a string likemy-message-id
, and attributes can be referred to using dot notation likemy-message-id.my-attributes
.args
is an optional dictionary of parameters for the message. These can be strings, numbers or date/datetimes, as described in Formatting messages.Example:
>>> bundle = FluentBundle.from_string('en', ''' ... hello-user = Hello, { $username }! ... ''') >>> value, errors = bundle.format('hello-user', {'username': 'Jane'}) >>> val "Hello, Jane!" >>> errors []
See
errors
for a description of the returned errors list.
- check_messages()[source]
Returns a list of compilation errors, as per
fluent_compiler.compiler.CompiledFtl.errors
.