加载资源和QUOT;的.resx"从文件夹中的Silverlight [英] Load Resources ".resx" from folder in Silverlight

查看:117
本文介绍了加载资源和QUOT;的.resx"从文件夹中的Silverlight的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多语言的应用程序和客户想要像他想要编辑Resources.resx文件。 我创建Silverlight项目,并添加一些文件:

I have a multilanguage application 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"

一切工作,但这些文件被内嵌到XAP文件。而客户无法对其进行编辑。

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;
            }
        }

我怎样才能得到这个资源的一些文件夹,而不是建立他们.xap文件???

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:

考虑以下内容:

  • 在大多数我见过的解决方案需要具有约束力的声明中约80个字符长的的每一个条目的。这包括巧妙的转换器使用不到尽头。
  • 在我所看到的每一个执行字符串作为一个通知性质大多数解决方案(这似乎是一个庞大的开销,几乎没有改变过的字符串)。
  • 在本地化一般不需要即时更新(你总是可以刷新当前页面)。
  • 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).

有一个更简单的方法是只需将您的字符串,如名值对,在全球应用字典,并通过引用它们的短/简单的的StaticResource 的结合,例如

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}

剩下的问题是,然后就如何得到另一套语言字符串进入App词典(这其实很简单):

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

  • 直接把你的默认语言的字符串到你的App.xaml(这有助于开发为丢失的钥匙将导致异常)。
  • 通过任何方便的方法(XML文件,XAML文件,CSV,或通过Web服务数据库)
  • 拉任何新选择的语言下,从您的服务器
  • 与新加载的数据替换字典条目。你必须做的唯一的事情就是确保关键是已经present,或者你必须代替或设置之一添加一个条目。
  • 刷新当前页面(带他们回语言变化后的主页?)
  • 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?)

我不知道为什么每个人似乎都喜欢非常复杂的解决方案时,StaticResources做的工作就好了,用少了很多的努力。我们也倾向于使用web服务来获取一组语言串从数据库,因为它通常小于200K和数据库是远更新更加灵活。

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.

希望这有助于。

这篇关于加载资源和QUOT;的.resx"从文件夹中的Silverlight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