Localized Labels on Custom Widgets
I am trying to use Sitefinity to store and retrieve the localizable labels for my own widgets (user controls). My goal is for them to be included in Sitefinity's import/export of all localizable content for easy editing offline.
I have a special method in all my user controls to retrieve labels based on a string key. I would like to hook this method up to the Sitefinity API to retreive the localized label.
Is this possible, and if so what approach should I take? How does the mechanism work?
Would Telerik.Sitefinity.Localization.Data be the right place to start?
To be more specific, I can add a localizable label with this code:
var resources = ResourceManager.GetManager();
resources.AddItem(
Thread.CurrentThread.CurrentCulture,
"GroupName"
,
"TestLabel1"
,
"TestLabel1 Value"
,
"TestLabel1 Description"
);
resources.SaveChanges();
var resources = ResourceManager.GetManager();
var resource = resources.GetResourceOrEmpty(Thread.CurrentThread.CurrentCulture,
"GroupName"
,
"TestLabel1"
);
Hello Jeff,
Please, check the Products sample from the SDK.
You have to inherit from Telerik.Sitefinity.Localization.Resource and then register your resource in Global.asax like that:
protected
void
Application_Start(
object
sender, EventArgs e)
Bootstrapper.Initialized +=
new
EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(
this
.AfterInit);
private
void
AfterInit(
object
sender, ExecutedEventArgs args)
Res.RegisterResource<
CustomModuleResources
>();
Is it possible to use a localization label in a master page? I've been trying with
<asp:Label ID="(Key value)" runat="server" />
Hello Adam,
You can use localized strings for label texts in master pages and even in .aspx pages part of your Sitefinity project. Bellow is a sample use of how to get the localized text for a resource class:
<
asp:Label
runat
=
"server"
ID
=
"lbl1"
Text='<%$ Resources:NewsResources, Content %>'></
asp:Label
>
Cheers! That did the trick, thanks :-)
dear , i have a question but please reply me asap :) , i made 8 users controls and registered them as widgets , but i am using Global resources of Asp.net ( .resx ) files , and my controls cant see these resources ... my version is 4.1 , please reply me asap , cause we are delivering ...
Thanks;
Freddy Khalaf
Hello freddy,
The thing is that we do not use the ASP.NET resource provider. We are using a custom one. You need to use localization strings as described here.
Best wishes,
Radoslav Georgiev
the Telerik team
Hi Sitefinity Team,
Can we import ASP.NET resource file in 'Import language pack' under 'Interface Labels and Messages' section of Administration? So that editor can edit resource key/values according to language. If yes, please provide details. It'll be very helpful in maintaining labels for custom controls.
Thanks,
Swati Bhatia
Hi Sitefinity Team,
Can we import ASP.NET resource file in 'Import language pack' under 'Interface Labels and Messages' section of Administration? So that editor can edit resource key/values according to language. If yes, please provide details. It'll be very helpful in maintaining labels for custom controls.
Thanks,
Swati Bhatia
Hi Radoslav,
The link under "here." is not working. Can you please provide the correct link?
Thanks
Nirav
Hello,
Please review the article available in our Sitefinity documentation. Furthermore, you could take a look at this forum thread.
Regards,
Stefani Tacheva
Telerik