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.

General Questions

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

Dynamic translation keys


Reply

2 Posts   248 Views

Avatar
richard-ward

11 July 2013 at 6:41am Community Member, 31 Posts

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

11 July 2013 at 6:53am Community Member, 31 Posts

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"