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