Published on: 14 April, 2016

Multiple Languages Support and Localization in DNN

Posted by andy | 1230 views 0 likes 0 favourites 1 comments
Tumblr Digg Google Plus

DNN has a built in Localization framework to help you create website with multiple languages support. By default, the common HTML module shipped in DNN installation does support this feature. Unfortunately, not all of the third party modules available would be able to support multiple languages. If they do, usually they only support the languages via resx files. Those files are used to translate label text only, while the content is usually saved into the database directly.

How to setup multiple languages in DNN?

The default language in DNN is EN-US (USA Language version), if you want to add a new language, you will need to login as host super account and go to Admin > Languages Menu.

To add a new language, click the Add New Language button.

A pop up window will appear and you can select the available languages. Please select the English Name, so you can easily read the language selection combo text. The DNN team should make this option as default rather than the native name, as it is hard to guess the text.

Once you have add the new language, you will notice that there are two new flags available on the DNN skin. Notes: as we are using the default DNN skin, those flags will be automatically displayed. If you create your own skin or purchase it from third party vendors, you want may to manually add it on the skin. Here is the sample on how to do it. What you need to do is to include the DNN skin object at the top of your skin.ascx file.

//include this skin object tag
<%@ Register TagPrefix="dnn" TagName="LANGUAGE" Src="~/Admin/Skins/Language.ascx" %>

//Once you have add the skin object tag, you can now include the language tag to any location of your skin html.
<dnn:LANGUAGE runat="server" id="LANGUAGE1"  showMenu="False" showLinks="True" />

As you can see from above image, we do have two different languages supported on the site. The English language will still be the default language on the site. If you do want to change, the second language option become the default site language, you will need to go to Admin > Languages menu and click the Settings tab. Then select your preferred language as the default site language.

How localization work in DNN?

The way how localization works in DNN is by using the resx files. Those files are placed under App_LocalResources folder. The easy way to edit or add localization is by using Visual Studio program. If you do not have one, you can download the community version to do this. The simple example you can see on how localization has been applied in DNN is by looking on the DesktopModules folders. Let see the example of HTML module. All the resources files are identical with the module ascx files name.

DNN has a built in resource label skin object, you can use this one to display the localization text. There is a tag called ID in this skin object which represents the ID of the resource label. The way how it works is, the DNN will look for the ID value, in this example, the value is lblResourceText, DNN will search if there is resource record defined in the resx file named lblResourceText, if it does find the record, it will use the defined value specified in the file otherwise it will use the default value tag specified in the Label object which contains the value Resource Text.

//this is the skin label object
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>

//an example on how to use the label text.
<dnn:Label id="lblResourceText" runat="server" Text="Resource Text" />

If you are a programmer, you can set the localization via behind code by using the following code. The LocalResourceFile represents the resource file name. For example: if your control name is MyControl.ascx then the resource file name will be MyControl.ascx.resx

Localization.GetString("ResourceTextName", LocalResourceFile);
Comments
JER
Commented on: 03 Aug, 2016 10:12:29 AM
Great article. What I don't understand is how to make the page actually display the second language. I have a fresh install of DNN8. My home page is the default for a fresh American English install. I chose Polski as my second language. I have the flag in the navbar. Nothing happens to my page when I click the polish flag. All the text on the home page is still displayed in English.
Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.
Related Articles
Published on: 22 May, 2016
If you want to use Gmail SMTP in your DNN website, this can be easily done by specifying the correct port 587 in the SMTP settings. Unfortunately, there is no port number field supplied in the SMTP settings form. So in order to include the port number, you just need to add the smtp.gmail.com:587 in the SMTP settings.
Published on: 21 May, 2016
There are two options to setup the skin template into the DNN website, the first option is to globally set all pages using the default skin template and the second option is to set the skin template manually to each page. Usually when you create skin templates in DNN, there are at least 2 skins will be created. One would be the home page skin and the rest is the generic page skin.