views:

246

answers:

1

Hi

In my asp.net app a user can upload several localized images (of buttons) . For example, he will upload 'send.gif', 'send.fr.gif', 'send.en-UK,gif; etc..

When a visitor is coming to his page, I need to pick up the right file based on the visitor's locale.

Is there an api (or simple way) to find the best appropriate image based on the locale - for example, if a visitor is from France the API will return 'send.fr.gif', if the visitor is from Australia the API will return 'send.en.gif' etc...

The logic should be the same as ASP.NET pick the right localized resource file basically.

Thanks.

+1  A: 

It seems from your post that you already have a way to detect the users locale. So I will assume that you are holding this information.

The way that we do this is we store the users locale in session, and store all localised resources in corresponding directory names. eg:

/
    /images
        sendButton.gif
        background.gif
        /de-de/
            sendButton.gif
        /fr-fr/
            sendButton.gif

An HttpHandler is then used to map the localised directories over the top of the default directory, based on the current users locale. This allows for seamless integration of images into all code, and css, and will use the image in the base directory if no localised image is found.

If more sophisticated sorting is required then i would suggest nesting your countries inside your languages. like this:

/
    /images
        sendButton.gif
        background.gif
        /de
            /de
                sendButton.gif
        /fr
            sendButton.gif
            /fr
            /be

You can then specify lenguage level resources. And even have your http handler map files in suce a way that they propogate up rather than down the tree. So that the fr-fr resource will be used for all french speacking countries that dont have their own resource of that name.

Of course at this point it does become rather complex, especially when deciding which french speaking country is used as the default for the french language if none is specified. you may wish to start storing priorities somewhere in order to decide what you serve to which locale. And whether resources propogate up or down the tree. But as a transparent structure for localising images while keeping yoru markup and CSS clean this should work very well.

Jack Ryan
Thank you - but basically my question is how complicated is it to write the HttpHandler? There is not always a 1-1 mapping between UI locale and the directory. There need to be a fallback mechanism. For example if there is a fr-FR and a French Belgium (fr-BE) is coming -- where should he go?
LeJeune
I have responded to this by editing the post. Unfortunately if your need is this complex that I imagine you will have to store a weighetd mapping between locales. I still believe mapping the chosen resources over a standard directory is best from a markup and CSS point of view though.
Jack Ryan