Home

Overriding Silverstripes language files with your own

The problem

In my most recent project I've had to run a site in another language (Swedish) and run into some issues which I thought I'd share with all of you.

Now Silverstripe probably comes with a translation for your language but even if it does, you probably want to change the wording of some of the phrases, so what to do?

You could of course hit up the language files for the relevant module or the ones in cms and sapphire but you really don't want to touch these files if you can help it.

The solution

The way Silverstripe reads the language files is by going through the directory looking for directories with a _config.php file and a lang directory. Later files in the chain overwrite the earlier files if they contain the same info so the solution is to create a folder which ends up last in the chain.

Personally I created a folder called zlang, put a _config.php file in the folder with just open and close PHP tags and then putting my language file in zlang/lang. After having done this I can override any translation I want to without touching the core files. You can of course name your folder whatever you want.

There is however one big bug in Silverstripes translations, namely that Silverstripe currently does not resolve nested include templates correctly. This means that if a template is included which in turn includes other templates Silverstripe will look for the translation in the included template and not the nested one.

An example of this is the PageComment-template which includes PageComment_single.ss. In order to guarantee that your translation works you will have to translate both PageComment_single.ss and then add that info to PageComment.ss as well.

About the Author

Name: Marcus Dalgren

Website: http://www.dragnet.se

Marcus is a web developer currently working at a small startup company called Dragnet in Gothenburg, Sweden. He also does freelance work for small to medium sized businesses in the Gothenburg area.

Comments (7)

  • Hi Marcus,

    thanks for the thread, it was helpful. Do you have more details on how to get the translation of nested fixed? There still is nothing to find in forum or tutorials on the silverstripe homepage.
    I would really appreciate it!

    Posted by Sunnybex, 27/08/2010 5:58am (13 days ago)

  • Thanks for sharing the informations i like it ,it is very usefull,really!and hope your websit is popular more and more!

    Posted by tiffany diamond necklace, 18/08/2010 10:28pm (21 days ago)

  • Actually doing that gives you mixed results just like the tutorial said and Ingo

    Posted by cheap bag, 02/08/2010 3:59am (1 month ago)

  • If I don't have many site text tweaks, I just put them in my mysite/_config.php file.

    Posted by Jeremy Shipman, 27/04/2010 12:43am (5 months ago)

  • To clarify even more, I tried doing it the way Martijn suggested at first and expected that to work.

    I personally think that anything placed under mysite should override anything else but right now it doesn't. At least not when it comes to translations.

    Posted by Marcus, 25/11/2009 9:56am (10 months ago)

  • Actually doing that gives you mixed results just like the tutorial said and Ingo confirmed this.

    Any translation arriving after the mysite-folder (sapphire for example) will override your translation file if they have entries for the same things.

    That's why you have to create a folder that ends up last if you want to guarantee that your own translations will override anything else.

    Posted by Marcus, 25/11/2009 9:52am (10 months ago)

  • You can also just add a xx_XX.php lang file in mysite/lang/ folder to override core or add missing translations without touching core files.

    Posted by Martijn, 22/11/2009 4:37am (10 months ago)

RSS feed for comments on this page RSS feed for all comments

Post your comment