4

Our goal is to offer to user setting up different application language and formatting (e.g. texts in English but Date/Number formats in German). So far I have tried different ways and most promising is this one (of course simplified hardcoded version):

var german = new CultureInfo("de-DE");
var english = new CultureInfo("en-US");

Thread.CurrentThread.CurrentCulture = german;
CultureInfo.DefaultThreadCurrentCulture = german;

Thread.CurrentThread.CurrentUICulture = english;
CultureInfo.DefaultThreadCurrentUICulture = english;
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(english.IetfLanguageTag)));

Unfortunately the last line enforce also English formatting for dates and numbers(not just for text). And there is no "CultureProperty" in FrameworkElement to override. So is there a way how to achieve desired behavior without using StringFormat everywhere?

When I try to use german culture for the last line instead of english, then some of the texts are in german instead of english (which is again not correct).

  • What happens if you don't override the LanguageProperty metadata? Without setting a Language, most Converters and stuff will default to english anyway – almulo Jun 11 '15 at 16:18
  • Then the language is sometimes broken. For example I display message-box when user is closing an application (so its a reaction on OnClosing event), but the text in it is in german although both CurrentUICulture properties from above code are set to english. Even when I debug into the message displaying itself the "Thread.CurrentThread.CurrentUICulture" is for unknown reason the german one. – Jan Nohavica Jun 11 '15 at 17:42

1 Answers1

-1

You can use WPF Converter to change culture setting by default.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Malitha Shan
  • 21
  • 1
  • 3
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Lukas Kabrt Oct 25 '15 at 18:52
  • @LukasKabrt: "Use WPF converter to change culture setting", while atrociously terse, *is* an answer. – Nathan Tuggy Oct 26 '15 at 00:46