LanguageManager using DynamicDataStore

by: Anders Hattestad

I have looked forward to the new propertbag concept in CMS6. I have always wanted a store for different kind of data/settings that are not pages. One area I find troublesome is the language xml files. If you have more than one server you need to copy those files to each of them. And there aint no easy method of say that this text should be changeble based on languages without having to code it inside a xml file.

For those of you that haven't used LangaugeManger a lot it has basically one function Translate(key). If you provide a key (like /search/searchbutton) it will look up in the xml files inside the lang/ folder and find that text in the current Threads language. If the text aint there it will return a error messages.

So on friday when i got a mail with a download link, I started the download right away. But something went wrong with the install procedure or something else, cause my OS crashed and I needed a total reinstall. Finnaly I’m on Windows 7 :)

First I made a small LanguageManagerStore class

image that instead of retrieving data from xml files, it uses the DataStore to get the LangaugeItem objectimage

If you want to see how to do it you can check out Ted Nybergs blog post

Then I thought of a lot of different ways of intercept the existing method in EPiServers  LangaugeManger, but I am stucked here. if only one of the methods inside that class could be virtual it would have made this code so much better. Then I could have change all places that depends on LangaugeManger and translate (witch is as far as I know every language depended text). So please devs add virtual to methods.

I therefore had to make  two base classes(TemplatePage, UserControlBase) that override the Translate method and use my Translate method.

  • TranslatePageBase : TemplatePage
  • TranslateUserControl:UserControlBase

image

Then I made Three  different ControlAdapters that will change text.

  • <episerver:Translate …. />
    overrides the Render method and used my Translate method

Then i made 2 other that extend the

  • HtmlControls
  • WebControls

And if you add an attribute to a control called translate=”true” it will take the text inside and use that text as a key and also add the text to the data store.

image

This will render like this

image

Editing

I then made a small edit page that shows all the keys in all language and display it in a grid.

image

 

Download

You can check the code out here

https://www.coderesort.com/svn/epicode/Itera.Language/trunk

22 October 2009


Comments

  1. Cool example! I'm with you on the cry for more virtual methods - I know Joel Abrahamsson feels the same way! :) By the way, it seems the link to the DDS post got the wrong URL, it should be: http://tednyberg.com/post/Save-and-retrieve-objects-to-and-from-the-EPiServer-Dynamic-Data-Store.aspx
Post a comment    
User verification Image for user verification  
EPiTrace logger