using Microsoft.Extensions.Localization; namespace Blahblah.FlowerApp; sealed class LocalizationResource { private static IStringLocalizer? localizer; public static IStringLocalizer? Localizer => localizer ??= #if __ANDROID__ MauiApplication #else MauiUIApplicationDelegate #endif .Current.Services.GetService>(); public static string GetText(string key, string defaultValue = "") { return Localizer?.GetString(key) ?? defaultValue; } } [ContentProperty(nameof(Key))] public class LangExtension : IMarkupExtension { public required string Key { get; set; } public string Default { get; set; } = string.Empty; public object ProvideValue(IServiceProvider _) { return LocalizationResource.GetText(Key, Default); } object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) => ProvideValue(serviceProvider); }