How to internationalize Sense/Net

From Sense/Net Wiki
(Redirected from How to globalize Sense/Net)
Jump to: navigation, search
  • 100%
  • 6.2
  • Enterprise
  • Community
  • Planned


Sense/Net pages and content can be internationalized and thus portal builders can provide ECM solutions for their customers with content, pages or any kind of feature on different languages. This guide shows you how to internationalize Sense/Net ECMS and allow the users to translate (localize) anything on the portal.


To create internationalized views, renderers, pagetemplates etc., simply use string resource keys in your files instead of hardcoded strings. This will allow others to translate (localize) your feature to any language without modifying the source code or view.

For example when you are working with a content view, add the resource key to the ascx:

<span><%= HttpContext.GetGlobalResourceObject("MyClass", "MyStringResource") %></span>

The string resource will appear with its default display on the UI:

String resource on UI

If you are a member of the Administrators group, you can switch the portal to resource editing mode to highlight your string resource and edit it with Resource Editor

After saving the changes, the correct text will appear on the currentt language.

Final string resource

As you can see you don't have to bother with the Resource xml content. The Resource content is automatically modified in the background, and also: if a resource file for the given classname did not exist yet, it is automatically created:

Resource content automatically created

Resource key formats

The way of using resource keys in your code depends on the file or type of the component you are editing. In Sense/Net you will have to use one of the following code formats to access resources.

It is advisable to use string constants instead of string literals when defining resource classes and keys so you may use the same resource class names and keys more than once.

Sense/Net resource manager format

SenseNetResourceManager class is responsible for managing string resources in Sense/Net ECMS. You are able to use this notation in source code:

var text = SenseNetResourceManager.Current.GetString("MyClass", "MyStringResource");

Or as an inline code in an ascx control:

<%= SenseNetResourceManager.Current.GetString("$MyClass,MyStringResource") %>

Sense/Net short resource format

This is the shorter version of getting a resource. These methods internally will eventually call the methods above.

var text1 = SNSR.Get("MyClass", "MyStringResource");
var text2 = SNSR.Get("$MyClass,MyStringResource");

ASP.NET $ notation

This format is used in ascx controls in case of server control attributes.

<%$ Resources:MyClass, MyStringResource %>

Sense/Net $ notation

In case of localizable content fields (e.g. Display name or Description) and portlet titles you have to use the following format:


ASP.NET global resource format

This is the standard ASP.NET method of getting a resource. It works but it is far more inconvenient than the other formats.

Source code:

var text = HttpContext.GetGlobalResourceObject("MyClass", "MyStringResource") as string;

Or as an inline code in an ascx control

<%= GetGlobalResourceObject("MyClass", "MyStringResource") %>

Internationalize content views

Portal builders can use the standard ASP.NET resource notation for string resources in attributes (properties) of server controls.

<sn:ActionLinkButton ID="ActionLinkButton1" runat='server' NodePath='<%# Eval("Path") %>' ActionName='checkin' 
Tooltip='<%$ Resources: Portal, CheckIn %>' /> 
<asp:Button CssClass="sn-submit" ID="SearchButton" Text='<%$ Resources: Portal, SearchButtonTitle %>' runat="server" />

The only way of displaying a localized string in an ASP.NET databinding environment (e.g. in case of a ListView item template) is to use an asp:Literal server control and set its Text property with the resource notation above.

When there is no server control in the ascx, you can use inline code to display a localized string:

<%= SenseNetResourceManager.Current.GetString("$MyClass,MyStringResource") %>

Internationalize XSLT renderers

To be able to display localized string in XSLT files, SenseNet.Portal.UI.ContentTools namespace must be included in the stylesheet.


The texts in the renderer can be internationalized using this notation (the string parameter must be in Sense/Net $ resource notation):

<xsl:value-of select="snc:GetResourceString('$Renderers, Fields')"/>

Internationalize portlet titles

Portlet titles can be internationalized also. You can set the title of a portlet by switching the page to edit mode, editing the portlet and providing a resource key as the Portlet title in ASP.NET $ notation.

Localized portlet title

Internationalize portlet properties

Sense/Net has a couple of built-in portlet property controls that are already internationalized. If you, as a developer are creating a custom control for displaying a portlet property, you will have to add the necessary resources to your source code or javascript files. All custom portlet property controls have to implement the interface IEditorPartField.

When you have a portlet property of type Enum, you are able to define string resource values for every enumeration item. See this article for more information on creating enum string resources.

Internationalize Content Type Definition

Portal builders and developers are able to internationalize content types. Please visit this article for more info on that topic.

Internationalize page templates

The standard ASP.NET notation for string resources can be used also in pagetemplates to define a string resource:

<snpe:TagCloudPortlet Title="&lt;%$ Resources: Portal, TagCloudPortlet_Title %&gt;" ID="TagCloud2" 
runat="server" BindTarget="CurrentWorkspace" ContentViewPath="/Root/Global/contentviews/Blog/TagCloudPortlet.ascx" />

Or you can use inline code:

<%= HttpContext.GetGlobalResourceObject("MyClass", "MyStringResource") %>

Internationalize content

Content or content template display names and descriptions are also internationalizable by setting a resource key as their display name or description:

Localized content template

After saving the content the edit views will show a slightly different field control in case of the DisplayName field that allows to edit the resources and the field value as well. You can read more about this here:

Please note that when a new content is created on the user interface using a internationalized content template, the display name of the new content will not be internationalized. It will contain the localized text in the language of the creator user.

Internationalize actions

Sense/Net ECMS uses Actions to enable navigation and let users perform operations in a very convenient way. If you want to display localized action names, please follow the instructions in this article on how to do that.

Internationalize javascripts

In case you are developing custom javascript modules or controls, you will find it useful that in Sense/Net you are able to internationalize your javascript files. Please visit the following article on how to do that.

Internationalize field controls and cell templates

Field control templates can be internationalized the same way as content views.

    <%=GetGlobalResourceObject("FieldControlTemplates", "CustomSetting")%>
    <input type="submit" value="<%= GetGlobalResourceObject("FieldControlTemplates", "Inherit") %>" />

In cell templates you can use resources only in server control attributes.

<sn:ActionLinkButton ID="ActionLinkButton1" runat='server' NodePath='<%# Eval("Path") %>' 
ActionName='checkin' Tooltip='<%$ Resources: Portal, CheckIn %>' />

Naming conventions

  • When creating your own custom feature, please define your own resource classes and do not use Sens/Net core resource class names (e.g. Portal, Actions, Controls) to avoid resource collisions.
  • It is advisable to place one resource class into one resource xml to make resource editing easier.
  • If you want to use your resources in javascript files, please define resource classes containing as few resource keys as possible to avoid rendering huge html content.

Related links


There are no external references for this article.