| | | 1 | | using Microsoft.Extensions.DependencyInjection; |
| | | 2 | | using TeleFlow.Telegram.Formatting; |
| | | 3 | | |
| | | 4 | | namespace TeleFlow.Telegram.I18n.Fluent; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Provides concise presentation-layer Fluent formatting from Telegram handler contexts without performing I/O. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class TelegramUpdateContextI18nExtensions |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Formats a plain-text Fluent message for the current update locale. |
| | | 13 | | /// </summary> |
| | | 14 | | public static string I18n( |
| | | 15 | | this TelegramUpdateContext context, |
| | | 16 | | string messageId, |
| | | 17 | | params ReadOnlySpan<I18nArgument> arguments) |
| | | 18 | | { |
| | 2 | 19 | | ArgumentNullException.ThrowIfNull(context); |
| | 2 | 20 | | return context.Services.GetRequiredService<IFluentLocalizer>().Format(messageId, arguments); |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Formats a Telegram HTML Fluent message for the current update locale. |
| | | 25 | | /// </summary> |
| | | 26 | | public static TelegramFormattedText I18nHtml( |
| | | 27 | | this TelegramUpdateContext context, |
| | | 28 | | string messageId, |
| | | 29 | | params ReadOnlySpan<I18nArgument> arguments) |
| | | 30 | | { |
| | 1 | 31 | | ArgumentNullException.ThrowIfNull(context); |
| | 1 | 32 | | return context.Services.GetRequiredService<IFluentLocalizer>().FormatHtml(messageId, arguments); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Formats a Telegram MarkdownV2 Fluent message for the current update locale. |
| | | 37 | | /// </summary> |
| | | 38 | | public static TelegramFormattedText I18nMarkdownV2( |
| | | 39 | | this TelegramUpdateContext context, |
| | | 40 | | string messageId, |
| | | 41 | | params ReadOnlySpan<I18nArgument> arguments) |
| | | 42 | | { |
| | 1 | 43 | | ArgumentNullException.ThrowIfNull(context); |
| | 1 | 44 | | return context.Services.GetRequiredService<IFluentLocalizer>().FormatMarkdownV2(messageId, arguments); |
| | | 45 | | } |
| | | 46 | | } |