开发者

How can I Localizing strings in code in WPF

Basically, what do I have to do to Localize something like this:

MessageBox.Show("Hello");

So depending on the culture it should show "Ciao", "Hola", "Bonjour", but this has to be done in the code, can't move it to the GUI.

开发者_StackOverflow

I know how to localize the GUI (with LocBaml), but that doesn't work with what I need, but I can imagine is something similar to what LocBaml does (expect the part where it generates an assembly maybe). I just need a pinpoint in the correct direction.

Thanks!


If your strings are already localized using resource dictionaries, you can use just

MessageBox.Show((string)Application.Current.Resources["IDS_HELLO"]);

This approach has however a small disadvantage that the text won't change automatically if the application's language is changed during the messagebox.Show. (Mind that the dynamic localization requires anyway additional effort from your side.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