开发者

Load Resources ".resx" from folder in Silverlight

I have a multilanguage applicati开发者_StackOverflow中文版on and customer wants to edit Resources.resx files like he wants. I created silverlight project and add some files:

  1. Resources.resx
  2. Resources.en-US.resx1.
  3. Resources.uk-UA.resx2.

They all have build action "Embedded Resource"

Everything is working but Those files are embeded to XAP file. And customer cannot edit them.

My resource manager i get like that:

   private static ResourceManager manager;
        public static ResourceManager Manager
        {
            get
            {
                if (manager == null)
                    manager =  new ResourceManager("Project.Resources", Assembly.GetExecutingAssembly());
                return manager;
            }
        }

How can i get this resources from some folder and not build them to .xap file ???


As this is a string localisation problem only, and you just want the flexibility of selecting an entire set of localised content, there are several methods out there for binding your strings to a resource manager. Most of them are overly complex for the desired result:

Given the following:

  • Most solutions I have seen require a binding statement about 80 character long for every single entry. This includes no end of clever Converter use.
  • Most solutions I have seen implement every string as a notify property (this seems a massive overhead for strings that hardly ever change).
  • Localisation generally does not require an instantaneous update (you can always refresh the current page).

A far simpler approach is to simply place your strings, as name value pairs, in the global App dictionary and reference them via a short/simple StaticResource binding e.g.

Text={StaticResource L_MenuHome}

The remaining problem is then just how to get another set of language strings into the App dictionary (which is actually quite easy):

  • Put your default languages strings directly into your App.xaml (this helps in development as missing keys will result in an exception).
  • Pull any newly chosen language down from your server via any convenient means (XML file, XAML file, CSV, or from a database via webservice)
  • Replace the dictionary entries with the newly loaded data. The only thing you must do is make sure the key is already present, or you must add an entry instead or setting one.
  • Reload the current page (take them back to the home page after a language change?)

I don't know why everyone seems to love the really complex solutions when StaticResources do the job just fine and with a lot less effort. We also tend to use a webservice to fetch a set of language strings from a database as it is generally less than 200K and databases are far more flexible for updates.

Anyway, just trying to put some commonsense back into localisation. It works for us. Feel free to use, ignore, suggest improvements etc.

Hope this helps.


You could try downloading the appropriate file and storing it in your isolated storage and try reading it from there. you could do this on application startup

Since you only have strings in your resx i would suggest that you copy your resource items into a simple text with some predefined format and reading it from there. Let me know if you need help on any specific implementation details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