#nullable enable using System.Collections.Generic; using System.Linq; using BTCPayServer.Payments; using BTCPayServer.Plugins.Translations; using BTCPayServer.Services; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; namespace BTCPayServer; // We use a partial class here to avoid breaking existing plugins public static partial class Extensions { public static IServiceCollection AddDefaultTranslations(this IServiceCollection services, params string[] keyValues) { return services.AddDefaultTranslations(keyValues.Select(k => KeyValuePair.Create(k, string.Empty)).ToArray()); } public static IServiceCollection AddDefaultPrettyName(this IServiceCollection services, PaymentMethodId paymentMethodId, string defaultPrettyName) { services.AddSingleton(new PrettyNameProvider.UntranslatedPrettyName(paymentMethodId, defaultPrettyName)); return services.AddDefaultTranslations(KeyValuePair.Create(PrettyNameProvider.GetTranslationKey(paymentMethodId), defaultPrettyName)); } public static IServiceCollection AddDefaultTranslations(this IServiceCollection services, params KeyValuePair[] keyValues) { services.AddSingleton(new InMemoryDefaultTranslationProvider(keyValues)); return services; } public static IServiceCollection AddTranslationProvider(this IServiceCollection services) where T: class, IDefaultTranslationProvider { services.TryAddSingleton(); services.AddSingleton(o => o.GetRequiredService()); return services; } }