Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Creating a data driven ASP.NET Resource Provider and Editor Article posted


:P
On this page:

I finally managed to write up my data driven localization resource provider for ASP.NET as an article. It ended up being quite a task getting it all to fit into an article and I actually ended up with TWO freaking articles - one an introduction and one for the resource provider and editor implementation. <s> Yeah, yeah my verbosity gets the best of me.

You can find the Resource Provider/Editor article here:
http://www.west-wind.com/presentations/wwDbResourceProvider/

And the Intro article here:
http://www.west-wind.com/presentations/wwDbResourceProvider/introtolocalization.aspx

There are also online samples you can play with to check out the provider here:
http://www.west-wind.com/wwdbResourceProviderSample

and yes you can change the UI in this sample, so behave yourselves. (I know you won't!)

And documentation for the Provider and related tools:
http://www.west-wind.com/tools/wwDbResourceProvider/docs/

The provider comes with all source code and samples so you can play with this stuff for yourself.

The resource provider is pretty cool and it's been one of those fun side projects I've been tinkering with off and on. I had to dust it of a bit a couple weeks ago for a presentation at the Portland .NET User group and it went well. I love showing this provider because it's fun to watch people get that surprised look on their face as they are editing resources in real time on an ASP.NET form <s>.The session stuff is alright, but this is really the kind of topic that benefits from having a backing article that explains what the heck is going on. Provider Models and ResourceManagers aren't easily explained and the paper should help put things in proper perspective.

Anyway, here are a few screen shots from the editor that's utilizing the data driven localization provider.

Here's the resource editor that can be used to edit resources and refresh them as the application is running.

The form's mostly AJAX driven (except some of the import and renaming operations which require full UI refreshes anyway) so it's very interactive. This is one case where a regular Postback API probably wouldn't have worked well. As you can see the tool has grown a bit from its early days - you can now import Resx resources into the data resource provider, edit resources and run with it, and when you're done optionally write all the resources back out to Resx files.

Other windows kind of pop up ontop so when you add resources or do things like run the translation dialog:

 

you stay in the current context. The translation dialog is more for inspiration than anything - the translations are worthless to use as is, but they actually help me with my rusty German (you can give me shit for the German translations of the UI) in giving my memory a little jog. But it'd be easy enough to integrate other more sophisticated translation tools into the admin interface.

But one of the most useful features of this toolset is the context sensitive help lookup which basically lets you select a control and jump straight to a matching resource:

This works with Implicit Resources in ASP.NET and tries to look up the control by its control Id and find a matching property. Even if it doesn't match exactly it often can figure out a close match that gets you close in the listbox. To me the biggest hassle in localization is finding the damn resource item in the list of items. I localized the Resource Admin form which is not very large, but it has 225 resource entries total with 157 of them for the Invariant Culture.

How do I know that - ah, but it's a database table <s>. Nothing like being able to run a SELECT statement over your resource data to filter and manipulate it <s>...

If you have questions or comments you can leave them here or, for more involved discussions post it on the message board:

www.west-wind.com/wwThreads/default.asp?forum=White+Papers

Posted in Localization  ASP.NET  

The Voices of Reason


 

# DotNetSlackers: Creating a data driven ASP.NET Resource Provider and Editor Article posted


Josh Stodola
July 18, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Wow, Rick, this is friggen awesome!!

Douglas Hammon
July 18, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Thanks Rick!!

Scott Allen
July 18, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Rick: this is awesome.

Andreas Kraus
July 23, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

This is really awesome Rick, wow!

Joe Manning
July 26, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Rick thank you very much for sharing this. Definitely makes the whole localization effort much more maintainable.

Giorgio
July 26, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Very good work. Congratulations!

The "Import from resources" functionality return a run-time error when the resources database table is empty. Is it a bug?
I insert manually one record in the table but clickin on "Import from resources" doesn't import the .resx files in App_LocalResources directory. How can I import from .resx files?

Thanks in advance.


Giorgio

Rick Strahl
July 26, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

What's the error? Most likely you may not have rights to read these files. Make sure the account you're running under (or per impersonation on the Resource Admin form) has rights to read files out of the App_LocalResource/GlobalResources folders.

Giorgio
July 27, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

The error (unfortunately in italian language) is "SelectedValue in 'lstResourceSet' non valido, poiché non è incluso nell'elenco di elementi. Nome parametro: value". The line that rise the error is "this.lstResourceSet.DataBind();" (line number: 160) in Default.aspx.cs of the LocalizationAdmin directory. As I said in my previous comment I get the error only when the database table that contain the resources is empty, so there isn't any ResourceSet.

Hua Yang
August 05, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Great articles and samples. Thank you very much.

I created a SQL simple resource provider. It works fine, I can use it to retrieve resources from my database for my pages. Even though my pages work as expected, I have an issue with my resource provider. When I compile my website, the compiler gives errors "the resource object with key 'AccountTeamEmail' not found' error. I use explicit resource expression for all my resource access. The compiler generate one error message for each expression. What I have missed?

Thank you in advance for your help.

Rick Strahl
August 05, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

The resource provider must be available at compile time because ASP.NET checks resource availability at compile time. If the provider is not working or a specific key is missing in the resources you'll get an error.

Most likely you're missing the resource key.

JefferyS
August 08, 2007

# Errors importing resource data

Having some problems. Unless I messed up the installation steps when I first go to import resource data I get:

Server Error in '/groupware' Application.
--------------------------------------------------------------------------------

'lstResourceSet' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'lstResourceSet' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Source Error:


Line 158: this.lstResourceSet.DataSource = dt;
Line 159: this.lstResourceSet.DataValueField = "ResourceSet";
Line 160: this.lstResourceSet.DataBind();
Line 161:
Line 162: if (this.ResourceSet != null)


Source File: c:\My Programming\Visual Studio 2005\WebSites\groupware\admin\LocalizationAdmin\Default.aspx.cs Line: 160

Stack Trace:


[ArgumentOutOfRangeException: 'lstResourceSet' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource) +1822067
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +104
System.Web.UI.WebControls.ListControl.PerformSelect() +31
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
LocalizeAdmin_Default.GetResourceSet() in c:\My Programming\Visual Studio 2005\WebSites\groupware\admin\LocalizationAdmin\Default.aspx.cs:160
LocalizeAdmin_Default.btnImport_Click(Object sender, EventArgs e) in c:\My Programming\Visual Studio 2005\WebSites\groupware\admin\LocalizationAdmin\Default.aspx.cs:293
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +105
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832


It did add info to the database but in most of my resources I get two square boxes in the value column. In your resource editor, I go to one of these resources and there is something in the value field but it is not visible. I copied what was in the box and pasted into a text editor and it showed as the word that was supposed to be in the value box.

Hope that made sense.

Let me know what you think about this problem.

Thanks,

JefferyS

Rick Strahl
August 08, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

You should import before enabling the database provider. If you do it the other way around there will be no resources and ASP.NET will fail to compile the application.

So steps are:

Configure the provider properties in web.config (but don't enable it)
Run the Admin form
Create the table if necessary
Import Resources from Resx
Turn on the Resource Provider (in <globalization>)
Re-run the app or admin form

At that point the data provider should be active and working properly.

JefferyS
August 08, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Rick, thank you for responding so quickly. I still received the same error.
This is what I did:

I removed the Localization table.
I have the two Westwind dll's in my Bin folder.
I have the following lines in the web.config

<section name="wwDbResourceProvider" type="Westwind.Globalization.wwDbResourceProviderSection" requirePermission="false"/>

<wwDbResourceProvider connectionString="SQLDataConnection"
resourceTableName="tblLocalizations"
designTimeVirtualPath="/internationalization"
showLocalizationControlOptions="true"
showControlIcons="true"
localizationFormWebPath="~/admin/localizationadmin/Default.aspx"
addMissingResources="false"
useVsNetResourceNaming="false"
stronglyTypedGlobalResource="~/App_Code/Resources.cs,AppResources"/>


The Globalization line in the web.config is remarked out.

I right clicked on the default.aspx file in the LocalizationAdmin and selected "view in browser"
It told me there was no localization table and that I needed to create one.
I created the table and it said it was successful.
I then clicked the import from resources button.
After a bit I received the error.

It imported a lot of resources but I still have two square boxes in most of my resource setting values. I think they may be carriage returns.

Am I still doing something wrong?

Thanks,

JefferyS

Rick Strahl
August 08, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Let's move this discussion to the message board Jeff. www.west-wind.com/wwthreads/default.asp?forum=White+Papers.

The square boxes should be no problem - it's just XML's CHR(10) (vs. CHR(13) + CHR(10) which shows properly as Carriage Returns, which won't be a problem in the designer or in the rendering. Not sure how those are getting there though - when i explicitly add CRs into the RESX file XML and then import I still see proper CR translation.

OmegaSupreme
August 28, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Great article. :)

Stefan
August 30, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

When I set things up I clicked the Import from resx, an error occured (something about missing folders) but the structure was imported correctly. No values though..
Now I want to export everything to resx, send it to a translation company, get more resx-files in return, and import it.
I tried importing again, and all my values dissapeared. Not very funny. Alot of work lost there.
Most of it was backed up, but there's no obvius way to restore from backup?

I'm also missing all the on-page symbols, I need to go to the admin-tool to edit things.

haim
September 18, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

very nice work Rick.
i one question,
i use
<globalization uiCulture ="en" culture="en-US" />

and if i wont to change to different lang
i use
<globalization uiCulture ="he" culture="he-IL" />


when installing your app
globalization tag is replaced

<globalization resourceProviderFactoryType="Westwind.Globalization.wwDbSimpleResourceProviderFactory,Westwind.Globalization" />


how can i write - uiCulture ="he" culture="he-IL"
in web config and still use your app

Rick Strahl
September 18, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Just add all attributes to the <globalization> tag.
<globalization 
  resourceProviderFactoryType="Westwind.Globalization.wwDbSimpleResourceProviderFactory,Westwind.Globalization"  
   uiCulture="de" culture="de-CH" />

haim
September 20, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

hi again
i implemented your code in one of my web app and
i am having little problem

every thing works o.k. in vs2005 - source code
but after i compile my site...

// works O.K.
object Value = this.GetLocalResourceObject("ResourceName");


// works O.K.
// Explicit Resource Expression
<asp:Label ID="lblCompany" runat="server" Text="<%$ Resources: lblCompany.Text %>" />


and if i try Implicit Resource Keys
// Not works 
// Implicit Resource Keys
<asp:Label ID="lblCompany" runat="server" Text="Company:" meta:resourcekey="lblCompany" />


this Implicit Resource Keys not works after i compile
but if i use Explicit Resource Expression it works fine

have any idea what can couse this ?

Josh Stodola
October 02, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hey Rick, was going to show the demo of this *incredible* tool to a buddy of mine, but unfortunately I got the dreaded server error.

http://www.west-wind.com/wwdbResourceProviderSample

Best Regards...

Rick Strahl
October 02, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Josh, yeah I know. People keep adding new invalid locales which breaks compilation of the sample. I have to update the data. I'll get it back online in a couple of days and fix it so people can't enter invalid locales.

Rick Strahl
October 02, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Oh and older version of this tool is also available here as part of the hoverpanel samples:

http://www.west-wind.com/presentations/wwhoverpanel/sample/ResourceProvider/CustomerList.aspx

Binab
December 20, 2007

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hello Rick,

Thank you for your awesome work. I have started to use your controls. Everything works fine but I have a question because I have no idea how to localize Web.sitemap file using your addons.

Thanks in advance for you answer, Greetings
Binab

Neil Burnett
January 16, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

"Hi Josh, yeah I know. People keep adding new invalid locales which breaks compilation of the sample. I have to update the data. I'll get it back online in a couple of days and fix it so people can't enter invalid locales. "

Still broken.

Neil Burnett
January 16, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi rick

I think I must be dumb, sorry. How do I get the Internationalization sample to run on my local system? It doesn't come with a project or solution file and seems not to be a Web Application either. Clearly I have missed something:-(

Do I need to create a new solution and dummy web project then import the Internationalization files, or is there a better way.

Sorry to be a nuisance.

Neil Burnett
January 16, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

I think I have done it. I created a new solution and web project (not a WAP) than copied the entire Internationalization folder into it. i now seem to have a working sample site.

Neil Burnett
January 16, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick

I am advancing with this and it is looking great so far! Thanks for making it available.

Question; Why aren't asp:Localizable controls recognized as localizable when attaching the localize icon? Labels work fine, but Localizables get ignored.

Neil Burnett
January 17, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Sorry, I meant asp:localize controls

Serhiy Michkovsky
February 25, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi, Rick! Thank you.
Your article and code is more starting point than msdn. Why it not there?

Patrick Coston
March 26, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

I'm converting the ASP pages to ASP.NET for the International Institute of Learning and I'm using your data driven resource provider and it's working great! When users rename their resource set via your admin page, you might consider trimming the New ResourceSet name. I accidentally appended a space to my new resource set name and of course all localized strings were empty resulting in my page content suddenly vanishing. That mistake took me an entire day to figure out and of course 2 seconds to fix. It would be nice if your code could compensate for us idiots! ;-)

Sam
March 27, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hey Rick
Please do you have any idea , why oracle is not working with the component.


Regards
Samarjit c

Rick Strahl
March 27, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@Sam - the provider is data provider used is SQL Server specific.

Patrick Coston
April 09, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Rick, I'm using your wwDbResourceProvider for the page below

http://www.iil.com/InternationalCourseSchedule.aspx?World=FRA

it was working perfectly then suddenly the page went blank.

This happened right after I renamed some values in my Localization table in the field ResourceID using several SQL update commands.

I have several dynamically populated dropdown lists which are localized. For example for my country dropdown list

<asp:DropDownList runat="server" ID="Country">
</asp:DropDownList>

I have these ResourceID's defined

Country0.Text = "Select"
Country0.Value = "none"
Country1.Text = "Australia"
Country1.Value = "AUS"
Country2.Text = "Germany"
Country2.Value = "DEU"

I wanted to insert "All Countries" as option 1 so I had to rename the existing ResourceID's to move them down using update commands like these.

update Localization set ResourceID='Country3.Text' where ResourceID='Country2.Text'
update Localization set ResourceID='Country3.Value' where ResourceID='Country2.Value'
update Localization set ResourceID='Country2.Text' where ResourceID='Country1.Text'
update Localization set ResourceID='Country2.Value' where ResourceID='Country1.Value'

then I added my new Country1 Text/Value pair for "All Countries" so then I had these values for the ResourceID field.

Country0.Text = "Select"
Country0.Value = "none"
Country1.Text = "All Countries"
Country1.Value = "all"
Country2.Text = "Australia"
Country2.Value = "AUS"
Country3.Text = "Germany"
Country3.Value = "DEU"

Is there any reason why making changes to my Localization table outside of the Admin tool should cause wwDbResourceProvider to return blanks even if the data is well formed?

Patrick Coston
April 09, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick, this is continued from last post.

I recompiled Westwind.Globalization.dll in debug mode using Visual Studio.NET 2005. I then added that dll and the pdb file to my bin directory then debugged my page. I then stepped into the source code for GetGlobalResourceObject( ).

object obj = HttpContext.GetGlobalResourceObject("InternationalCourseSchedule.aspx", Val);

it calls

object IResourceProvider.GetObject(string ResourceKey, CultureInfo culture)

in file wwDbResourceProvider.cs

this line of code

object value = this.ResourceManager.GetObject(ResourceKey, culture);

returns value = null. The variable culture is also null so it returns an empty string even though the value of the variable Val does exist in my Localization table.

I checked the value of

Thread.CurrentThread.CurrentUICulture
Thread.CurrentThread.CurrentCulture

before and after calling HttpContext.GetGlobalResourceObject( ) and they are always properly set for example "pt-BR" for Portuguese in Brazil.

I have implemented an App_Code\Resources.cs file which implements class Resources and is referenced in my web.config inside <wwDbResourceProvider>

stronglyTypedGlobalResource="~/App_Code/Resources.cs,AppResources"

This line of code works in my .aspx page to display the main menu

<%=AppResources.Resources.MainMenu%>

This line of code works in my .cs file Page_Load to set some button text.

ButtonSearch.Text = AppResources.Resources.LabelButtonSearch;

But others do not work. At this point I've got about 25% of the page working. I'm trying to localize 14 different countries!

http://www.iil.com/InternationalCourseSchedule.aspx?World=AUS
http://www.iil.com/InternationalCourseSchedule.aspx?World=BRA
http://www.iil.com/InternationalCourseSchedule.aspx?World=CAN
http://www.iil.com/InternationalCourseSchedule.aspx?World=TTO
http://www.iil.com/InternationalCourseSchedule.aspx?World=CHN
http://www.iil.com/InternationalCourseSchedule.aspx?World=GBR
http://www.iil.com/InternationalCourseSchedule.aspx?World=FIN
http://www.iil.com/InternationalCourseSchedule.aspx?World=FRA
http://www.iil.com/InternationalCourseSchedule.aspx?World=DEU
http://www.iil.com/InternationalCourseSchedule.aspx?World=HKG
http://www.iil.com/InternationalCourseSchedule.aspx?World=HUN
http://www.iil.com/InternationalCourseSchedule.aspx?World=IND
http://www.iil.com/InternationalCourseSchedule.aspx?World=JPN
http://www.iil.com/InternationalCourseSchedule.aspx?World=ESP

Any idea why some of it works and some of it doesn't?

Patrick Coston
April 09, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick, part 3 ... new discoveries. My code sets the language and country for each site using this c# code.

string Lang = "";
switch (WorldCode.ToUpper())
{
    case "SGP": Lang = "zh-SG"; break;    // Chinese        Singapore
    case "AUS": Lang = "en-AU"; break;    // English        Australia
    case "BRA": Lang = "pt-BR"; break;    // Portuguese    Brazil
    case "CAN": Lang = "en-CA"; break;    // English        Canada
    case "TTO": Lang = "en-TT"; break;    // English        Trinidad and Tobago
    case "CHN": Lang = "zh-CN"; break;    // Chinese        China
    case "GBR": Lang = "en-GB"; break;    // English        United Kingdom
    case "FIN": Lang = "fi-FI"; break;    // Finnish        Finland
    case "FRA": Lang = "fr-FR"; break;    // French        France
    case "DEU": Lang = "de-DE"; break;    // German        Germany
    case "HKG": Lang = "zh-HK"; break;    // Chinese        Hong Kong
    case "HUN": Lang = "hu-HU"; break;    // Hungarian    Hungary
    case "IND": Lang = "hi-IN"; break;    // Hindi        India
    case "JPN": Lang = "ja-JP"; break;    // Japanese        Japan
    case "MEX": Lang = "es-MX"; break;    // Spanish        Mexico
    case "ESP": Lang = "es-ES"; break;    // Spanish        Spain
    default: Response.Redirect("default.asp"); break;
}
Thread.CurrentThread.CurrentUICulture = new CultureInfo(Lang);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Lang);


Take Spanish/Spain for example. If my Localization SQL table has "es-es", then the localized text for Spain is displayed. If I use "es" or "" (invariant empty string), then I get an empty string.

That's why 25% of my site is working. 75% uses only language (example: es) or the invariant for English. 25% uses a specific language-country combo such as "es-es".

http://www.iil.com/InternationalCourseSchedule.aspx?World=ESP

It was working 100% then suddenly this happened. Do you have any idea why?

ps

I've gotta demo this site for the CEO Friday! Any help would be greatly appreciated.

Jef
June 25, 2008

# Creating a data driven ASP.NET Resource Provider for use with SharePoint

Hi Rick-

Thanks for the great example. I've tried to implement this within a SharePoint environment, however the resourceProviderFactoryType causes issues with SharePoint, as I don't have or want to put all of the SharePoint resources in the database. So long story short, SharePoint fails to run correctly when overriding the resource provider using this example.

I've tried to implement a modified version between your example and the MSDN article(http://msdn.microsoft.com/en-us/library/aa905797.aspx), which I have working. I can either set the expression in the control on the aspx or through the code behind. However when I set the expression in the control and view the aspx page in design mode I get an ‘Object reference not set to an instance of an object’ error.

Anyone have experience creating a ResourceProvider and using it within a SharePoint environment? Any ideas on why the designer would fail? I'm thinking that it may have something to do with not having a Resource Manager.

Thanks in advance for any help. Sample code can be shared upon request.

Matt
September 12, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

FYI - the online sample is still broken.

There are also online samples you can play with to check out the provider here:
http://www.west-wind.com/wwdbResourceProviderSample

JToast
September 18, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Wow, thanks Rick. This is exactly what we need. I thought we were going to have to go down the Enterprise Localization route (http://msdn.microsoft.com/en-us/library/aa479334.aspx#loctoolkit_topic2) which seemed like overkill. I think this is preferable for a number of reasons, especially its simplicity.

You the man!

Thanks

LeoG
November 02, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Rick,

Does this implementation work from a class library via the built in ResourceManager? If so what configuration would be necessary if for example you are localizing messages in a business layer that is consumed by an asp.net web application that has your provider configured?

LeoG
November 02, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

I guess I should have looked at this before posting but for anyone interested it looks like all you need to do is create an instance of wwDbResourceManager and pass in your ResourceSetId and everything just works in class libraries also.

Lasko
November 15, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Any tips on making this work in a master page? I went ahead and threw the contents of Default.aspx in an asp:Content control which causes the IDs of all of its children to have the nice ct100_ct100_blah prefix added to it. The javascript then can't find the correct controls ($w("lstResourceIds") == null). Perhaps I'm blind and I missed something, but I'm having a heck of a time getting it to work.

DanB
December 11, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Rick, this is a great project. It's really helpful.

Is there a way to copy a set of resources for a language? If not, this would be a nice feature to have for when you decide to add a new language to your site. I guess I can just run a query to copy the invariant resources but I'd like the translator to be able to completely manage the site languages once the site is launched.

OleM
December 17, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hey Rick, really enjoyed your article, and I'm running something almost identical on my sites. One thing that I haven't been able to solve, is the "hack", which returns an empty string if the resource is not found, for the compile time problem.

The problem is, that I have a lot of controls with parameters like .showInMenu (for SiteMapNodes) and 3rd party controls which should NOT be localized for parameters like .Tools etc.).

All these instances ONLY work, if I can return NULL when there is actually no translations. But then I can't precompile!

Can you think of ANY way to fix this, so I don't have to return dummy/empty values if nothing is found? Please, it's driving me maaaad! :o)

