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 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.

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 (3 years ago)

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

  • Marcus Dalgren
    11/03/2011 3:47pm (3 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.

Advertisement

Site of the Month

Find SSbits on

Top Contributers

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

View full leaderboard


Advertisement