private void SetLanguageEntites(string languageTag) { // Use BCP47 Format string bcp47Tag = GetRegionFromBCP47LanguageTag(languageTag); //Apply the PrimaryLanguage ApplicationLanguages.PrimaryLanguageOverride = languageTag; if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5)) { // set user language if (Windows.Globalization.Language.IsWellFormed(languageTag)) { try { //Set the Region GlobalizationPreferences.TrySetHomeGeographicRegion(bcp47Tag); //Set the Speech Language Task.Run(async() => { Language speechLanguage = new Language(languageTag); await SpeechRecognizer.TrySetSystemSpeechLanguageAsync(speechLanguage); }); } catch (InvalidCastException) { // This is indicitive of EmbeddedMode not being enabled (i.e. // running IotCoreDefaultApp on Desktop or Mobile without // enabling EmbeddedMode) // https://developer.microsoft.com/en-us/windows/iot/docs/embeddedmode } } } //Only for ApiContract > 5 }
private void SetLanguageEntities(string languageTag) { // Use BCP47 Format string bcp47Tag = GetRegionFromBCP47LanguageTag(languageTag); // Apply the PrimaryLanguage ApplicationLanguages.PrimaryLanguageOverride = languageTag; if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5)) { // Set user language if (Language.IsWellFormed(languageTag)) { try { // Set the Region GlobalizationPreferences.TrySetHomeGeographicRegion(bcp47Tag); // Set the Speech Language Task.Run(async() => { Language speechLanguage = new Language(languageTag); await SpeechRecognizer.TrySetSystemSpeechLanguageAsync(speechLanguage); }); } catch (UnauthorizedAccessException ex) { // This is indicative of EmbeddedMode not being enabled (i.e. // running on Desktop or Mobile without enabling EmbeddedMode) // https://developer.microsoft.com/en-us/windows/iot/docs/embeddedmode App.LogService.Write(ex.ToString()); App.LogService.Write("UnauthorizedAccessException: Check to see if Embedded Mode is enabled"); } } } // Only for ApiContract > 5 }