RobB
December 17, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick, great article thanks!

I am implementing an exception handling page for a website that uses resource files from a database. This error page also needs to be localised for the user, but of course one of the possible problems could be that the database is unavailable!

Any ideas if there is a way that a single page could use .resx files for resources, while all other pages go to the database?? I guess the ProviderFactory could check the page path and return the standard resource provider if it matches the path of the error page. Does anyone have any other ideas?

Cheers, and thanks again for the article.

JasonC
December 18, 2008

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

hey rick great article,
I have a question about your admin page.I know how you able to populate a list of all the pages...tahts easy, but after that when you select a page and are able to list all the controls on the page.I see the code where you loop through the control collecton and find those that are localizable.....but how to you get that data into that list on the admin page...Do you load a page object then call the method to go through the control collection.....or do you let each page independantly put the list list of contols in the database then get it from there.
How exactly do you do it please get back to me ...........thanks in advance

Ralph
December 24, 2008

# Problem with pre-compiled app

Hi Rick. Great Tool!

I only have one problem left. When I precompile the web app (using VS 2005 web deployment project) it seems like the resources are not found and therefore not available at run-time.

Does anyone have any idea on how to solve this problem?

Thanks a lot in advance... Ralph.

Adi Saric
January 08, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick,

This is a fantastic implementation of the database driven localization. I have a quick question. How would you handle a scenario where text of a control is set within the code behind and needs to change based on the locale? I guess the same would go for the HTML elements. Thanks,

