Skip to content

Commit 032d540

Browse files
HandyS11claude
andcommitted
refactor(alarms): extract IAlarmLocalizer + fix stale catalog doc
Fix 1: Update stale XML comment on AlarmLocalizationCatalog.Default to reference the actual per-slice AlarmLocalizer constructor instead of non-existent shared ILocalizer type. Fix 2: Extract IAlarmLocalizer interface (matching ISwitchLocalizer pattern) with Get(key, culture) and Get(key, culture, params args) methods. Make AlarmLocalizer implement it with <inheritdoc /> on public methods. Update AlarmEmbedRenderer ctor to accept IAlarmLocalizer instead of concrete AlarmLocalizer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4891830 commit 032d540

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

src/RustPlusBot.Features.Alarms/Rendering/AlarmEmbedRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace RustPlusBot.Features.Alarms.Rendering;
88
/// <summary>Renders a Smart Alarm as a Discord embed + control row, and the pairing-prompt embed + row. Pure.</summary>
99
/// <param name="localizer">The alarm localizer.</param>
1010
/// <param name="clock">The clock used to compute relative trigger times.</param>
11-
internal sealed class AlarmEmbedRenderer(AlarmLocalizer localizer, IClock clock)
11+
internal sealed class AlarmEmbedRenderer(IAlarmLocalizer localizer, IClock clock)
1212
{
1313
/// <summary>Renders the alarm embed and its control buttons.</summary>
1414
/// <param name="alarm">The alarm to render.</param>

src/RustPlusBot.Features.Alarms/Rendering/AlarmLocalizationCatalog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ namespace RustPlusBot.Features.Alarms.Rendering;
22

33
/// <summary>
44
/// The in-memory string catalog for Smart Alarms: culture → (key → value).
5-
/// English is the fallback. Intended to be passed directly to the shared
6-
/// <c>RustPlusBot.Discord.Localization.ILocalizer</c> constructor.
5+
/// English is the fallback. Intended to be passed to the per-slice
6+
/// <see cref="AlarmLocalizer"/> constructor.
77
/// </summary>
88
internal static class AlarmLocalizationCatalog
99
{

src/RustPlusBot.Features.Alarms/Rendering/AlarmLocalizer.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ namespace RustPlusBot.Features.Alarms.Rendering;
55
/// <summary>Dictionary-backed localizer for Smart Alarms with English fallback and region normalization.</summary>
66
/// <remarks>Mirrors the SwitchLocalizer pattern; a future refactor may hoist a shared implementation.</remarks>
77
/// <param name="catalog">The culture → (key → value) catalog.</param>
8-
internal sealed class AlarmLocalizer(IReadOnlyDictionary<string, IReadOnlyDictionary<string, string>> catalog)
8+
internal sealed class AlarmLocalizer(IReadOnlyDictionary<string, IReadOnlyDictionary<string, string>> catalog) : IAlarmLocalizer
99
{
1010
private const string FallbackCulture = "en";
1111

12-
/// <summary>Gets the localized string for a key, or the key itself if not found.</summary>
13-
/// <param name="key">The string key to resolve.</param>
14-
/// <param name="culture">The BCP-47 culture tag (e.g. "en", "fr").</param>
12+
/// <inheritdoc />
1513
public string Get(string key, string culture)
1614
{
1715
var normalized = Normalize(culture);
@@ -29,10 +27,7 @@ public string Get(string key, string culture)
2927
return key;
3028
}
3129

32-
/// <summary>Gets the localized, <see cref="string.Format(IFormatProvider, string, object?[])"/>-applied string.</summary>
33-
/// <param name="key">The string key to resolve.</param>
34-
/// <param name="culture">The BCP-47 culture tag (e.g. "en", "fr").</param>
35-
/// <param name="args">Format arguments.</param>
30+
/// <inheritdoc />
3631
public string Get(string key, string culture, params object[] args)
3732
{
3833
var format = Get(key, culture);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace RustPlusBot.Features.Alarms.Rendering;
2+
3+
/// <summary>Resolves localized smart-alarm strings by key and culture, falling back to English.</summary>
4+
internal interface IAlarmLocalizer
5+
{
6+
/// <summary>Gets the localized string for a key, or the key itself if not found.</summary>
7+
/// <param name="key">The string key.</param>
8+
/// <param name="culture">The BCP-47 culture tag (e.g. "en", "fr").</param>
9+
string Get(string key, string culture);
10+
11+
/// <summary>Gets the localized, format-applied string.</summary>
12+
/// <param name="key">The string key.</param>
13+
/// <param name="culture">The BCP-47 culture tag.</param>
14+
/// <param name="args">Format arguments.</param>
15+
string Get(string key, string culture, params object[] args);
16+
}

0 commit comments

Comments
 (0)