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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Multilingual support in templates

Go to End

4 Posts   1726 Views


Community Member, 11 Posts

30 April 2010 at 12:44am

Edited: 30/04/2010 12:45am

Im trying to do some multilingual support but can't get i to work, I've added this in my sv_SE.php language file:

$lang['sv_SE']['SplashScreen']['SVENSKA'] = "Svenska";
$lang['sv_SE']['SplashScreen']['ENGLISH'] = "English";

And this is my template:

<div id="SplashScreen" class="hidden">
	<div id="SplashContent">
		<div id="SplashLanguages">
			<a onclick=""><% _t('SplashScreen.SVENSKA', 'Swedish') %></a>
			<a onclick=""><% _t('SplashScreen.ENGLISH', 'English') %></a>

But all that I can see is the fallback "Swedish" and "English"

Martin Pales

Community Member, 19 Posts

30 April 2010 at 6:21pm

Your sv_SE.php language file should contain template filename. Like this:

$lang['sv_SE']['']['SVENSKA'] = "Svenska";
$lang['sv_SE']['']['ENGLISH'] = "English";

Without .ss it only works in your SplashScreen.php (class/controller file).



Community Member, 11 Posts

3 May 2010 at 6:14pm

Tried to add .ss to SplashScreen, but still the only thing that shows is the fallback string!


Forum Moderator, 1391 Posts

4 May 2010 at 1:19am

The preferred way is to just leave out the namespace bit in templates, to keep it readable, and add:

<a onclick=""><% _t('SVENSKA', 'Swedish') %></a>
<a onclick=""><% _t('ENGLISH', 'English') %></a>

Now, if you template name were to be, you can add this to your language file and SilverStripe should find it:
$lang['sv_SE']['']['SVENSKA'] = "Svenska";
$lang['sv_SE']['']['ENGLISH'] = "English"; 

Just in case: it still might not work if your template is included in some other template. In that case you could use the enveloping template's namespace. So supposing a template has a <% include mytemplate %>, add this to your languagefile:

$lang['sv_SE']['']['SVENSKA'] = "Svenska";
$lang['sv_SE']['']['ENGLISH'] = "English"; 

Hope it helps,