Adi

Puneet Bhasin
March 05, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick,

Amazing work!

One question though - If I am creating something like this. How can I debug the code, especially the design time code.

Thanks!

Rick Strahl
March 05, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@Puneet - you can debug design time with two instances of Visual Studio.

Arthur
March 10, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick,
Thanks for this fantastic article. I didn't know much about Resources until now. We have a real interesting situation in how we use our web-based application which is presenting a problem I'm having difficulty with.

I'm not sure if I can use the resource provider if I'm tied to static configuration data, i.e., .config or elsewhere and here's why.

When a user logs in, they're authenticated on a "master" database. Once authenticated, we now know who the user is and which client they belong to, e.g., the user's id is 1234 and their specific database is Client1_DB. As soon as we know this, I would have to configure the custom resource provider to connect to Client1_DB, set the user's id so when the resource provider's data manager calls the stored procedure that fills our resource cache, we can pass it the user's id. The stored procedure returns the resources text based on the user id because different users may see different text within even the same database, e.g., Client1_DB. Other users logging in may be user's in Client2_DB, Client3_DB, etc.

The problem here is that the resource provider gets initialized with the parameter-less constructor and I'm trying to figure out a way to configure it before it calls GetResourceCache(...) because I need the critical pieces of information before calling the resource stored procedure.

