Making SilverStripe 3.x Multilanguage

Because of the code changes from 2.4 to 3.x you need to do more to make your site translatable than just adding just one line to _config.php. In this post I tell how to do it!

  1. Add lines to _config.php:
    // Set the site locale
    i18n::set_locale('en_US');
    Translatable::set_default_locale('en_US');
    SiteTree::add_extension('Translatable');
    SiteConfig::add_extension('Translatable');
  2. Download the translatable module from github
  3. Upload the content of github zip file to folder named ‘translatable’
  4. Now some how to code for PHP files:
    // Simple string translation
    _t('LeftAndMain.FILESIMAGES','Files & Images');
    
    // Using the natural languate comment parameter to supply additional context information to translators
    _t('LeftAndMain.HELLO','Site content','Menu title');
    
    // Using injection to add variables into the translated strings.
    _t('CMSMain.RESTORED',
        "Restored {value} successfully",
        'This is a message when restoring a broken part of the CMS',
        array('value' => $itemRestored)
    );
  5. Inside Theme files .ss u need to use <%t params %>:
    // Simple string translation
    <%t Namespace.Entity "String to translate" %>
    
    // Using the natural languate comment parameter to supply additional context information to translators
    <%t SearchResults.NoResult "There are no results matching your query." is "A message displayed to users when the search produces no results." %>
  6. After making your theme and php files and adding module don’t forget to build the database using www.yoursitename.com/dev/build?flush=1

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 × 6 =

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>