.NET Globalization & Satellite DLL's

萝らか妹 提交于 2019-12-04 13:27:52

问题


I'm working on localizing an app I've written in C#.

Everything seems to be working nicely, using satellite resource assemblies to translate each form's strings (as per this tutorial: http://msdn.microsoft.com/en-us/library/y99d1cd3%28VS.71%29.aspx)

However, the application will ultimately require quite a number of languages, which means loads of directories in my working directory (i.e. /zh-tw, /zh-cn, /fr-FR, /ja-JP, etc). I'd like to clean this up a bit by locating all of them within a /languages or /resources subdirectory (in other words, set the "base path for satellite assemblies"). But I've searched high and low, and been unable to find any way to customize the location of these satellite assemblies.

Any tips would be greatly appreciated!


回答1:


Found an even easier solution - in app.config:

<configuration>
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <probing privatePath=".;Lang" />
  </assemblyBinding>
</runtime>
</configuration>

Then you can just toss all those dirs in the "Lang" subdir and it'll work right out of the box! A post-build event is also handy to auto-copy them in there after compilation :)




回答2:


Using Resources in Your Application Part I - Simple Embedding.




回答3:


IMHO, I wouldn't change anything here. There is a standard mechanism for localization in .NET, which is based on satellite dlls and these subdirectories. If you use a tool for localization, eg. Passolo, it will also support exactly this structure and nothing else.

There will be a lot of subdirectories ... so what? Everything else will be quite complicated.




回答4:


Add all your resource files (i.e. *.resx) to /Resource folder and create the object of ResourceManager as below

System.Resources.ResourceManager rm = new System.Resources.ResourceManager("ApplicationName.Resources.MyResource", Assembly.GetExecutingAssembly());

Here say for lang de-DE your resx file will be named as MyResource.de-DE.resx



来源:https://stackoverflow.com/questions/1892433/net-globalization-satellite-dlls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!