I need to localize my UWP application to German language.I am maintaining two resource files for English and German. I have added a button as follow.
<Button
x:Name="localizationButton"
Width="32"
Height="32"
Padding="0"
Click="SettingsButton1_Click">
<Image
Margin="4"
Source="ms-appx:///Assets/Images/Common/AppBarIcons/LocalisationIcon.png"
Stretch="Uniform" />
<Button.Flyout>
<MenuFlyout x:Name="DropdownFlyout">
<MenuFlyoutItem Text="English" Click="MenuFlyoutItem_Click_En" />
<MenuFlyoutItem Text="Deutsch " Click="MenuFlyoutItem_Click_De" />
</MenuFlyout>
</Button.Flyout>
</Button>
When changing the language to German executes the following method.
private async void MenuFlyoutItem_Click_De(object sender, RoutedEventArgs e)
{
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "de-DE";
ApplicationData.Current.LocalSettings.Values["LanguagePreference"] = "de-DE";
ChangeLanguage("de-DE");
await Task.Delay(100);
Frame.Navigate(this.GetType());
}
However it doesn't change the text in the ui elements which used x:Uid and bind the text from resources file.
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="{StaticResource PrimaryFontSize16}"
FontWeight="SemiBold"
Style="{StaticResource PrimaryTextBlockStyle}"
x:Uid="/Util/Resources/UsernameText"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" />
This is how the above button text refer in resources.resw file.
<data name="UsernameText.Text"
xml:space="preserve">
<value>Username</value>
it only translates the words which binds from the code behind as below.
LblLoginSubHeader.Text = ResourceHandler.Get("info_262");
However if I restart the app only all the words(both UI and code behind) get translated to selected language.
How can I fix this.I need to translate the words once the language preference changes from the dropdown,without restarting the app.
UsernameText? If you follow the official steps, can you reproduce the same problem?