When you localize a widget, it pulls the language information from the language folder. If you put the language information in the Resources.xml file in the folder, then you do not have to specify which file to pull resources from in the code file. However, if you put your language specific text into a custom file, for example NewWidget_Resources.xml, then you will need to use the following procedure.

To localize a widget:

  1. Create a resource file in the ~/Languages/{Your Language}/ folder. When you create a resource file, you ensure that it will not be overwritten. The resource file in the following example is called NewWidget.xml. 

<?xml version="1.0" encoding="UTF-8" ?>

<root>
<resource name="NewWidget_MyInfoConfigurableWidget_FragmentName">My Info 2 (From Resource File)</resource>
<resource name="NewWidget_MyInfoConfigurableWidget_FragmentDescription">This widget displays my personal information. (Configurable)</resource>
<resource name="NewWidget_MyInfoConfigurableWidget_Title">Widget Title</resource>
<resource name="NewWidget_MyInfoConfigurableWidget_YourName_Title">Name</resource>
<resource name="NewWidget_MyInfoConfigurableWidget_YourName_Default">Your Name</resource>
<resource name="NewWidget_MyInfoConfigurableWidget_Location_Title">Location</resource>
<resource name="NewWidget_MyInfoConfigurableWidget_Location_Default">Your Location</resource>
<resource name="NewWidget_MyInfoConfigurableWidget_Occupation_Title">Occupation</resource>
<resource name="NewWidget_MyInfoConfigurableWidget_Occupation_Default">Your Occupation</resource>
</root>
  • In the widget code file, use the CommunityServer.Components.ResourceManager class to retrieve localized strings from your Resource file (~/Languages/{your language}/{YourFile.xml}).

public override stringFragmentDescription
{
get
{
CommunityServer.Components.ResourceManager.GetString(
"NewWidget_MyInfoConfigurableWidget_FragmentDescription"
, "NewWidget.xml");
}
}
  • In the User Control section, use the <CSControl:ResourceControl.. /> to retrieve localized strings from your Resource file:

<%@ Control Language="C#"AutoEventWireup="true" %>
<div>
<p>
<b><CSControl:ResourceControl runat="server"ResourceName="NewWidget_MyInfoConfigurableWidget_YourName_Title" ResourceFile="NewWidget.xml" /></b>
<cscontrol:configurablecontentfragmentdata property="Name"runat="server" />
</p>
<p>
<b><CSControl:ResourceControl runat="server"ResourceName="NewWidget_MyInfoConfigurableWidget_Location_Title" ResourceFile="NewWidget.xml" /></b>
<cscontrol:configurablecontentfragmentdata property="Location"runat="server" />
</p>
<p>
<b><CSControl:ResourceControl runat="server"ResourceName="NewWidget_MyInfoConfigurableWidget_Occupation_Title" ResourceFile="NewWidget.xml" /></b>
<cscontrol:configurablecontentfragmentdata property="Occupation"runat="server" />
</p>
</div>
  • Ensure the the strings are set up in the resources.xml file. Based on the same code above, the widget may look something like this: