Windows Phone 8.1 Application Multilingual Interface

I am creating a Windows Phone 8.1 application in SilverLight with Visual Studio 2015. I am creating a multilingual application in English and Arabic. To do this, I created the Strings folder in the project with two en-US and ar-KW folders with the Resources.resw file in each folder.

I set the x: Uid properties . for exampleKey:- Actual.Text Value:- Actual

<TextBlock x:Uid="Actual" TextWrapping="Wrap" MaxWidth="65" HorizontalAlignment="Center" />

The above works very well. I have combobox with elements EN and AR. I fire the SelectionChanged event to change the language But the problem is that I stop the application and fire it again, than just changing its text and layout.

How can I do this at runtime without rebooting.

private void LanguageComboBoxName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string selectedItem = (e.AddedItems[0] as ComboBoxItem).Content as string;
            var RootFrame = Window.Current.Content as SlideApplicationFrame;

            if (selectedItem == "EN")
                ApplicationLanguages.PrimaryLanguageOverride = "en-US";
            else if (selectedItem == "AR")
                ApplicationLanguages.PrimaryLanguageOverride = "ar-KW";

            RootFrame.Navigate(this.GetType());
    }
+4
2

, Microsoft ( ), , . - combobox , , , ( ), , . , ( ). .

:

ApplicationLanguages.PrimaryLanguageOverride = "xx-XX";

, . .

, , , , , (, 12/01/2015 01-12-2015).

string lang = "en-US";    //default
var culture = new CultureInfo(lang);
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = lang;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

.

, , Generate app bundle "Never". , . . , , , , ( , ).

+4

, , . ApplicationLanguage .

, App.Xaml.cs InitializePhoneApplication() ( ApplicationLanguages.PrimaryLanguageOverride)

string savedLanguage = string.Empty;
var hasSavedLanguage = AppSettings.TryGetSetting(Constants.LanguageSettingKey, out savedLanguage);
if (hasSavedLanguage)
{
  Thread.CurrentThread.CurrentUICulture = new CultureInfo(savedLanguage);
  Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture;
}

, ,

0

Source: https://habr.com/ru/post/1616479/


All Articles