I hope I'm making sense. At this point, to me at least, it seems that I can't do this and we'd have to implment some other way. I hope I'm wrong and am just missing something. Thanks for taking the time to help.

Rick Strahl
March 10, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@Arthur - the ResourceProvider is always initialized by ASP.NET so there's not anything you can do about *how* you are being called.

However, since you have the code you can hook the constructor and do whatever you need to in the startup code for the provider. For example, you can look at static configuration objects or whatever you need to.

Keep in mind though that the resource provider initializes only once, not on every hit, so this is probably not useful to what you're doing. We can maybe discuss this offline.

Arthur
March 11, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hello Rick,
Thank you for the quick response. I figured as much regarding how the call is made by ASP.NET. I was just hoping to be able to override it or something similar.

Yes, I was poking around in debug mode to see what was available to me during the startup code. The HttpContext.Current is valid, so I'm trying to leverage these types of objects and maybe am able to get what I need from there.

Initializing once is actually fine. The user can either log off or start a new session and our lookup text doesn't change all that often so that's really not a big deal. If I get stuck, I'd like to definitely chat off line. Thanks again. I've actually only scratched the surface on all the code you have. I'm modeled my stuff after the simple provider since that's all we need. :)

Hugo Egerström
April 09, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick,

Just like Puneet Bhasin above I need to debug my design time resource provider, could you elaborate on how to debug with a second instance of visual studio?

