Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[SS 3.0.5] Translation syntax for templates

Go to End

2 Posts   1344 Views


Community Member, 2 Posts

6 June 2013 at 3:36am

Edited: 06/06/2013 3:37am

I'm currently working on our first project on silverstripe 3.0.5. It's quite a big project for a first-timer on the new version of SS.

Anyhow, I got a bit confused by the i18n documentation. It says we should use a different syntax for translating in templates:

In .ss template files, instead of _t(params) the syntax <%t params %> is used. The syntax for passing parameters to the function is quite different to the PHP version of the function.

It turns out the <%t SEARCHBYNAME 'Search by name' %> syntax isn't working at all. Atleast, I didn't get it to work in my templates. Instead i used the old syntax: <% _t('SEARCHBYNAME','Search by name') %> which was working perfectly.

My question is; what is the correct syntax and why isn't the syntax working as stated in the documentation?


Community Member, 30 Posts

6 June 2013 at 5:17am

Edited: 06/06/2013 5:18am


The template syntax of 3.x requires you to namespace your keys unlike in 2.x. As stated in the documentation you need to do something like this instead

<%t Namespace.Entity "String to translate" %>

If your trying to so replacements with sprintf you now would do something like:

<%t Header.Greeting "Hello {name} {greeting}" name=$Name greeting=$Greeting %>

Documentation does show this but it doesn't explicitly say that what you have will not work.