Developer FAQ
I want to output different strings and XHTML markup (like images) in my Layout Templates and XSLT output depending on the language of the page being rendered. I.e. if my XSLT is executed on a Dutch page I want to output Dutch strings and images etc.
Answer:
Composite C1 version 1.2 come with two new tags which can be used in markup like Layout Template XHTML and XSLT; one for "switching" between markup blocks and one for emitting strings from a central string store (like a .NET resource file).
<lang:switch />
This tag define that a specific string or markup fragment should be selected based on the language of the page being rendered. This enables you to write localized content inline in your markup and is a quick way to localize content and is also the only construct which lets you define language specific markup elements.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lang="http://www.composite.net/ns/localization/1.0" > <head /> <body> <lang:switch> <lang:when culture="da-DK"> <img src="~/dk-logo.png" title="Dansk logo" /> </lang:when> <lang:when culture="en-US"> <img src="~/us-logo.png" title="American logo" /> </lang:when> <lang:default>No logo available</lang:default> </lang:switch> </body> </html>
<lang:string key="…" />
The following markup will emit a string named "Hello" loaded from an ASP.NET Global Resource File named "MyResources":
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lang="http://www.composite.net/ns/localization/1.0" > <head /> <body> <h1> <lang:string key="Resource, Resources.MyResources.Hello" /> </h1> </body> </html>
The strings you can load all come from the C1 String Resource system (a provider based extendable system) which is used by both the C1 front- and back-end to localize UI. The key value is what identified the string and has the format “[provider name], [provider specific key]".
By default C1 ships with a String Resource Provider named “Resource", which will read strings from any .Net resource files, including ASP.NET “Global Resources Files", but if you would like to read string from another store you can do so.
You can read more about ASP.NET Global Resources here: http://msdn.microsoft.com/en-us/library/ms227427.aspx
Using the <lang:string />
element make sense to use when you would like to keep all strings specific to languages in a central repository for easy language versioning.