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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Dynamic translation keys


Go to End


2 Posts   1137 Views

Avatar
richard-ward

Community Member, 31 Posts

11 July 2013 at 6:41am

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

Avatar
richard-ward

Community Member, 31 Posts

11 July 2013 at 6:53am

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"