How to Make Multilanguage Pages in SilverStripe

  1. Make site translatable. go to mysite/_config.php and add lines:
    // Set the site default locale
    i18n::set_locale('en_US');
    i18n::enable(); 
    global $allowed_i18n;
    // Set the site allowed locales
    $allowed_i18n = array( 'de' => "de_DE", 'en' => "en_US");
    // Set the site default locale
    Translatable::set_default_locale('en_US');
    // Activate translatable and make siteconfig translatable
    Object::add_extension('SiteTree', 'Translatable');
    Object::add_extension('SiteConfig', 'Translatable');
    
    
  2. In mysite/code/page.php change code on page_controller:
    class Page_Controller extends ContentController {
        public function init() {
            parent::init();
    
            if($this->dataRecord->hasExtension('Translatable')) {
                i18n::set_locale($this->dataRecord->Locale);
            }
        }
    }
  3. Make folder named lang in to mysite folder
  4. Make locale named file to lang folder (example:en_US.php)
  5. Add translation codes to mysite/lang/en_US.php like so:
    <?php
    global $lang;
    //Page.ss translated fields
    $lang['en_US']['Page.ss']['WAYTO'] = 'Find the way...';
    $lang['en_US']['Otherthemefilename.ss']['TRANSLATABLEFIELD'] = 'Translatable field translation';
    
    ?>
  6. in you yourthemefile.ss (example Page.ss) use code for translatable like so:
    <% _t('WAYTO','Find the way...') %> //this part add the translation for WAYTO in your theme file.
  7. Flush your website cache to make the changes viewable:
    http://www.yoursite.com/?flush=all

Looking for quality SilverStripe Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , | Posted under SilverStripe CMS | RSS 2.0

Author Spotlight

Teet Bergmann

Teet Bergmann

I'm a freelance web designer from Estonia. Mostly doing sites using Silverstripe, magento, prestashop, wordpress.

Leave a Reply

Your email address will not be published. Required fields are marked *


2 × = 12

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>