Jump to:

3392 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » multilingual footer

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

Page: 1
Go to End
Author Topic: 1413 Views
  • craesh
    Avatar
    Community Member
    25 Posts

    multilingual footer Link to this post

    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

  • Taffy
    Avatar
    Community Member
    119 Posts
  • craesh
    Avatar
    Community Member
    25 Posts

    Re: multilingual footer Link to this post

    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.

  • Juanitou
    Avatar
    Community Member
    322 Posts

    Re: multilingual footer Link to this post

    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…

  • craesh
    Avatar
    Community Member
    25 Posts

    Re: multilingual footer Link to this post

    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

  • Juanitou
    Avatar
    Community Member
    322 Posts

    Re: multilingual footer Link to this post

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

    Best regards,
    Juan

  • craesh
    Avatar
    Community Member
    25 Posts

    Re: multilingual footer Link to this post

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

    Greetings!
    craesh

    1413 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.