i18n: translate waitlist eligibility responses

This commit is contained in:
biss committed 2026-11-07 19:43:26 +08:00
1 parent 2a580de424
commit cc1b60450f
2 files changed
+23 -5

No files matched your search

@@ -1609,7 +1609,7 @@ public sealed class CourseSelectionsController(
offering,
cancellationToken);
if (eligibility.Error is not null)
return ConflictProblem(eligibility.Error);
return ConflictProblem(SelectionMessage(eligibility.Error, eligibility.EnglishError ?? LocalizeSelectionError(eligibility.Error)));
var sameCourseWaitlistExists = await db.CourseEnrollments.AnyAsync(
x =>
@@ -2190,7 +2190,8 @@ public sealed class CourseSelectionsController(
return new(
isRetake,
$"获得名额后将达到 {selectedCredits + task.Course.Credits:0.#} 学分," +
$"超过本轮 {round.MaxCredits:0.#} 学分上限。");
$"超过本轮 {round.MaxCredits:0.#} 学分上限。",
$"Receiving a place would total {selectedCredits + task.Course.Credits:0.#} credits, exceeding the round limit of {round.MaxCredits:0.#}.");
}
var selectedCourseCount = await db.CourseEnrollments.CountAsync(
x =>
@@ -2204,7 +2205,8 @@ public sealed class CourseSelectionsController(
{
return new(
isRetake,
$"你已达到本轮最多 {round.MaxCourseCount} 门课程限制。");
$"你已达到本轮最多 {round.MaxCourseCount} 门课程限制。",
$"You have reached the limit of {round.MaxCourseCount} courses for this round.");
}
var candidateEntries = await PublishedScheduleEntries(
@@ -2239,7 +2241,8 @@ public sealed class CourseSelectionsController(
{
return new(
true,
$"重修课程时间冲突 {overlap:F0}%,超过 50% 上限。");
$"重修课程时间冲突 {overlap:F0}%,超过 50% 上限。",
$"The retake overlaps by {overlap:F0}%, exceeding the 50% limit.");
}
}
@@ -2586,7 +2589,7 @@ public sealed class CourseSelectionsController(
private static int[] NormalizeGrades(IEnumerable<int>? values) =>
values?.Distinct().OrderBy(x => x).ToArray() ?? [];
private sealed record EnrollmentEligibility(bool IsRetake, string? Error);
private sealed record EnrollmentEligibility(bool IsRetake, string? Error, string? EnglishError = null);
private sealed record RetakeGradeAttempt(
Guid CourseId,
@@ -38,4 +38,19 @@ public sealed class CourseSelectionErrorLocalizationTests
}
finally { CultureInfo.CurrentUICulture = original; }
}
[Fact]
public void DynamicEligibilityMessageUsesTheRequestLanguage()
{
var method = typeof(CourseSelectionsController).GetMethod("SelectionMessage", BindingFlags.NonPublic | BindingFlags.Static)!;
var original = CultureInfo.CurrentUICulture;
try
{
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
Assert.Equal("You have reached the limit of 3 courses.", method.Invoke(null, ["你已达到最多 3 门课程限制。", "You have reached the limit of 3 courses."]));
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("zh-CN");
Assert.Equal("你已达到最多 3 门课程限制。", method.Invoke(null, ["你已达到最多 3 门课程限制。", "You have reached the limit of 3 courses."]));
}
finally { CultureInfo.CurrentUICulture = original; }
}
}