Jump to:

3447 Posts in 1032 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » [SS 3.0.5] Translation syntax for templates

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

Page: 1
Go to End
Author Topic: 536 Views
  • Jeroen
    Community Member
    2 Posts

    [SS 3.0.5] Translation syntax for templates Link to this post

    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: http://doc.silverstripe.org/framework/en/topics/i18n#usage-in-template-files

    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?

  • UndefinedOffset
    Community Member
    27 Posts

    Re: [SS 3.0.5] Translation syntax for templates Link to this post


    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.