Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/ConsoleMode.Tests/LocalizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
foreach (var language in LocalizationService.SupportedLanguages.Select(l => l.Code))
{
var keys = LocalizationService.GetKeys(language).ToHashSet();
Assert.Empty(properties.Where(p => !keys.Contains(p)));

Check warning on line 61 in tests/ConsoleMode.Tests/LocalizationTests.cs

View workflow job for this annotation

GitHub Actions / Build and test

Do not use Assert.Empty to check if a value does not exist in a collection. Use Assert.DoesNotContain instead. (https://xunit.net/xunit.analyzers/rules/xUnit2029)
}
}

Expand All @@ -82,6 +82,33 @@
}
}

/// <summary>Names that read the same in every language (products, the desktop shortcut).</summary>
private static readonly HashSet<string> SameInEveryLanguage =
["Brand", "ShortcutName", "LaunchSteam", "FpsOverlayShowApi"];

private static readonly Regex WordPattern = new(@"\p{L}{2,}", RegexOptions.Compiled);

[Fact]
public void Translations_do_not_copy_english_sentences()
{
// Single words ("Volume", "Desktop", "FPS") can legitimately match English; a phrase of
// three or more words that matches is an English text pasted in and never translated.
var english = LoadCatalog(LocalizationService.EnglishUnitedStates);
var copied = new List<string>();
foreach (var language in LocalizationService.SupportedLanguages
.Select(l => l.Code)
.Where(code => code != LocalizationService.EnglishUnitedStates))
{
var localized = LoadCatalog(language);
copied.AddRange(english
.Where(entry => !SameInEveryLanguage.Contains(entry.Key)
&& WordPattern.Matches(entry.Value).Count >= 3
&& localized[entry.Key] == entry.Value)
.Select(entry => $"{language}:{entry.Key}"));
}
Assert.True(copied.Count == 0, $"Untranslated (same as en-US): {string.Join(", ", copied)}");
}

[Fact]
public void Display_mode_labels_follow_the_language_switch()
{
Expand Down
Loading