从resx手动检索资源值?

是否可以从未设置为当前用户文化的资源文件中获取值? 我们的应用程序是基于数据的,与基于文化的相反。

例如,文档是法语文档,需要更新特定标签和字段并用新数据替换。

是否可以指示资源管理器使用法语.resx而不是默认的.resx?

您可以使用ResourceManager.GetString()方法并提供所需的区域性作为参数:

var culture = CultureInfo.CreateSpecificCulture("fr-FR"); var localizedString = ResourceManager.GetString("labelName", culture); 

您可以将语言类型设置为其中一个表单中的标签文本,然后选择要向最终用户显示的语言与使用该标签文本IE的语言进行比较,如果标签文本是法语,则可以显示所有你的法语控制名称

NOte:它只能在您用法语创建resx文件后手动重写法语中的所有标签和按钮控件名称,如此名称值。

  Name value ----------- ------------- lblname.text frenchtype name using System; using System.IO; using System.Linq; using System.Data; using System.Text; using System.Diagnostics; using System.Windows.Forms; using System.Collections.Generic; using System.ComponentModel; public partial class Form1 : Form { public form1() { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR"); getlanguagaefile(); InitializeComponent(); } // blah // blah private void getlanguagaefile() { if (label1.Text == "French") { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR"); ComponentResourceManager resources = new ComponentResourceManager(typeof(Wait)); resources.ApplyResources(this, "$this"); applyResources(resources, this.Controls); } } 

您可以在加载表单时向所有标签文本和按钮文本显示法语

  private void applyResources(ComponentResourceManager resources, Control.ControlCollection controlCollection) { foreach (Control ctl in controlCollection) { resources.ApplyResources(ctl, ctl.Name); applyResources(resources, ctl.Controls); } } } 

您可以通过本地化来实现,其中资源文件被调整为您希望支持的不同语言。 以下链接,从这里取得应该得到你想要的。

“ .NET本地化,第1部分:资源管理器 – 在”为多种语言创建资源“下进行检查,以获得良好的开端。

.NET本地化,第2部分:创建附属程序集

.NET本地化,第3部分:本地化文本

.NET本地化,第4部分:本地化单元 “