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 texthtml
is threated as HTML<h1>{{ plainMsg('site.title')</h1>
<p>{{ htmlMsg(site.description) | raw }}</p>
plainMsg
and htmlMsg
both do the following:
plainMsg
creates a plain message tokenhtmlMsg
creates an HTML message tokenFIXME:<key>
Plain token | HTML token | |
---|---|---|
plainMsg |
directly outputs the translation | htmlspecialchars |
htmlMsg |
strip_tags |
directly outputs the translation |
$translator = $this->container->get('loginet_messaging.translator');
$title = $translator->plainMsg('site.title');
$description = $translator->htmlMsg('site.description');
// Behaviour is same as in templating
You can edit the message translations for the current locale on tha admin page /admin/messaging
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'));