Snippets - Little bits of code to make you happy
Overriding Silverstripes language files with your ownTweet
28 October 2009 | |
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 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.