Difference between revisions of "Routing and Template Cookbook: Translation system"

From Dreamwidth Notes
Jump to: navigation, search
(Created page with "= Handlers = = Templates = In templates, the translation system can be accessed as a filter or a method. == Using translation strings == === As a filter: without extra arg...")
 
(As a filter: with extra arguments)
 
Line 13: Line 13:
 
=== As a filter: with extra arguments ===
 
=== As a filter: with extra arguments ===
  
<code>[% '.label' | ml(user = u.ljuser_display) %]</code>
+
<code>[% '.label' | ml( user = u.ljuser_display ) %]</code>
  
 
=== As a method: with extra arguments ===
 
=== As a method: with extra arguments ===

Latest revision as of 18:46, 24 February 2013

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'); %]