|
@@ -10,12 +10,55 @@ namespace PixiEditor.Views;
|
|
|
|
|
|
public class Translator : UIElement
|
|
|
{
|
|
|
+ public static readonly DependencyProperty KeyProperty = DependencyProperty.RegisterAttached(
|
|
|
+ "Key",
|
|
|
+ typeof(string),
|
|
|
+ typeof(Translator),
|
|
|
+ new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.AffectsRender, KeyPropertyChangedCallback));
|
|
|
+
|
|
|
+ public static readonly DependencyProperty TooltipKeyProperty = DependencyProperty.RegisterAttached(
|
|
|
+ "TooltipKey", typeof(string), typeof(Translator),
|
|
|
+ new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.AffectsRender, TooltipKeyPropertyChangedCallback));
|
|
|
+
|
|
|
+ public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached(
|
|
|
+ "Value",
|
|
|
+ typeof(string),
|
|
|
+ typeof(Translator),
|
|
|
+ new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.AffectsRender));
|
|
|
+
|
|
|
+ public static readonly DependencyProperty TooltipLocalizedStringProperty = DependencyProperty.RegisterAttached(
|
|
|
+ "TooltipLocalizedString",
|
|
|
+ typeof(LocalizedString),
|
|
|
+ typeof(Translator),
|
|
|
+ new FrameworkPropertyMetadata(default(LocalizedString), FrameworkPropertyMetadataOptions.AffectsRender, TooltipLocalizedStringPropertyChangedCallback));
|
|
|
+
|
|
|
+ private static void TooltipLocalizedStringPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
+ {
|
|
|
+ d.SetValue(FrameworkElement.ToolTipProperty, GetTooltipLocalizedString(d).Value);
|
|
|
+ ILocalizationProvider.Current.OnLanguageChanged += (lang) => OnLanguageChangedTooltipString(d, lang);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void OnLanguageChangedTooltipString(DependencyObject dependencyObject, Language lang)
|
|
|
+ {
|
|
|
+ LocalizedString localizedString = GetTooltipLocalizedString(dependencyObject);
|
|
|
+ LocalizedString newLocalizedString = new(localizedString.Key, localizedString.Parameters);
|
|
|
+
|
|
|
+ dependencyObject.SetValue(FrameworkElement.ToolTipProperty, newLocalizedString.Value);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static void TooltipKeyPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
+ {
|
|
|
+ d.SetValue(FrameworkElement.ToolTipProperty, new LocalizedString(GetTooltipKey(d)).Value);
|
|
|
+ ILocalizationProvider.Current.OnLanguageChanged += (lang) => OnLanguageChangedTooltipKey(d, lang);
|
|
|
+ }
|
|
|
+
|
|
|
private static void OnLanguageChangedKey(DependencyObject obj, Language newLanguage)
|
|
|
{
|
|
|
string key = GetKey(obj);
|
|
|
if (key != null)
|
|
|
{
|
|
|
- obj.SetValue(ValueProperty, new LocalizedString(key).Value);
|
|
|
+ UpdateKey(obj, key);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -28,22 +71,6 @@ public class Translator : UIElement
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static readonly DependencyProperty KeyProperty = DependencyProperty.RegisterAttached(
|
|
|
- "Key",
|
|
|
- typeof(string),
|
|
|
- typeof(Translator),
|
|
|
- new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.AffectsRender, KeyPropertyChangedCallback));
|
|
|
-
|
|
|
- public static readonly DependencyProperty TooltipKeyProperty = DependencyProperty.RegisterAttached(
|
|
|
- "TooltipKey", typeof(string), typeof(Translator),
|
|
|
- new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.AffectsRender, TooltipKeyPropertyChangedCallback));
|
|
|
-
|
|
|
- private static void TooltipKeyPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
- {
|
|
|
- d.SetValue(FrameworkElement.ToolTipProperty, new LocalizedString(GetTooltipKey(d)).Value);
|
|
|
- ILocalizationProvider.Current.OnLanguageChanged += (lang) => OnLanguageChangedTooltipKey(d, lang);
|
|
|
- }
|
|
|
-
|
|
|
public static void SetTooltipKey(DependencyObject element, string value)
|
|
|
{
|
|
|
element.SetValue(TooltipKeyProperty, value);
|
|
@@ -58,54 +85,53 @@ public class Translator : UIElement
|
|
|
{
|
|
|
if (e.NewValue is string key)
|
|
|
{
|
|
|
- LocalizedString localizedString = new(key);
|
|
|
- Binding binding = new()
|
|
|
- {
|
|
|
- Path = new PropertyPath("(0)", Translator.ValueProperty),
|
|
|
- RelativeSource = new RelativeSource(RelativeSourceMode.Self)
|
|
|
- };
|
|
|
-
|
|
|
- if(d is TextBox textBox)
|
|
|
- {
|
|
|
- textBox.SetBinding(TextBox.TextProperty, binding);
|
|
|
- }
|
|
|
- else if (d is TextBlock textBlock)
|
|
|
- {
|
|
|
- textBlock.SetBinding(TextBlock.TextProperty, binding);
|
|
|
- }
|
|
|
- else if (d is Run run)
|
|
|
- {
|
|
|
- run.SetBinding(Run.TextProperty, binding);
|
|
|
- }
|
|
|
- else if (d is ContentControl contentControl)
|
|
|
- {
|
|
|
- contentControl.SetBinding(ContentControl.ContentProperty, binding);
|
|
|
- }
|
|
|
- else if (d is HeaderedItemsControl menuItem)
|
|
|
- {
|
|
|
- menuItem.SetBinding(HeaderedItemsControl.HeaderProperty, binding);
|
|
|
- }
|
|
|
- else if (d is LayoutContent layoutContent)
|
|
|
- {
|
|
|
- layoutContent.SetValue(LayoutContent.TitleProperty, localizedString.Value);
|
|
|
- }
|
|
|
-
|
|
|
- d.SetValue(ValueProperty, localizedString.Value);
|
|
|
+ UpdateKey(d, key);
|
|
|
ILocalizationProvider.Current.OnLanguageChanged += (lang) => OnLanguageChangedKey(d, lang);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached(
|
|
|
- "Value",
|
|
|
- typeof(string),
|
|
|
- typeof(Translator),
|
|
|
- new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.AffectsRender));
|
|
|
+ private static void UpdateKey(DependencyObject d, string key)
|
|
|
+ {
|
|
|
+ LocalizedString localizedString = new(key);
|
|
|
+ Binding binding = new()
|
|
|
+ {
|
|
|
+ Path = new PropertyPath("(0)", ValueProperty),
|
|
|
+ RelativeSource = new RelativeSource(RelativeSourceMode.Self)
|
|
|
+ };
|
|
|
+
|
|
|
+ if (d is TextBox textBox)
|
|
|
+ {
|
|
|
+ textBox.SetBinding(TextBox.TextProperty, binding);
|
|
|
+ }
|
|
|
+ else if (d is TextBlock textBlock)
|
|
|
+ {
|
|
|
+ textBlock.SetBinding(TextBlock.TextProperty, binding);
|
|
|
+ }
|
|
|
+ else if (d is Run run)
|
|
|
+ {
|
|
|
+ run.SetBinding(Run.TextProperty, binding);
|
|
|
+ }
|
|
|
+ else if (d is ContentControl contentControl)
|
|
|
+ {
|
|
|
+ contentControl.SetBinding(ContentControl.ContentProperty, binding);
|
|
|
+ }
|
|
|
+ else if (d is HeaderedItemsControl menuItem)
|
|
|
+ {
|
|
|
+ menuItem.SetBinding(HeaderedItemsControl.HeaderProperty, binding);
|
|
|
+ }
|
|
|
+ else if (d is LayoutContent layoutContent)
|
|
|
+ {
|
|
|
+ layoutContent.SetValue(LayoutContent.TitleProperty, localizedString.Value);
|
|
|
+ }
|
|
|
+
|
|
|
+ d.SetValue(ValueProperty, localizedString.Value);
|
|
|
+ }
|
|
|
|
|
|
public static void SetKey(DependencyObject element, string value)
|
|
|
{
|
|
|
element.SetValue(KeyProperty, value);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static string GetKey(DependencyObject element)
|
|
|
{
|
|
|
return (string)element.GetValue(KeyProperty);
|
|
@@ -115,4 +141,14 @@ public class Translator : UIElement
|
|
|
{
|
|
|
return (string)element.GetValue(ValueProperty);
|
|
|
}
|
|
|
+
|
|
|
+ public static LocalizedString GetTooltipLocalizedString(DependencyObject element)
|
|
|
+ {
|
|
|
+ return (LocalizedString)element.GetValue(TooltipLocalizedStringProperty);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void SetTooltipLocalizedString(UIElement element, LocalizedString value)
|
|
|
+ {
|
|
|
+ element.SetValue(TooltipLocalizedStringProperty, value);
|
|
|
+ }
|
|
|
}
|