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

Multilingual support in templates


Go to End


4 Posts   2168 Views

Avatar
gonace

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>
		</div>
	</div>
</div>

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

Avatar
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']['SplashScreen.ss']['SVENSKA'] = "Svenska";
$lang['sv_SE']['SplashScreen.ss']['ENGLISH'] = "English";

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

Harl

Avatar
gonace

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!

Avatar
martimiz

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 mytemplate.ss, you can add this to your language file and SilverStripe should find it:
$lang['sv_SE']['mytemplate.ss']['SVENSKA'] = "Svenska";
$lang['sv_SE']['mytemplate.ss']['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 sometemplate.ss has a <% include mytemplate %>, add this to your languagefile:

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

Hope it helps,
Martine