message module

class fluent_anvil.message.Message

Bases: object

Container for a translation request.

The Message class is used to define a translation request. You can define a message id and optional keyworded variables that are passed to fluent (e.g., for placeables). Alternatively, you may use it in a way similar to Python’s setattr() function: In addition to the afore mentioned parameters you can define an object and the name of the attribute to write to. The translated string will then be assigned to that attribute automatically.

__init__(*args, **kwargs)

Initialize the Message class.

Examples

Variant 1:

Message(my_label, "text", "my_message_identifier", name="John") This example assumes that you have a form containing the label my_label for greeting the user. The greeting message is defined in the .ftl file using identifier my_message_identifier, for example: my_message_identifier = Welcome, { $name }! or my_message_identifier = Willkommen, { $name }! In the example above, the name is given as keyworded argument.

Varian 2:

Message("my_message_identifier", name="John") Same as above without assigning the translation.

Parameters:
  • args – You may provide object (any), attribute name (str) and message id (str). Alternatively, you can provide the message id (str) only.

  • kwargs – Optional keyworded variables to pass on to fluent (e.g., for placeables or selectors).

tofluent()

Generate parameters for the Javascript fluent library.