Thank you in advance.

Partha S Nath
April 26, 2009

# The implementation is working in my first page only

Hi Rick,

I have implemented your resource provider in my project and it is working fine in my first page but not working in the other pages of the project. In my project,I am using Master Page and the HeaderText of my GridView cann't be localised as I am using Template columns.

Have any solution for this???
Thanks in advance to you...

Partha S Nath

Rick Strahl
April 26, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@Partha - if you're generating dynamic code in the grid that you localize (like template columns) you need to explicitly embed the content using the resource functions of the provider (GetLocalResourceObject/GetGlobalResourceObject).

Partha S Nath
April 27, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Dear Rick,

Thanks for your sharp response. But still I am in trouble that my one page is responding to Localization but my other pages of the project do not. The wwResourceProvider is impleted application wise.Right?Am I doing any mistake?

Thanks in advance.

Partha S Nath

Partha S Nath
April 27, 2009

# The implementation is working in my one page only

Dear Rick,

Sorry for the previous wrong title.

Thanks for your sharp response. But still I am in trouble that my one page is responding to Localization but my other pages of the project do not. The wwResourceProvider is impleted application wise.Right? Am I doing any mistake?

Thanks in advance.

Partha S Nath

Richard Hubert
April 27, 2009

# RESX Comments Trashed ...

