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.
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.
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.
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.
Reference from the template using the following:
<%$ Resources:ProductsResources, AmazonSearchServiceTitle %>
Reference from the view using the following:
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important
Custom Products module: Create the localizable resources
You can download the Progress Sitefinity CMS SDK samples from GitHub:
.NET localizable resource handling
Copyright © 2019 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.