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.

Template Questions

multilingual footer


Reply

7 Posts   1511 Views

Avatar
craesh

28 August 2009 at 3:40am (Last edited: 28 August 2009 4:14am), Community Member, 25 Posts

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
Taffy

28 August 2009 at 3:49am Community Member, 119 Posts

Have a look at http://doc.silverstripe.com/doku.php?id=multilingualcontent#templates & http://doc.silverstripe.com/doku.php?id=i18n#the_t_function

Avatar
craesh

28 August 2009 at 4:11am Community Member, 25 Posts

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

28 August 2009 at 5:55am Community Member, 323 Posts

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

28 August 2009 at 11:20pm Community Member, 25 Posts

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

29 August 2009 at 5:26am Community Member, 323 Posts

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

Best regards,
Juan

Avatar
craesh

29 August 2009 at 6:43am Community Member, 25 Posts

Thanks for your comment. I've opened a new [url=http://open.silverstripe.com/ticket/4530]Ticket[/url] for this. Maybe it will get included in future releases.

Greetings!
craesh