Jump to:

23453 Posts in 18902 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » i18n 99% there

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

Page: 1 2
Go to End
Author Topic: 944 Views
  • novaweb
    Avatar
    Community Member
    115 Posts

    i18n 99% there Link to this post

    Greetings fellow SilverStrippers,

    I have a project I am working which requires internationalization.

    First time using i18n, following the doc.

    If I set i18n::set_locale in mysite/_config.php to "de_DE" - then I can see my translation successfully.

    However if I change this back to "en_US" then try visit localhost/mywebpage?locale=de_DE then I don't see the translation.

    I thought appending the locale parameter to the URL was meant to be the "language switcher"

    Can you see any wrongdoings in my _config.php file?

    // Set the site locale
    i18n::set_locale('en_US');
    date_default_timezone_set('Pacific/Auckland');
    i18n::default_locale('en_US');
    i18n::set_date_format('dd/MM/YYYY');
    i18n::set_time_format('HH:mm');
    Translatable::set_default_locale('en_US');

    Cheers!

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: i18n 99% there Link to this post

    I thought appending the locale parameter to the URL was meant to be the "language switcher"

    Not so, I believe there is a "small hack" to do this on the forum or the dev list. The correct was is to use the CMS to create teh page transations (using the special tab) and then including the <% control Transalations %> to show them in the template.

    Try reading this...

    http://www.ssbits.com/tutorials/2011/using-translatable-to-create-a-simple-multilingual-site/

  • novaweb
    Avatar
    Community Member
    115 Posts

    Re: i18n 99% there Link to this post

    The content that I am attempting to translate is in the templates, not in the database. I am pretty sure I have to use i18n and not Translatable.

    For anyone who attempts this, here is my solution:

    Make sure i18n::set_locale() is not set in your mysite/_config.php, then in Page:

    public function init() {
        parent::init();
        self::languageSwitcher();
       }
       
       
       function languageSwitcher() {
          if(isset($_GET['locale'])){
             $lang = $_GET['locale'];
             $_SESSION['locale'] = $lang;
             return i18n::set_locale($_SESSION['locale']);      
          }
          if(isset($_SESSION['locale'])){
             return i18n::set_locale($_SESSION['locale']);
          }
       }

    Thanks guys!

  • novaweb
    Avatar
    Community Member
    115 Posts

    Re: i18n 99% there Link to this post

    And this in your template:

    <div id="LanguageSelector">
       <ul>
          <li><a href='{$URLSegment}?locale=en_US'>English</a></li>
          <li><a href='{$URLSegment}?locale=de_DE'>German</a></li>
       </ul>
    </div>

  • Josua
    Avatar
    Community Member
    86 Posts

    Re: i18n 99% there Link to this post

    Hi!

    Unfortunately, this does not work very well with the hardcoded pages of SilverStripe (Security/login, Security/lostpassword, Security/passwordsent, ....).

    See http://open.silverstripe.org/ticket/7056

    Regards,
    Jose

  • novaweb
    Avatar
    Community Member
    115 Posts

    Re: i18n 99% there Link to this post

    Hola Jose,

    In my project I have used custom extensions on the login form etc, provided you do this you can make the login pages i18n enabled

    Cheers,
    Josh

  • Josua
    Avatar
    Community Member
    86 Posts

    Re: i18n 99% there Link to this post

    Hi Josh!

    Where are those extensions?
    Do you have created?

    However, the problem is not only in these pages, other pages, for example, in the forum, that they are also hardcoded.

    Thanks Josh,

    Regards,
    Jose

  • novaweb
    Avatar
    Community Member
    115 Posts

    Re: i18n 99% there Link to this post

    Hi Jose,

    You need to create a CustomLoginPage, which just extends the normal Page class, with a Sign In form. This is just a normal form with EmailField and PasswordField.

    The form's action should be doLogin

    My Custom Form is a bit too large and customized to share on here, but the tricky part of the doLogin logic is as follows:

    $authenticate = MemberAuthenticator::authenticate(array("Email"=>$data['Email'], "Password"=>$data['password']));
       if($authenticate){
          $authenticate->login();
    // then do a redirect here
    }

    Good luck and let me know if you get stuck.

    944 Views
Page: 1 2
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.