You are here:   XsltDb > Help > Common > Localization
Register   |  Login

Localization

To create a multilingual module you can create an XML inside your configuration where all strings must be put. XsltDb provides a macro that helps to access this localization XML.

Example. Localized input form.

<xsl:variable name="_strings">
    <header>
        <value culture="en-US">Enter your <b>login</b> and <b>password</b>.</value>
        <value culture="ru-RU">Введите ваши <b>имя пользователя</b> и <b>пароль</b>.</value>
    </header>
    <label.login>
        <value culture="en-US">Login</value>
        <value culture="ru-RU">Имя пользователя</value>
    </label.login>
    <label.password>
        <value culture="en-US">Password</value>
        <value culture="ru-RU">Пароль</value>
    </label.password>
    <label.sign-in>
        <value culture="en-US">Sign In</value>
        <value culture="ru-RU">Войти</value>
    </label.sign-in>
</xsl:variable>
<xsl:variable name="strings" select="msxsl:node-set($_strings)"/>
 
{h{mdo:text(#strings/header#)}}<br/>
<table>
  <tr><td>{{#strings/label.login#}}</td><td><input/></td></tr>
  <tr><td>{{#strings/label.password#}}</td><td><input/></td></tr>
  <tr><td/><td><a href="#">{{#strings/label.sign-in#}}</a></td></tr>
</table>

Live Sample

Enter your login and password.
Login
Password
Sign In

In the code above you can se a localization macros instaed of strings. Localization macro looks like following;

# localization-variable-name / localization-item-tag #

This construction is replaced by XPath expression that retrieves required string. So, for the macro

#strings/header#

we have a replacement as follows:

mdo:coalesce(
$strings/header/value[@culture=mdo:culture()],
$strings/header/value[position()=1])

As you can see, XsltDb determines current language and tries to select a value for that language. if a value is not found it uses the first value. So it is better to put most frequent language on top.

Note, that the localization XML is declared in 2 stages:
  • first, we declare an XML fragment $_strings that contains out labels.
  • second, we create a queryable variable $strings that can be queried extremely fast. 
Total site hits: 17097