Skip to content

Commit 0ec0d74

Browse files
committed
fix: ignore empty translations
1 parent 294dff0 commit 0ec0d74

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/MudBlazor.Translations/MudTranslationsInterceptor.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
namespace MudBlazor.Translations;
55

66
/// <summary>
7-
/// Provides community translations for the MudBlazor component library.
7+
/// Provides crowdsourced translations for the MudBlazor component library.
88
/// </summary>
99
public class MudTranslationsInterceptor : ILocalizationInterceptor
1010
{
1111
public LocalizedString Handle(string key, params object[] arguments)
1212
{
1313
// rewrite upstream key to match overrides
14-
key = key switch
14+
string fixedKey = key switch
1515
{
1616
"MudDataGrid.=" => "MudDataGrid.Equal",
1717
"MudDataGrid.!=" => "MudDataGrid.NotEqual",
@@ -22,13 +22,28 @@ public LocalizedString Handle(string key, params object[] arguments)
2222
_ => key
2323
};
2424

25-
string? translation = LanguageResource.ResourceManager.GetString(key, CultureInfo.CurrentCulture);
25+
bool notFound = false;
26+
string? translation = LanguageResource.ResourceManager.GetString(fixedKey, CultureInfo.CurrentCulture);
27+
28+
// Weblate likes to create empty stubs for missing translations, so we need to ignore those and
29+
// use english as a fallback.
30+
if (!Equals(CultureInfo.CurrentCulture, CultureInfo.InvariantCulture) && string.IsNullOrWhiteSpace(translation))
31+
{
32+
translation = LanguageResource.ResourceManager.GetString(fixedKey, CultureInfo.InvariantCulture);
33+
notFound = true;
34+
}
2635

2736
if (translation is not null && arguments.Length > 0)
2837
{
2938
translation = string.Format(translation, arguments);
3039
}
3140

32-
return new LocalizedString(key, translation ?? key, translation == null);
41+
if (translation is null)
42+
{
43+
translation = key;
44+
notFound = true;
45+
}
46+
47+
return new LocalizedString(key, translation, notFound);
3348
}
3449
}

0 commit comments

Comments
 (0)