views:

15

answers:

1

I'm a beginner in the black art of ASP .NET development, so forgive me if this is a stupid question. After a bit of googling, and reading though (some of...) ASP .NET 3.5 Unleashed, I've yet to find a way of doing what I want - which usually either means I'm trying to do something stupid, or it's so obvious I've missed it :)

I'm creating a Server Control for use across multiple sites my company is developing. It's nothing fancy, just a standard here-you-may-edit-and-create-users control.

Doing so naturally requires localization of some text.

The natural way of doing this, for me, would be a global resource named after some convention which the projects that include the server control may then fill with localized data.

However, I'm having some trouble accessing these resources from within my component.

Having created in Project A in the App_GlobalResources folder a resource file called CreateOrEditUserControl.da.resx (side note: do I need to add my App_GlobalResources folder to the web-config or something?). Project A includes the CreateOrEditUserControl which is from project B and loaded via an assembly reference. CreateOrEditUserControl.da.resx contains the key UserName mapped to the string Brugernavn (this is just a Danish localization, as you may have guessed...)

Inside my control in the CreateChildControls() method (as I need the localized strings here), I've tried accessing the resources the following ways:

HttpContext.GetGlobalResource("CreateOrEditUserControl","UserName");
HttpContext.GetGlobalResource("CreateOrEditUserControl.da","UserName");
HttpContext.GetGlobalResource("CreateOrEditUserControl.da.resx","UserName");
HttpContext.GetLocalResource("CreateOrEditUserControl.da.resx","UserName");

the first three of which return null, and the last of which throws an exception since I do not have the rights to said resource from within my component, which seems logical.

So far I've had to resort to a "hack", in which you can specify language in the querystring and I manually insert the strings. This is undesirable, however, as any change would require change in the component, not just on the user...

What is the right way of doing this - if there is one?

Thanks in advance!

A: 

The natural way of doing this, for me, would be a global resource named after some convention which the projects that include the server control may then fill with localized data.

I know next-to-nothing about ASP.Net but if I had common control to use on different pages or in various applications, I would include translatable resources "inside" this control. Then you wouldn't have to localize it for each project but only once. I am pretty sure this is possible in ASP.Net.

As for accessing global resources (again sorry for my limited knowledge) you will probably have to use ResourceManager or ResourceReader.

Paweł Dyda
Thanks for your response! Including the resources inside the component is very possible - but doesn't solver the larger issue, from what I can see. It still doesn't allow the user of the component to "inject" his own localization data? Thanks for the tip on ResourceManager / Reader - I'll look those up!
Fafnr