简体   繁体   English

.NET中的外部翻译

[英]External Translations in .NET

Good morning, 早上好,

I am interested in developing an application which supports external GUI translation files to be added as desired by the users. 我对开发一种应用程序感兴趣,该应用程序支持用户根据需要添加外部GUI转换文件。 I thought about using the localization methods built into .NET, but I think this way I cannot distribute isolated files with translations (can I?) after the application is built. 我考虑过使用.NET内置的本地化方法,但是我认为通过这种方式,在构建应用程序后,我无法分发带有翻译的隔离文件(可以吗?)。

What is the better way to achieve localization using external files in C#? 使用C#中的外部文件实现本地化的更好方法是什么?

Thank you very much. 非常感谢你。

I've seen a lot of people implementing their own localization system for .net, but personally, I would stay with the built in structure. 我见过很多人为.net实现自己的本地化系统,但就我个人而言,我会坚持使用内置结构。

Now, you can just add additional .resx files and recompile the app afterwards. 现在,您只需添加其他.resx文件,然后再重新编译该应用程序即可。 But I guess this is not what you want? 但是我想这不是你想要的吗?

Or you can implement your own Resource Provider and for example get all localization strings from a DB. 或者,您可以实现自己的资源提供程序,例如从数据库获取所有本地化字符串。

Example: 例:
http://msdn.microsoft.com/en-us/library/aa905797.aspx#exaspnet20rpm_topic4 http://msdn.microsoft.com/zh-CN/library/aa905797.aspx#exaspnet20rpm_topic4

You can use .NET localizations without any issues. 您可以使用.NET本地化而没有任何问题。

After you sucessfully localized yopur appliation files, in your application folder will contain subfolders for you localized versions of assembly resources. 成功地对yopur应用程序文件进行本地化之后,您的应用程序文件夹中将包含子文件夹,这些子文件夹用于您对程序集资源进行本地化的版本。 So after adding new language into localizations, you can distrubute these new DLLs to your castomers from folder for your newly added localizations. 因此,在将新语言添加到本地化之后,您可以将这些新的DLL从文件夹中分解为您的Castomer,以用于新添加的本地化。

Cheers ;) 干杯;)

If you don't want to recompile the files later you can use something like the folowing. 如果您不希望以后重新编译文件,则可以使用以下方法。

  1. Create multiple xml files with the same keys and different values for different locations. 使用相同的键和不同的值在不同的位置创建多个xml文件。 Or make one big file. 或制作一个大文件。 Save that file's path somewhere in app settings (or embed during build) 将该文件的路径保存在应用设置中的某个位置(或在构建过程中嵌入)
  2. Build your application with default language on forms (for e, english) 在表单上使用默认语言构建您的应用程序(例如,英语)
  3. On startup (or first startup) ask user to specify the language to use. 在启动(或首次启动)时,要求用户指定要使用的语言。
  4. On each form/window in constructor (after InitializeComponent() called) replace the texts on the form with values in XML. 在构造函数中的每个窗体/窗口上(在InitializeComponent()调用之后),将窗体上的文本替换为XML中的值。

Example xml: 范例XML:

<doc>
  <loc name="English">
    <form name = "main">
      <okButton>OK</okButton>
      ....
    </form>
    <form name = "about">
      <lblAuthorName>Author's name: </lblAuthorName>
      ....
    </form>
  </loc>
  <loc name="Ukrainian">
    <form name = "main">
      <okButton>Добре</okButton>
      ....
    </form>
  </loc>

</doc>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM