Skip to content

Latest commit

 

History

History
291 lines (273 loc) · 22.5 KB

kb-common-localizableresourceextension.md

File metadata and controls

291 lines (273 loc) · 22.5 KB
title description page_title type slug position tags res_type
How to Utilize the LocalizableResourceExtension Markup Extension
This article shows how you can use the LocalizableResourceExtension markup extension.
Utilizing the LocalizationResourceExtension Markup Extension
how-to
kb-common-localizableresourceextension
0
wpf, localization, localizableresourceextension, dynamic, support dynamic localization
kb

Environment

Product Version 2024.2.514
Product Telerik UI for WPF

Description

This article will showcase how to utilize the [LocalizableResourceExtension]({%slug common-localization%}#localizableresourceextension) to support [dynamic localization]({%slug common-localization%}#dynamic-localization).

The example will use the tooltips of the minimize, maximize, and close buttons of the RadWindow control as they do not support dynamic localization. The used theme will be Windows 11.

Solution

Create a new .resx file that will contain the localized strings for the tooltips of the minimize, restore, maximize, and close buttons. Then, assign it to the ResourceManager property of the LocalizationManager class as shown [here]({%slug common-localization%}#localization-using-resourcemanager).

[C#] Setting a new .resx file to the ResourceManager property of the LocalizationManager

{{region kb-common-localizableresourceextension-0}} LocalizationManager.Manager = new LocalizationManager() { ResourceManager = MyResources.ResourceManager }; {{endregion}}

English translation for the tooltips texts

English translation for the tooltips texts

German translation for the tooltips texts

German translation for the tooltips texts

To apply the LocalizableResourceExtension markup extension on the buttons' ToolTip instances, extract the default ControlTemplate of the RadWindow element.

[XAML] Default ControlTemplate of the RadWindow control for the Windows 11 theme

{{region kb-common-localizableresourceextension-1}} <Style TargetType="telerik:RadWindow" BasedOn="{StaticResource RadWindowStyle}"> <Setter.Value> <Grid.RowDefinitions> </Grid.RowDefinitions> <Grid.ColumnDefinitions> </Grid.ColumnDefinitions> <Grid.ColumnDefinitions> </Grid.ColumnDefinitions> <telerik:RadButton x:Name="PART_MinimizeButton" Command="{x:Static telerik:WindowCommands.Minimize}" Style="{StaticResource WindowButtonStyle}" Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource BooleanToVisibilityConverter}}"> <ToolTipService.ToolTip> </ToolTipService.ToolTip> <telerik:RadGlyph Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadButton}}}" Glyph="{StaticResource GlyphMinimize}" FontSize="{telerik:Windows11Resource ResourceKey=GlyphCompactFontSize}"/> </telerik:RadButton> <telerik:RadButton x:Name="PART_RestoreButton" Command="{x:Static telerik:WindowCommands.Restore}" Style="{StaticResource WindowButtonStyle}" Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource BooleanToVisibilityConverter}}"> <ToolTipService.ToolTip> </ToolTipService.ToolTip> <telerik:RadGlyph Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadButton}}}" Glyph="{StaticResource GlyphWindowCollapse}" FontSize="{telerik:Windows11Resource ResourceKey=GlyphCompactFontSize}"/> </telerik:RadButton> <telerik:RadButton x:Name="PART_MaximizeButton" Command="{x:Static telerik:WindowCommands.Maximize}" Style="{StaticResource WindowButtonStyle}" Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource BooleanToVisibilityConverter}}"> <ToolTipService.ToolTip> </ToolTipService.ToolTip> <telerik:RadGlyph Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadButton}}}" Glyph="{StaticResource GlyphWindow}" FontSize="{telerik:Windows11Resource ResourceKey=GlyphCompactFontSize}"/> </telerik:RadButton> <telerik:RadButton x:Name="PART_CloseButton" Command="{x:Static telerik:WindowCommands.Close}" Style="{StaticResource WindowCloseButtonStyle}" Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource BooleanToVisibilityConverter}}"> <ToolTipService.ToolTip> </ToolTipService.ToolTip> <telerik:RadGlyph Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadButton}}}" Glyph="{StaticResource GlyphClose}" FontSize=" {telerik:Windows11Resource ResourceKey=GlyphCompactFontSize}"/> </telerik:RadButton> <ControlTemplate.Triggers> <Trigger.EnterActions> </Trigger.EnterActions> <MultiTrigger.Conditions> </MultiTrigger.Conditions> <MultiTrigger.Conditions> </MultiTrigger.Conditions> <MultiTrigger.EnterActions> </MultiTrigger.EnterActions> <MultiTrigger.Conditions> </MultiTrigger.Conditions> <MultiTrigger.EnterActions> </MultiTrigger.EnterActions> <MultiTrigger.Conditions> </MultiTrigger.Conditions> </ControlTemplate.Triggers> </Setter.Value> </Style> {{endregion}}

Locate the ToolTipService.ToolTip attached properties on the RadButton instances for the minimize, restore, maximize, and close behavior. Then, you can use the LocalizableResourceExtension markup extension to set the custom localizable string.

[XAML] Using the LocalizableResourceExtension markup extension on the tooltips for the buttons of RadWindow

{{region kb-common-localizableresourceextension-2}} <telerik:RadButton x:Name="PART_MinimizeButton" Command="{x:Static telerik:WindowCommands.Minimize}" Style="{StaticResource WindowButtonStyle}" Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource BooleanToVisibilityConverter}}"> <ToolTipService.ToolTip> </ToolTipService.ToolTip> <telerik:RadGlyph Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadButton}}}" Glyph="{StaticResource GlyphMinimize}" FontSize="{telerik:Windows11Resource ResourceKey=GlyphCompactFontSize}"/> </telerik:RadButton> <telerik:RadButton x:Name="PART_RestoreButton" Command="{x:Static telerik:WindowCommands.Restore}" Style="{StaticResource WindowButtonStyle}" Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource BooleanToVisibilityConverter}}"> <ToolTipService.ToolTip> </ToolTipService.ToolTip> <telerik:RadGlyph Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadButton}}}" Glyph="{StaticResource GlyphWindowCollapse}" FontSize="{telerik:Windows11Resource ResourceKey=GlyphCompactFontSize}"/> </telerik:RadButton> <telerik:RadButton x:Name="PART_MaximizeButton" Command="{x:Static telerik:WindowCommands.Maximize}" Style="{StaticResource WindowButtonStyle}" Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource BooleanToVisibilityConverter}}"> <ToolTipService.ToolTip> </ToolTipService.ToolTip> <telerik:RadGlyph Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadButton}}}" Glyph="{StaticResource GlyphWindow}" FontSize="{telerik:Windows11Resource ResourceKey=GlyphCompactFontSize}"/> </telerik:RadButton> <telerik:RadButton x:Name="PART_CloseButton" Command="{x:Static telerik:WindowCommands.Close}" Style="{StaticResource WindowCloseButtonStyle}" Visibility="{Binding IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource BooleanToVisibilityConverter}}"> <ToolTipService.ToolTip> </ToolTipService.ToolTip> <telerik:RadGlyph Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadButton}}}" Glyph="{StaticResource GlyphClose}" FontSize="{telerik:Windows11Resource ResourceKey=GlyphCompactFontSize}"/> </telerik:RadButton> {{endregion}}

Enabled dynamic localization on the RadWindow's buttons' tooltips

Enabled dynamic localization on the RadWindow's buttons' tooltips