views:

74

answers:

2

Hi,

I am developing my first multilingual C# site and everything is going ok except for one crucial aspect. I'm not 100% sure what the best option is for storing strings (typically single words) that will be translated by code from my code behind pages.

On the front end of the site I am going to use asp.net resource files for the wording on the pages. This part is fine. However, this site will make XML calls and the XML responses are only ever in english. I have been given an excel sheet with all the words that will be returned by the XML broken into the different languages but I'm not sure how best to store/access this information. There are roughly 80 words x 7 languages.

I am thinking about creating a dictionary object for each language that is created by my global.asax file at application run time and just keeping it stored in memory. The plus side for doing this is that the dictionary object will only have to be created once (until IIS restarts) and can be accessed by any user without needing to be rebuilt but the downside is that I have 7 dictionary objects constantly stored in memory. The server is a Win 2008 64bit with 4GB of RAM so should I even be concerned with memory taken up by using this method?

What do you guys think would be the best way to store/retrieve different language words that would be used by all users?

Thanks for your input.

Rich

+1  A: 

From what you say, you are looking at 560 words which need to differ based on locale. This is a drop in the ocean. The resource file method which you have contemplated is fit for purpose and I would recommend using them. They integrate with controls so you will be making the most from them.

If it did trouble you, you could have them on a sliding cache, i.e. sliding cache of 20mins for example, But I do not see anything wrong with your choice in this solution.

OMO

Cheers,

Andrew

P.s. have a read through this, to see how you can find and bind values in different resource files to controls and literals and use programatically.

http://msdn.microsoft.com/en-us/magazine/cc163566.aspx

REA_ANDREW
Thanks for your help. My issue is that I am just looking to localize strings. These won't be tied to any controls so I don't think I can use the resx files for that. Can I?
Richard Reddy
What will you be using the localised strings for as in how will you display them to the user?
REA_ANDREW
I was thinking that on page load I would just call the dictionary object for the language I want based on the language selected and find the Key that matches the string I'm looking for. For example: if I wanted to replace the word "Door" that was returned by the XML and display it in French I would have something like: Dictionary<string, string> XMLWording = (Dictionary<string, string>)Application["FrenchXMLWording"]; then something like XMLWording["Door"]; to write onto screen. Hope that makes sense ;)
Richard Reddy
Just edit my post, added a link which will help you, as you can do what you require with resource files. i.e. programatic access and databinding is supported
REA_ANDREW
I didn't realise I could use the resource files for just random strings - I thought it had to match controls on the page. This is definately the solution for me as it only gives the user the text they need for that particular page without the overhead of storing everything in memory. Thanks for all your help!
Richard Reddy
No worries, always glad to help. :-)
REA_ANDREW
A: 

As long as you are aware of the impact of doing so then yes, storing this data in memory would be fine (as long as you have enough to do so). Once you know what is appropriate for the current user then tossing it into memory would be fine. You might look at something like MemCached Win32 or Velocity though to offload the storage to another app server. Use this even on your local application for the time being that way when it is time to push this to another server or grow your app you have a clear separation of concerns defined at your caching layer. And keep in mind that the more languages you support the more stuff you are storing in memory. Keep an eye on the amount of data being stored in memory on your lone app server as this could become overwhelming in time. Also, make sure that the keys you are using are specific to the language. Otherwise you might find that you are storing a menu in german for an english user.

Andrew Siemer