Hi Rick,

very interesting app. I'm configuring it to use with a translation manager (TM) we have, and I notice that you trash the comments in the RESX file when you insert into the DB. This is a problem, since when your editor is used to create and modify I18N entries, the RESX must be generated for use with a TM or to send the RESX to a remote translator etc. I love the bi-directional RESX support -- the killer feature -- but the comments need to be there too.

Ideas?

Thanks!
R

Partha S Nath
April 28, 2009

# The implementation is still working in my ONE PAGE only

Dear Rick,

I had implemented first a single page with wwResourseProvider of my project which is running fine with Localization and while I am trying to implement to the rest of pages now,they are not responding to Localization.

Only the first implemented page is still responding but the other pages not. Is there any rule/restriction of wwResourceProvider or am I missing something?

Waiting for your comments as before.Thanks in advance.

Partha S Nath

Cheryl S.
May 15, 2009

# Error in SQL Script on German system, "Network Service" user spelled differently

The SQL Script used by the installer to create the database structures fails when trying to create a login for "NT AUTHORITY\Network Service". This login is spelled "NT AUTHORITY\NetworkService" on German systems (thank you Microsoft). I would really appreciate it if anyone could post or send me a copy of the complete script to create the database so we could also have the opportunity to try this out.

Yulia
June 30, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Dear Rick,
Is it possible to configure and use several resource providers in one application?
Say, for some controls the page will use the default .net provider and for the others the custom provider?

Thanks in advance.
Yulia

Luca
September 21, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick,
really interesting article. I would love to install and study your code but the SQL Script used by the installer to create the database structures fails when trying to create a login for "NT AUTHORITY\Network Service". Could it be as this user is spelled "NT AUTHORITY\SERVIZIO DI RETE" on Italian systems? Should it be the case, could you just make publicy available a copy of the complete sql script to create the database so "non/US" developers can have the opportunity to try it out?

Rick Strahl
September 22, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@Luca - I've updated the database installation code. Go ahead and download again and give it another shot. The database script is provided but you probably have to manually add the network service (or other IIS) account.

Nag
October 22, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick,
I tried to run your sample against Oracle. Here are the steps i followed for my one page web site.

1.create a web site with one page default .aspx
2. add the dlls to my BIN folder(westwind.globalization.dll ,westwind.globalizationweb.dll,westwind.utilities.dll,westwind.web.dll)
3.update the web.config file as follows
<section name="DbResourceProvider" type="Westwind.Globalization.DbResourceProviderSection" requirePermission="false"/>
<DbResourceProvider connectionString="OracleConnectionString" resourceTableName="Localizations" designTimeVirtualPath="/internationalization" showLocalizationControlOptions="true" showControlIcons="true" localizationFormWebPath="~/localizationadmin/LocalizationAdmin.aspx" addMissingResources="false" useVsNetResourceNaming="false" stronglyTypedGlobalResource="~/App_Code/Resources.cs,AppResources"/>
<connectionStrings><add name="OracleConnectionString" connectionString="Data Source=HTEST88;Persist Security Info=True;User ID=sysadm;Password=abcd;Unicode=True" providerName="System.Data.OracleClient"/></connectionStrings>

4.create the 'Localizations' table in data base.
5.in Visual Studio for Default.aspx ,go to tools and click 'Generate Local resource' to create implicit resources for my controls.
6.run the project to display Admin Form ( at first i get the Error "The Resource Table does not exist. Please use the Create Table option" ,but later it disappears)
7.Click on 'Import from resources' ,then i get the following error (may be beacause it is using SQLDataAccess which is SQLServer specific -then what changes i should make,to get it work for Oracle)


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

[NullReferenceException: Object reference not set to an instance of an object.]
Westwind.Utilities.Data.SqlDataAccess.ExecuteNonQuery(DbCommand Command, DbParameter[] Parameters) +147
Westwind.Utilities.Data.SqlDataAccessBase.ExecuteNonQuery(String sql, DbParameter[] parameters) +119
Westwind.Globalization.DbResourceDataManager.UpdateResource(String ResourceId, Object Value, String CultureName, String ResourceSet, Boolean ValueIsFileName) +1570
Westwind.Globalization.DbResourceDataManager.UpdateOrAdd(String ResourceId, Object Value, String CultureName, String ResourceSet, Boolean ValueIsFileName) +173
Westwind.Globalization.DbResourceDataManager.UpdateOrAdd(String ResourceId, Object Value, String CultureName, String ResourceSet) +77
Westwind.Globalization.DbResXConverter.ImportResourceFile(String FileName, String ResourceSetName, String LocaleId) +908
Westwind.Globalization.DbResXConverter.ImportDirectoryResources(String path, String WebRelativePath) +667
Westwind.Globalization.DbResXConverter.ImportWebResources(String WebPath) +526
Westwind.Globalization.DbResXConverter.ImportWebResources() +64
Westwind.GlobalizationWeb.LocalizeAdmin.btnImport_Click(Object sender, EventArgs e) +132
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +111
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +79
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Rick Strahl
October 22, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

