locked
Is there a way to change the apps language during runtime?

    Question

  • And without resorting to the control panel?
    Wednesday, November 14, 2012 5:22 PM

Answers

  • Yes, APIs like CompareStringEx should change their behavior; the purpose of primaryLanguageOverride is to override the user's settings in all these ways.

    As for waiting, I don't know for certain. You will receive the WinJS.Resources.oncontextchanged event which might be a good time to refresh (it’s typically where you call WinJS.Resources.processAll to respond to a language change).

    If there are uncertainties with the timing, CompareStringEx does take an optional locale parameter, and because you know what language you're using you should be able to provide that directly.

    • Proposed as answer by Marcus Ilgner Thursday, November 15, 2012 8:23 PM
    • Marked as answer by Song Tian Tuesday, November 20, 2012 9:53 AM
    Thursday, November 15, 2012 7:28 PM

All replies

  • Yes, there is. Here's a quote from Chapter 17 of my book on the subject:

    "If you like, you can allow the user to select the language for the app independent of the system settings. This is done by setting the Windows.Globalization.ApplicationLanguages.primaryLanguageOverride property, as demonstrated in Scenario 10 the Application resources and localization sample. Scenario 11 also shows loading specific language resources rather than the default."

    .Kraig
    Author, Programming Windows 8 Apps with HTML, CSS, and JavaScript, a free ebook from Microsoft Press.

    • Proposed as answer by Astro-Boy Friday, April 26, 2013 9:57 AM
    Thursday, November 15, 2012 5:13 AM
  • Will this also affect collation/sorting done in a component DLL via CompareStringEx or only reload strings and other localized resources for the current app?

    If CompareStringEx behaviour changes - documentation for primaryLanguageOverride states that the change will not take effect immediately - how long will I need to wait approximately, before its behaviour changes?

    Thursday, November 15, 2012 12:39 PM
  • Yes, APIs like CompareStringEx should change their behavior; the purpose of primaryLanguageOverride is to override the user's settings in all these ways.

    As for waiting, I don't know for certain. You will receive the WinJS.Resources.oncontextchanged event which might be a good time to refresh (it’s typically where you call WinJS.Resources.processAll to respond to a language change).

    If there are uncertainties with the timing, CompareStringEx does take an optional locale parameter, and because you know what language you're using you should be able to provide that directly.

    • Proposed as answer by Marcus Ilgner Thursday, November 15, 2012 8:23 PM
    • Marked as answer by Song Tian Tuesday, November 20, 2012 9:53 AM
    Thursday, November 15, 2012 7:28 PM
  • Kraig, thanks for the clarification. Indeed we adapted our SQLite component so we can explicitly set the language used for collation and now trigger setting this property upon receiving the oncontextchanged event.
    Thursday, November 15, 2012 8:25 PM