Documentation

Install

Multilingual Module is expected to be installed on a fresh db. You can however use the migrationtask (for Multilingual Module 2.0) to migrate a DB to work with MultilingualPages. Dataobjects can not be migrated because they use a completly new set of IDs per Object. You will have to start fresh with your multilingual dataobjects (you might do an own migration thru sql queries however, there is just no bundled task for it). 

 

  1. Add the module to the root of your site and name it to "multilingual" if not already namned that way.
  2. - Make your Page class extend from MultilingualPage (both class and controller)
    - Make SiteConfig extend MultilingualSiteConfig
    - Make all Dataobjects you want in multilingual extend from MultilingualDataObject instead of DataObject.
  3. Open up /multilingual/_config.php and set the module up
  4. Do /dev/build/
  5. You can also run a task /dev/tasks/ActivateLanguageTask?en=1 if you want all pages (that extend multilingualpage) to be viewable for english.
  6. (Only for Multilingual Module 2.0 for SS 3.0.2 and above) If you are not starting from a fresh DB you can use the MigrateToMultilingualTask, where all Pages in the DB will be migrated to MultilingualPages. If task not used it might look like you ended up without pages after an dev/build in your site. 

This means that all pages in your site must extend from multilingualpage. This doesnt mean that all pages must be multilingual, but is a prerequisite for the module to work. Dataobject are however optional. Those dataobject that make sense to translate you just extend from MultilingualDataObject. 

Set up

Open up /multilingual/_config.php. Here's an example of how you can set it up:

Multilingual::set_default_lang("en");
Multilingual::set_langs(array(	
	"English"=>array("en"=>"en_GB"),
	"Swedish"=>array("sv"=>"sv_SE"),
	"German"=>array("de"=>"de_DE") 
));

First you choose default language. This is the language that will be the base in your admin as well. All the other languages will be translated in fields with a lang sufffix. Ex: Title_deTitle_sv. The default language is simply Title.

Setting multilingual fields

You set multilingual fields from the class that has the field you want to translate. For instance: If you want make a Page db-field called "MyField" multilingual, you just add a static $multilingual_fields=array("MyField"); on that page. Ex:

class Page extends MultilingualPage{
	static $db=array("BackgroundInfo"=>"Text");
	static $multilingual_fields=array("BackgroundInfo");
	...
}

 

Setting multilingual fields for SiteTree & SiteConfig

The functions Multilingual_SiteTree::set_multilingal_fields and Multilingual_SiteConfig::set_multilingal_fieldslets you set an array for the the core-classes as well You just set them in the _config.php file. Ex:

Multilingual_SiteTree::set_multilingal_fields(
array(
	"Title",		
	"MenuTitle",
	"Content",
	"MetaTitle",
	"MetaDescription",
	"MetaKeywords",
	"ExtraMeta",	
));

Translate URLsegments?

Add the option  

Multilingual::$use_URLSegment=true;

in _config.php before the enable() function.

Or for Multilingual Module 2.0 for Silverstripe 3 use 

Multilingual::use_multilingual_urlsegments(true);

Enable

Last but not least. 

Multilingual::enable();

Multilingual Dataobjects

The structure of the getCMSFields function in dataobjects must be something like this (they also must extend MultilingualDataObject):

function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTabs("Root.Main",array(
new TextField("Title","Title"),
new TextAreaField('Description', "Description"),
...
)
)
);
//for Mutlilingual Module 2.0 , SS 3.0.2 or higher
$this->doExtend("updateCMSFields",$fields, get_class());
// else
$this->extend('updateCMSFields', $fields);

return $fields;
 
}

Multilingual Pages

The structure of the getCMSFields function in pages must be something like this (it also must extend MultilingualPage):

function getCMSFields(){
	$fields = parent::getCMSFields();

//add your fields for the page here
	//for Multilingual Module 2.0, SS 3.0.2 or higher
	$this->doExtend("updateCMSFields",$fields, get_class());
	//else
$this->extend('updateCMSFields', $fields);
return $fields;
}

Activate languages

Lastly you can activate/deactivate objects for different languages in the "Settings tab" for the objects. The default is only to show the default language. There is also a task in dev/tasks that can activate a language for all objects.

Done!

Now you have a fully multilingual site still works as you expect to. The features are:

  • Non-default languages uses a URL lang-prefix. Ex: /sv/about-us/contact-us
  • Possibility to translate URLSegments. Ex: /sv/om-oss/contact-us. And unlike Translatable module - its still the same page.
  • In behavior-tab in the cms you can select for which languages the page should be visible for. You can thus select to show the page only in english for instance.
  • Multilingual dataobjects. All you complextablefields that show a dataobject that extends from multilinugaldataobject will show you options for different languages.
  • All fields that havent yet been translated fall back to the original language. Ex if Content hasn't been set for a page, it falls back to the default language. For instance: the swedish documentation page has no page Content, so it falls back to the original language - en.

Other tips

You can add 

static $hide_ancestor=true;

In Page.php to hide the "MultilingualPage" page type to be creatable in Admin.

Good Luck and enjoy!

/Kreationsbyrån