Routing and Template Cookbook: Translation system

From Dreamwidth Notes
Jump to: navigation, search

Handlers

Templates

In templates, the translation system can be accessed as a filter or a method.

Using translation strings

As a filter: without extra arguments

[% '.createlayer.toplevel.label.coreversion' | ml %]

As a filter: with extra arguments

[% '.label' | ml( user = u.ljuser_display ) %]

As a method: with extra arguments

[% dw.ml( '.createlayer.new', { 'name' => new_layer.name, 'id' => new_layer.s2lid } ) %]

Saving translations in a template variable

Sometimes it can be useful to save the results of a translation into a template variable that can be used later:

[%- confirm_msg = '.delete.text' | ml( type => layerinfo.laytype, name => "#$layerinfo.lid: $layerinfo.name") -%]

Including a template with a temporary ML scope change

[% dw.scoped_include('stats/site.tt'); %]