Jump to:

22976 Posts in 11702 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Dynamic translation keys

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 172 Views
  • richard-ward
    Avatar
    Community Member
    31 Posts

    Dynamic translation keys Link to this post

    Hi,

    This may not be possible, but I was wondering if there was a way to use a variable as part of a translation key, for example:

    <%t $ClassName.TITLE "..." %>

    Obviously I can't do the above, but I wondered if anyone else had found a way?

    Many thanks,
    Richard

  • richard-ward
    Avatar
    Community Member
    31 Posts

    Re: Dynamic translation keys Link to this post

    Whilst I await much better solutions, I thought I would share what I am doing for the time being...

    TranslateExtension.php

    <?php

    class TranslateExtension extends DataExtension {

    function T($key) {
    return _t($this->owner->ClassName . "_ss." . $key);
    }

    }

    WidgetHolder.ss

    $T(TITLE)

    en.yml

    en:
    FlickrWidget_ss:
    TITLE: "Flickr Photos"
    PicasaWidget_ss:
    TITLE: "Comments"

    172 Views
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.