I recently had a situation where many of the controls on my ASP.NET form (with a mixture of ASP.NET, custom & Coolite controls) needed size adjustment depending upon the language in which the form was rendered. Translation of content itself was not that such big a problem with ASP.NET’s wonderful support for Localization based on locale-specific resource files.
I tried many options, and I am presenting 3 of them here, that can prove useful in various situations:
- Themes
You can easily create a separate theme for controls for each locale you are targeting. You would then need to programatically load the theme for the page based on the user locale.
This is easy to accomplish using the Page’s Theme property. Remember, this poperty should be set in or before the Page’s PreInit event, or else your dynamic theme change would not work. - CSS Files
You can create separate CSS files for each locale and load them into the page on demand based on the user locale. Because of the richness of ASP.NET/Coolite controls, you would probably need a good understanding of CSS selectors to successfully apply classes on parts of rich controls like ASP.NET’s GridView or Coolite’s GridPanel.
However, I must say, with the many Css Class options these controls provide (e.g. AlternatingRowStyle-CssClass etc. for GridView, and Cls, ItemCls, LabelCls etc. for Coolite GridPanel), the task is easier even for a novice. - Localization itself
I have not seen any references to this on web. To my surprise, I can even specify properties like Width, Height etc. for controls in the resource files.
This makes it almost trivial to adjust content sizes for languages, as everything you need to change can be specified at a single place in the resource file.
In my opinion, a combination of locale specific css files and ASP.NET’s resource files is the most flexibile, and maintainable option. Themes might pose a challenge in the ordering of loading of the css files, plus if you want to conditionally include css files.
However, in my own solution, I am using a combination of all 3 above. Themes have provided me some customization that I was not able to achieve otherwise easily.
Recent Comments