The provider only works with SQL Server. The DAL provider I use uses SQL Server syntax only...

Ranjeet Bhargava
October 22, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick,
Here provider is data provider used is SQL Server specific.
Would you suggest that how it can be Provider Independent (useful for Oracle, SQL etc) likewise using DBProviderFactory?
I have tried my Stuffs but not succeeded yet.

Rick Strahl
October 23, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

The version in the Web Toolkit uses DbProviderFactory and it's potentially pluggable, but right now the code is tied to the SQL Server DAL. With Oracle you're on your own...

António Farinha
November 30, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

First of all, thanks for this. It's exactly what I need.

I've managed to create the localizations table, import the resource keys from the .resx files and get the website to "feed" from the database instead of the .resx.

But now the problems...

The "Reload Resources" button doesn't seem to be doing what it's supposed to, although the "ResourcesReloaded" text is displayed. I did manage to kick off the reloading by editing a .resx file (even though any changes don't make a difference).

Another problem (a very annoying one) is having Visual Studio throwing a compilation error for every single time I use a resource item in an .aspx page, like

<%$ Resources:MasterPages,Title %>

Does this mean I'll have to do it all from the codebehind with GetGlobalResourceObject()?

Thanks in advance.

Rick Strahl
November 30, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@antonio - The resource editor only edits the database resources. So if you want to see changes you either need to use the data driven provider (configured in web.config) or you need to edit, then export the resources back into Resx and then reload.

While developing I recommend you use the data driven provider. this will effectively work with resources in real time and allow you to easily reload resources. When all done (and possibly a few times along the way just to make sure everything works as expected) you can export resources to Resx and turn off the data driven provider.

António Farinha
December 01, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Maybe I didn't make myself clear. I'm using:

<globalization resourceProviderFactoryType="Westwind.Globalization.DbSimpleResourceProviderFactory,Westwind.Globalization" />

This seems to be making use of the DB provider. I see (in the application UI) the resources that are in the database and not the ones in the .resx files (from where they were imported). The problem is the cache clearing mechanism is not working. Isn't that why the "Reaload Resources" button is there?
Now if I do change something in the .resx files or the web.config this triggers some kind of compilation progress and then I can see the newly updated (in your editor) resources. And they're coming from the DB, as expected.

Rick Strahl
December 01, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Not sure then. This should work. The Resource provider kills the cached resource set items so next time the client requests them they will be reloaded. Couple of other things to watch for: Pages that are cached by the browser and ViewState that's overriding the default values on controls.

It does work for me as long as I'm using one of the data providers.

Shlomi
December 21, 2009

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi!
I'm trying to use the db resource manager in WinForms, but I can't find any reference of how to do so.
The form's designer creates InitializeComponent() method which in turns uses its default ResourceManager to work with resx, but I can't see how to override it with dbResourceManager. The only way I found was to 'hard-code' the texts in the form's constructor, after InitializeComponent() create the db resource manager and the set the texts of the controls manually.

How should dbResourceManager be used in WinForms?

Thanks!
Shlomi

kmoo01
March 03, 2010

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

I have stumbled across your website so many times in the past while looking for solutions, you are a legend and keep up the good work!

Camilo
March 17, 2010

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick I am having a problem with the Recycle App button, it doesn't look like it recycles the app correctly since I don't see the changes in the site after that button is clicked, I have to go to IIS and restart the app in order to see the changes.

Any help would greatly be appreciated and thanks a lot

Camilo

Sam
August 31, 2010

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Absolutely unreal! Cheers for this awesome bit of code. Now to extend it and detect when resource entries need to be syncronised when the invariant has been updated.

Quan Nguyen
October 10, 2010

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick,

I was about to implement this Resource Database provider when I came across your articles. This will definitely save me lots of hours. However, before I start using this provider, i would like to know if this provider supports the localization lists.

For example, if I have a list of customers whose names will be displayed in a list a long with other information. Since customers' name could be written differently in different languages, I'd need to localize this information and display it accordingly.
How would i localize this since your provider seems to store all resources in a single table.

Is it possible to extend your provider to support this scenario and other scenarios where resources will be updated regularly by the site users of different locals?

Do you have another article or blog post that explain how to accomplish this?

Thanks very much in advance.

Best,
Quan.

Gary
November 26, 2010

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

I noticed that Guy Smith-Ferrier updated his code for VS2010. I'm wondering whether any VS2010 changes affect your DbDesignTimeResourceProviderFactory code.

In my test project I can read resources from the database but I can't get CreateDesignTimeGlobalResourceProvider or CreateDesignTimeLocalResourceProvider to fire when I use the VS Generate Local Resources tool. I can't find _anything_ on the web other than your (awesome) work that provides much of anything related to hooking Generate Local Resources into a custom provider so this has become a show-stopper for me.

Thanks. And thanks too for your great work on this important subject.

Patty
November 29, 2010

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hello, I'd like to know if this custom resource provider has been tested successfully with an Oracle Database? Would anyone share their comments on the subject?

Thanks,

Rick Strahl
November 29, 2010

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@Patty - the provider works only with SQL Server. However the db layer is isolated and separate so it'd be possible to port just the data access layer to Oracle code and leave the rest intact.

Patty
November 29, 2010

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Thanks for your quick response,
Would the data access layer be contained in the DbResourceDataManager.cs file ?

Regards,

Rick Strahl
December 02, 2010

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@Patty - Yes. The data access code is limited to that particular class.

Jorge
December 07, 2010

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Will this work with SQL Server Reporting Services? If so, can you provide an example?

Thank you very much.

Nelis
May 05, 2011

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

The only way to specify MVC's DefaultModelBinder's error messages in a resource that's not located in App_GlobalResources is - as far as i could find - by making a custom resource provider factory.

DefaultModelBinder retrieves the resource internally by calling the static method GetValueInvalidResource which calls GetUserResourceString that uses
str = controllerContext.HttpContext.GetGlobalResourceObject(ResourceClassKey, resourceName, CultureInfo.CurrentUICulture) as string;

Even when I register my custom factory in <globalization> it is not used until I invoke GetGlobalResourceObject myself. In the next code s1 and s3 are different, actually s3 equals s2 !! (MethodCaller is a class to invoke methods by reflection)
string s1 = (string)MethodCaller.CallMethod(typeof(DefaultModelBinder), "GetValueInvalidResource", this.ControllerContext);
string s2 = (string)this.ControllerContext.HttpContext.GetGlobalResourceObject("DefaultModelBinderMessages","PropertyValueInvalid");
string s3 = (string)MethodCaller.CallMethod(typeof(DefaultModelBinder), "GetValueInvalidResource", this.ControllerContext);

Question is: why is the static constructor of my custom resource provider called when s2 is evaluated and NOT when System.Web.Mvc.DefaultModelBinder calls GetGlobalResourceObject during the evaluation of s1??

Michael Freidgeim
June 25, 2011

# Sliding expiration of localized ASP.NET resources

Hi Rick,
Have you considered Sliding expiration of localized ASP.NET resources? See my question at http://stackoverflow.com/questions/6480963/sliding-expiration-of-localized-asp-net-resources

Michael Freidgeim
June 29, 2011

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick,
We are planning to localize ASPX/ASCX pages/controls on our web site using your DbResourceProvider. Additionally we have a few look-up tables in the database(e.g. Country codes/Country Names) that also required translation. I thought to create another table with the same schema as your Localizations and run second instance of Admin and DbResourceProvider to maintain and use this second table. But looking at the code, it seems, that to change your current singleton implementation is possible, but will take some time. So we decided to store our look-up data in the same Localizations table just as extra global resources. Is it correct way? Do you see better solutions?
Thank you for the tool.

Rick Strahl
June 29, 2011

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@Michael - I think I would opt to add additional global resources for additional features. The problem isn't the singleton implementation I think but the fact that ASP.NET can only use a single Resource Provider at a time. So even if you can break out the singleton (which isn't difficult) you can't really tell ASP.NET to use more than one provider.

