Messaging

Instead of printing text directly, you can use message tokens. Message tokens are small entities, identified by a text key and they can have translation in each language.

There are two type of tokens:

  • plain is treated as plain text
  • html is threated as HTML

Usage in templates

<h1>{{ plainMsg('site.title')</h1>
<p>{{ htmlMsg(site.description) | raw }}</p>

plainMsg and htmlMsg both do the following:

  1. Checks if a token exists with the given key and the current local.
    • If not, it creates the token with an empty translation
      • plainMsg creates a plain message token
      • htmlMsg creates an HTML message token
  2. Outputs the token translation.
    • If the translation is empty, it outputs FIXME:<key>
Plain token HTML token
plainMsg directly outputs the translation htmlspecialchars
htmlMsg strip_tags directly outputs the translation

Usage in code (controllers ot other container aware code)

$translator = $this->container->get('loginet_messaging.translator');
$title = $translator->plainMsg('site.title');
$description = $translator->htmlMsg('site.description');

// Behaviour is same as in templating

Admin

You can edit the message translations for the current locale on tha admin page /admin/messaging

Client side

In javascript, you can use Loginet.Platform.Messaging.plainMsg or Loginet.Platform.Messaging.plainMsg functions with the same parameters as on server side

$('#title').html(Loginet.Platform.Messaging.plainMsg('site.title'));
$('#desc').html(Loginet.Platform.Messaging.htmlMsg('site.description'));