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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[SOLVED] Multilanguage Site and Forms


Reply


5 Posts   950 Views

Avatar
biapar

Forum Moderator, 435 Posts

26 February 2011 at 2:33am

Hi,

I've done a multilanguage site and I made a form ( layout and class ) for italian lang, but I need the same form for eng lang...
I wish to solve the problem of traslating data and label and redirect page ( after submit form ) to landing page under right language site...

if ($flag_ricerca_ok==1)
Director::redirect('disponibilita-en/');
//Director::redirect('disponibilita-'.$lang.'/');
//echo "Disponibile";
else
Director::redirect('no-disponibilita-en/');
//Director::redirect($langSegment.'no-disponibilita-'.$lang.'/');
//echo "No Dispo";
}


So:

In Layout/HomePage.ss

<% if Locale == "en_GB" %>
<!-- Inglese Search Form -->
$DisponibilitaStep1EN_Form
<% end_if %>
<% if Locale == "it_IT" %>
$DisponibilitaStep1Form
<% end_if %>


and into Include dir , I've DisponibilitaStep1EN_Form.ss . The DisponibilitaStep1Form is rendered but other not when I'm in english site.

Under my_site/code, I've create class :

<?php
class DisponibilitaStep1EN_Form extends Form {.....

Thanks

Avatar
Gelert

Community Member, 8 Posts

26 February 2011 at 10:41pm

I have the same problem, I'd be interested to see how to solve it.

I have a Sidebar form which needs to direct English searches to one URL and when it the form is displayed in Italian it needs to direct submits to a different URL holding the Italian versions of the pages.

Avatar
biapar

Forum Moderator, 435 Posts

28 February 2011 at 6:47am

Solved.

In my form class, I wrote:

$language = Director::get_current_page()->Locale;
$lang = substr($language, 0, 2);
      
if ($lang == 'en')
Director::redirect('availability/');
else
Director::redirect('disponibilita-'.$lang.'/');

Bye

Avatar
Gelert

Community Member, 8 Posts

28 February 2011 at 10:45pm

Edited: 28/02/2011 10:45pm

Thank you, that has solved my problem too.

I altered the code slightly and put it on my custom form submit function:

function submit($data, $form) {
   $language = Director::get_current_page()->Locale;

   switch ($language) {
      case "it_IT": $form_processor_url = "italianFormProcessor"; break;
      case "en_GB": $form_processor_url = "englishFormProcessor"; break;
      default: $form_processor_url = "englishFormProcessor"; break; // not needed, but just in case
   }

   Director::redirect(Director::baseURL(). $form_processor_url . "/?element1=".$somethingID);
} // end func

That's solved it. Now all I need to do is get the form front end working in Italian too! That bit shouldn't be so difficult.

Thank you so much.

Avatar
biapar

Forum Moderator, 435 Posts

28 February 2011 at 10:52pm

See http://www.silverstripe.org/general-questions/show/15949