Skip to content

Commit

Permalink
fix: ignore empty translations
Browse files Browse the repository at this point in the history
  • Loading branch information
meenzen committed Jul 1, 2024
1 parent 294dff0 commit 0ec0d74
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/MudBlazor.Translations/MudTranslationsInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
namespace MudBlazor.Translations;

/// <summary>
/// Provides community translations for the MudBlazor component library.
/// Provides crowdsourced translations for the MudBlazor component library.
/// </summary>
public class MudTranslationsInterceptor : ILocalizationInterceptor
{
public LocalizedString Handle(string key, params object[] arguments)
{
// rewrite upstream key to match overrides
key = key switch
string fixedKey = key switch
{
"MudDataGrid.=" => "MudDataGrid.Equal",
"MudDataGrid.!=" => "MudDataGrid.NotEqual",
Expand All @@ -22,13 +22,28 @@ public LocalizedString Handle(string key, params object[] arguments)
_ => key
};

string? translation = LanguageResource.ResourceManager.GetString(key, CultureInfo.CurrentCulture);
bool notFound = false;
string? translation = LanguageResource.ResourceManager.GetString(fixedKey, CultureInfo.CurrentCulture);

// Weblate likes to create empty stubs for missing translations, so we need to ignore those and
// use english as a fallback.
if (!Equals(CultureInfo.CurrentCulture, CultureInfo.InvariantCulture) && string.IsNullOrWhiteSpace(translation))
{
translation = LanguageResource.ResourceManager.GetString(fixedKey, CultureInfo.InvariantCulture);
notFound = true;
}

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

return new LocalizedString(key, translation ?? key, translation == null);
if (translation is null)
{
translation = key;
notFound = true;
}

return new LocalizedString(key, translation, notFound);
}
}

0 comments on commit 0ec0d74

Please sign in to comment.