问题描述
1.- I am looking for some example of multilanguage application in C#. I'm not talking about entering the text of each language by hand.
2.- In WPF I have several ComboBox linked to a table in a Sql Server database. How can I translate the texts retrieved from the database into the active language? I do not want to add in each table a text field for each language.
我尝试过:
What I have tried:
What have you tried?
What have you tried?
推荐答案
Thread.CurrentThread.CurrentCulture
Thread.CurrentThread.CurrentUICulture
你可以查询或者在运行时设置:
which you can either query or set at runtime:
Thread.CurrentThread.CurrentCulture = new CultureInfo(options.LanguageSelected);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(options.LanguageSelected);
参考: []
引用的项目使用此信息查找正确的* .resx文件,以获得用户可能正在寻找的最佳语言匹配。
如何在数据库表中使用它完全取决于你和取决于所有结构(你不知道什么,所以我只能猜测)。但是简单地说,如果你想从表中检索字符串,为什么不用这样的字符串表:
Reference: Edi/App.xaml.cs at master · Dirkster99/Edi · GitHub[^]
The referenced project uses this information to find the right *.resx file for the best language match a user might be looking for.
How you use this in a database table is completely up to you and depends and the other all structure (about which you are telling nothing so I am left to guessing). But simply put, if you jsut want to retrieve strings from a table, why not having a table with strings like this:
Create Table MyStrings
(
id int not null,
mystring varchar(255) not null,
langid int not null
)
其中langid标识给定字符串的语言,而id本身应该是唯一的识别每个字符串 - 然后您可以使用此结构查找尚未翻译的字符串,或者确定是否存在翻译。
当然,您应该始终以基本语言提供所有必需的字符串(例如,英语)至少。确保这一点的最佳方法可能是对其进行单元测试......
where the langid identifies the language of a given string and the id itself should be unique to identify each string - you can then use this structure to find strings you have not translated, yet, or determine if there is a translation at all.
You should of course always have all required strings available in a base language (eg. English) at the very least. The best way of ensuring this might be unit testing against it...
这篇关于C#中带有文本SQL服务器表的多语言应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!