Create custom resource classes

In Sitefinity, resource classes are the main localization structure. Resource classes are used to distribute labels among multiple projects or to enable translations of labels and text inside widgets or modules. With its modules, Sitefinity provides predefined resource classes. When you create custom widgets or specific functionality, you need to create your own resource class. The following article demonstrates how to create a new resource class and register it in Sitefinity. 

Create custom resource class

To create a custom resource class, you add a class to your Sitefinity project. By convention, you must name the file with Resources suffix, for example, ProductsResources. It must inherit the Resource class, which can be found inside the Telerik.Sitefinity.Localization namespace. Use the following example:

Every resource is using the ResourceEntry attribute. The attribute binds the property name with a specific value, last modified date, and description.

NOTE: You can either add the resources to the class programmatically, using the above example, or you can add them using the UI after you register the resource class, as described below. After registration, the class becomes available under Administration » Labels & Messages

You can add as many resources to the class as you need.

Register the custom resource class

To use the newly created custom resource class, you must register it on application initialization. You do this is inside the Application_Start method of the Global.asax class. You must subscribe to the Bootstrapper.Bootstrapped event and add the following code inside:

When you restart the application, the class is registered and becomes available under Administration » Labels & Messages. Whenever you add new resources, you can point to the newly created resource class.

NOTE: When a new resource is added or translated through the backend, a physical file is created in ~/App_Data/Sitefinity/GlobalResources folder. Make sure to deploy those files when you move your site from development to production.

Reference the labels from the resource class

You can reference the labels from the custom resource class both from WebForms and MVC widgets and controls. In addition, you can reference the labels through code behind.

WebForms

Reference from the template using the following:
<%$ Resources:ProductsResources, AmazonSearchServiceTitle %> 

MVC

Reference from the view using the following:
@using Telerik.Sitefinity.Frontend.Mvc.Helpers;

@Html.Resource("NameOfTheResourseString")

Code-behind

Add the following using statement:
using Telerik.Sitefinity.Localization;
 
Reference the label using the following code:
Res.Get<ProductsResources>().AmazonSearchServiceTitle

Additional resources

ARTICLES

Custom Products module: Create the localizable resources

SAMPLES

You can download the Progress Sitefinity CMS SDK samples from GitHub:

EXTERNAL RESOURCES

.NET localizable resource handling

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?