mirror of
https://github.com/Maplespe/DWMBlurGlass.git
synced 2026-12-01 15:55:39 -05:00
40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
using DWMBlurGlassGUI.Services;
|
|
using System;
|
|
using System.Windows.Data;
|
|
using System.Windows.Markup;
|
|
|
|
namespace DWMBlurGlassGUI.Helpers
|
|
{
|
|
/// <summary>
|
|
/// XAML Markup Extension for localized strings
|
|
/// Usage: Text="{helpers:Localize Key=general}"
|
|
/// </summary>
|
|
[MarkupExtensionReturnType(typeof(string))]
|
|
public class LocalizeExtension : MarkupExtension
|
|
{
|
|
public string Key { get; set; } = string.Empty;
|
|
public string Default { get; set; } = string.Empty;
|
|
|
|
public LocalizeExtension() { }
|
|
|
|
public LocalizeExtension(string key)
|
|
{
|
|
Key = key;
|
|
}
|
|
|
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
|
{
|
|
if (string.IsNullOrEmpty(Key))
|
|
return Default;
|
|
|
|
var binding = new Binding($"[{Key}]")
|
|
{
|
|
Source = LanguageService.Instance,
|
|
Mode = BindingMode.OneWay
|
|
};
|
|
|
|
return binding.ProvideValue(serviceProvider);
|
|
}
|
|
}
|
|
}
|