Home

Localization

Web pages can be localized by replacing text with named placeholders in the form ##placeholder##

The placeholder name can be anything you like. When the template is rendered, the translation provider will be called. You should provide your own translation provider by creating a class implementing the ITranslationProvider interface, which defines the following methods:

  • string GetTranslation(string tag, string viewName, string languageCode)
  • string[] GetAvailableLanguages()

The GetTranslation() method will be called for each translation tag in the template. The language passed to the method is the 2-letter ISO language code ("en","fr", "nl", ...).

Parameters in translations

To be completed

Switching languages

You can set the language from code or by embedding the language code in the URL.

Setting the language in code

In code, you can set the language by setting the LanguageCode property of the session object, which is available in the controller class or in the WebAppContext class.

For example:

Session.LanguageCode = "en";
or
WebAppContext.Session.LanguageCode = "en";

The language is set at session level, and at the same time it is stored in a permanent cookie. This means that when the site visitor returns to the site, the language setting will be remembered (unless the user deleted all cookies for your site)

Setting the language from the URL

It is also possible to embed the language code in the URL. In that case, the first "slashed part" (/../) represents the language code to be used for the page. For example:

http://www.vicimvcdemo.com/en/products => displays the page in English
http://www.vicimvcdemo.com/fr/products => displays the page in French

To enable this, you have to set the "UseLanguagePath" configuration property to true. (see the section on configuration for more information on how to set configuration options.

If the UseLanguagePath property is set, and no language code is specified, the language is taken from the session or the user's cookie. This means that whenever a page is rendered in a specific language for a user (or session), this language will be used for subsequent page requests, unless a new language is explicitly set. If no language code is embedded in the URL, and there is no previously saved language, the default language code will be used (set via the configuration option "DefaultLanguage").

Retrieving translations from code

If you need to translate some tags from code, you can call the registered translation provider by using the TranslationHelper class:

string TranslationHelper.GetTranslation(string viewName, string tag)

This will return the translation of the given tag using the current session's language. The view name is required.

string TranslationHelper.ParseTranslations(string inputString, string viewName)

The ParseTranslations() method takes a string that contains one or more tagged expressions in the form ##tag##, similar to how tags are used in template files.

For example: (let's assume the current language is dutch, and the 'FirstName' and 'Age' tags are handled by the translation provider)

string translated = TranslationHelper.ParseTranslations("##FirstName##, ##Age##", View.Name)

// translated == "Naam, Leeftijd".