SSbits - Home page
Site by Carbon Crayon
Submit a Post >

Snippets - Little bits of code to make you happy

Overriding Silverstripes language files with your own

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 In order to guarantee that your translation works you will have to translate both and then add that info to as well.

Marcus Dalgren avatar

Marcus Dalgren

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

  • Bart van Irsel
    11/03/2011 3:45pm (6 years ago)

    Thanks! This post is from a long time ago but today it made my day :)

  • Marcus Dalgren
    11/03/2011 3:47pm (6 years ago)

    Awesome to hear it helped you! :D
    I scratched my head over this for a long time before I realized how it worked so it's really nice to hear it's helping others.

Post a comment ...

You cannot post comments until you have logged in. Login Here.


Site of the Month

Find SSbits on

Top Contributers

Rank Avatar Name
1 article image Aram Balakjian
2 article image wfacewomens
3 article image Daniel Hensby
4 article image Marcus Dalgren
5 article image ryduhartchas
6 article image Hamish Campbell
7 article image Ty Barho
8 article image Martijn van Nieuwenhoven
9 article image Darren-Lee
10 article image Roman Schmid

View full leaderboard