Localization

Weavy is designed to support multiple languages, cultures and regions. The default user interface language is English, but it's possible to configure additional languages by adding resource files for the language(s) you want to support.

Resource files

Weavy uses resource files for separating localizable strings from code. These resource files contain key/value pairs, where key is the English string that should be translated, and value is the translated string.

The server SDK includes two template files (Resources\Resources.txt and Scripts/resources\resources.js) containing all strings that must be translated.

For example, to translate Weavy to Swedish you would create copies of these files and name them Resources.sv.txt and resources.sv.js (sv is the language code for Swedish). You would then translate all keys in the files into Swedish.

Placeholders

Some keys in the resource files contain curly brackets { and }. This indicates a placeholder that should not be removed when translating. For example, the English string "{0} is required" translated to Swedish would look like this:

{0} is required={0} måste fyllas i

Pluralization

Resource keys with placeholders that come in pairs, where one item ends with .n, are used to show the correct plural form of a string to the user. For example "1 page" vs "2 pages".

{0} page={0} sida
{0} page.n={0} sidor

Most languages only have 2 plural forms, one for the singular case and one for everything else, but other languages have different plural rules. See Localization and Plurals for for more information.

Configuration

When you've created resource files for the language you want to support, you must also configure Weavy to use this language. This is done with the weavy.languages configuration setting. For example to configure Weavy to use both English and Swedish you would use the following configuration setting:

<add key="weavy.languages" value="en, sv" />

When more than one language is specified, the first language in the list is the "default" language that will be used for users that haven't specified a language preference on their profile page.

Usage

In order for Weavy to lookup localized strings for the current language you should use our localization helpers.

Localizing views

In .cshtml views you can use the T["key"] helper to look up a localized string. For example:

<p>@T["This is a resource key"]</p>

Localizing javascript

In javascript files you can use the wvy.t("key") helper to look up a localized string. For example:

var localized = wvy.t("This is a resource key");