2

I have a web application which needs to support multiple languages. We currently have quite a lot of images on the site with text in them. Im trying to find a way to localize these images with the least amount of hassle. What i have come up with so far is to add sub folders to the current /Images folder which relate to the required language. So for example /Images contains the default set of images and /Images/es-MX contains the Spanish-Mexican localised images.

All pretty standard so far i think. Now the issue i have is that in order for this new structure to work i need to add the following to all img tags:

<img ... src="/images/<%= GetGlobalResourceObject("MyResource","IMAGEPATH").ToString() %>image1.gif" ../>

Or in the case of asp:ImageButton i need to programmatically set their ImageURL in codebehind with a utility method that replaces the /Images/ with /Images/es-MX or whatever the culture happens to be.

All of this leaves me with messy markup and lots of codebehind calls just to correct the image path. I ask you dear reader, is there a better way?

SecretDeveloper
  • 3,140
  • 2
  • 31
  • 36
  • Where is the requiered language comming from ? Is it available at the server ? – bang Feb 10 '09 at 13:21
  • Sorry im not sure what you mean by required language. Its a C# app but i dont think that matters regarding the question. – SecretDeveloper Feb 10 '09 at 14:26
  • It was your term 'requiered language' :-) What I ment was : How does the server know what language to serve ? Is it saved in a cookie on the client ? Or is it saved in the session on the server or how is it done ? – bang Feb 11 '09 at 07:52
  • Currently its saved in a cookie. In Global.asax im changing the current threads ui culture based on the cookies value during App_BeginRequest. – SecretDeveloper Feb 11 '09 at 08:27

1 Answers1

1

Here is a good article from MSDN on globalization in ASP.NET. It uses a resource file approach so I am not sure if that will work for you but here is the article:

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

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
  • 1
    I believe that you can also add image to the resource file. – Jedi Master Spooky Feb 10 '09 at 13:44
  • 1
    Yes you definitely can. I just meant that since all his images are currently stored on disk it may be difficult to move them all to resource files. – Andrew Hare Feb 10 '09 at 14:05
  • 2
    Thanks for the link. I do currently have resource files but even if i made the effort to place all the paths for the images into a resource file it still would not solve the issue i have regarding messy markup and codebehind. – SecretDeveloper Feb 10 '09 at 14:24