If you have 'reusable resources' that you want to use in several projects, you might implement some routines that can load those resources from either an existing resource file or an XML export from the database that you can import later.

Paraschiv Andrei
January 09, 2012

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

hello,
I am trying to adapt your code to create an updatable resource provider.
I am having the following problem with localresources.
Considering I have a local resource like so:
lblLocalRes.Text = this.GetLocalResourceObject(ResApp.App_LocalResources.Default_aspx.key) as string;

This works and triggers:
public override IResourceProvider CreateLocalResourceProvider(string virtualPath)

but if I use it like this:
lblLocalRes.Text = ResApp.App_LocalResources.Default_aspx.key;

it doesn't work(doesn't trigger CreateLocalResourceProvider)
With global resources both ways work.
Does anyone know what I am doing wrong?
Thank you in advance

Rick Strahl
January 09, 2012

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@Paraschiv - The localization provider only generates strongly typed resources for global resources. If you're using the same for local resources you either will find that no such class exists or if it does it's the default class that .NET generates for resource files. If it's the latter, those resources don't use the ASP.NET ResourceProvider (it only uses raw RESX localization use ResourceManager) and so no localization occurs.

For local resources you need to use the string based functions.

Faiz
November 12, 2012

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hey Rick,
Amazing work. In fact i saw this after i finished mine, but not as specific as this. Yours is no doubt awesome.
I had a requirement and had to fulfill, here is the scenario and the problem. Maybe youc an help.
-I want my controls to read values from .resx in app_localresources folder, which is working.
-I am generating other .resx from code, after reading the english resx and searching corresponding values from a table. This is also working fine.
-Now as soon as i generate it, the session expires clearing all the values.

I read your article and some place you said 'session is alright'. I didnt get the point.

Technically asp.net worker process is recycled bcuz it might have assemblies for resource file.

hence when session expires user is thrown on login page and when re-logs in, the resources are updated.

Kindly help me with this solution.

Regards,
Faiz

Michael
June 22, 2017

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

Hi Rick

I have implemented Globalization on MVC 5 platform. Just wanted to know, is it possible to load all resourcesets and resources on Application_Startup.

Thanks in advance

Michael


Rick Strahl
June 23, 2017

# re: Creating a data driven ASP.NET Resource Provider and Editor Article posted

@Michael - not directly but you can reference a resource in each resource set which forces the resource sets to load.

Personally I don't think I would do that - let it lazy load. Individually the overhead should be minimal (for RESX especially and for DB other than the very first DB access as well) and I think it's better to take a small first time hit when needed than trying to load them all up front.


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024