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.

Template Questions /

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

multilingual footer


Go to End


7 Posts   2310 Views

Avatar
craesh

Community Member, 25 Posts

28 August 2009 at 3:40am

Edited: 28/08/2009 4:14am

Hi!

I'm developing a bilingual site. Translatable works fine for the articles, but I don't know how to make the footer language-aware. Out of the box, it won't, so I know I'll need to modify something. Maybe it would be the best to have some <% control Page(footer-LOCALE) %> in footer.ss and have both versions of the footer as independent pages in the CMS? But how would I choose the right page in my footer.ss? Is there something like <% if locale = 'de-de' %>? I can't find anything in the docs. Any ideas?

Thanks!
craesh

Avatar
craesh

Community Member, 25 Posts

28 August 2009 at 4:11am

Thanks, Taffy, but neither of both will do it. The Translatable control will give me all translations, but I need just one - the right one. The _t function also won't do it, as the footer is too complex.

Avatar
Juanitou

Community Member, 323 Posts

28 August 2009 at 5:55am

Hi! I think I don't understand that “The _t function also won't do it, as the footer is too complex” thing.

Example of one of my footers:

<div id="Footer">
	<span class="left"><% _t('DESIGNBY', 'Conception :') %> <a href="http://www.eurovertice.eu/">EuroV&eacute;rtice</a></span>
	<span>$MetaClient
	<% if ClassName != ContactPage %>
	&nbsp;|&nbsp;<a href="$ContactPageLink"><% _t('CONTACTPAGE','Contact') %></a>
	<% end_if %>
	</span>
</div>

That gives footers translated in as much languages as xx_XX.php files you put in the lang folder, containing:

$lang['xx_XX']['Page.ss']['DESIGNBY'] = 'Conception :';
$lang['xx_XX']['Page.ss']['CONTACTPAGE'] = 'Contact';

If I got you well…

Avatar
craesh

Community Member, 25 Posts

28 August 2009 at 11:20pm

Sorry, I don't like the _t() solution. _t() is ok for buttons, labels, "read more" links, etc, but it's not appropriate for translating content. What if the customer wants to edit his footer in the future? You won't tell him too edit Footer.ss and xx_YY.php. A footer is content, thus it should be managed and translated through the admin interface. I actually set my Footer.ss to <% control page(Footer) %>... for all my Silverstripe projects. This is the first time I need to make it bilingual.

I did some hacking and now this does that work for me:

function PageForCurrentLocale( $pagename ) {
	if ( Object::has_extension('Page','Translatable') ) {
		Translatable::$enable_lang_filter = false; 
		$page = DataObject::get_one("Page","URLSegment='$pagename'");
		Translatable::$enable_lang_filter = true;
		if ( empty($page) )
			return;
		else if ( Translatable::get_current_locale() != Translatable::default_locale() )
			return $page->getTranslation( Translatable::get_current_locale() );
		else
			return $page;
	}
}

just put it in your Page class and this one in your Footer.ss

<% control PageForCurrentLocale(footer) %>
$Content
<% end_control %>

Greetings
craesh

Avatar
Juanitou

Community Member, 323 Posts

29 August 2009 at 5:26am

Ah! I understand now. Thanks for the contribution, it's most useful.

Best regards,
Juan

Avatar
craesh

Community Member, 25 Posts

29 August 2009 at 6:43am

Thanks for your comment. I've opened a new Ticket for this. Maybe it will get included in future releases.

Greetings!
craesh