using Microsoft.Extensions.Localization; using System.Text; namespace Blahblah.FlowerStory; [ContentProperty(nameof(Key))] public class LocalizeExtension : IMarkupExtension { //private IStringLocalizer Localizer { get; } public string Key { get; set; } //public LocalizeExtension() //{ // Localizer = MauiApplication.Current.Services.GetService>(); //} public object ProvideValue(IServiceProvider _) { return LocalizationResource.Localizer.GetString(Key); } object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) => ProvideValue(serviceProvider); } sealed class LocalizationResource { private static IStringLocalizer localizer; public static IStringLocalizer Localizer => localizer ??= MauiApplication.Current.Services.GetService>(); public static string GetText(string key) { return Localizer.GetString(key); } }