Files
radzen-blazor/Radzen.Blazor/RadzenHtmlEditorButtonBase.cs
Vladimir Enchev e5bd0343fa Add built-in German, French, Spanish, Italian and Japanese translations
Ship satellite resource files (RadzenStrings.{de,fr,es,it,ja}.resx) with all
535 strings translated, so components localize out of the box via the standard
.NET ResourceManager.

Make culture handling reactive everywhere:
- RadzenDatePicker rebuilds its month/year lists when Culture or the
  DefaultCulture cascade changes (previously cached at init).
- Scheduler views, HtmlEditor tools and the spreadsheet ChartOverlay localize
  through their parent component's UICulture instead of CurrentUICulture;
  spreadsheet dialogs honor a DefaultUICulture cascade. UICulture is added to
  IScheduler/ISpreadsheet as default interface members, so this is non-breaking.

Update the Localization demo with an interactive language switcher (cascading
DefaultUICulture + DefaultCulture) backed by an ILocalizer so it works in-place
on Blazor WebAssembly.
2026-06-15 18:45:19 +03:00

81 lines
2.5 KiB
C#

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using System.Globalization;
using Microsoft.Extensions.DependencyInjection;
using Radzen.Blazor;
namespace Radzen.Blazor
{
/// <summary>
/// Base class that RadzenHtmlEditor color picker tools inherit from.
/// </summary>
public abstract class RadzenHtmlEditorButtonBase : ComponentBase, IDisposable
{
[Inject]
private IServiceProvider Services { get; set; } = default!;
private Localizer? localizer;
internal Localizer Localizer => localizer ??=
Services.GetService<Localizer>() ?? Localizer.Default;
/// <summary>
/// Gets a localized string for the specified resource key.
/// </summary>
public string Localize(string key) => Localizer.Get(key, Editor?.UICulture ?? CultureInfo.CurrentUICulture);
/// <summary>
/// The RadzenHtmlEditor component which this tool is part of.
/// </summary>
[CascadingParameter]
public RadzenHtmlEditor? Editor { get; set; }
/// <summary>
/// Specifies the name of the command. It is available as <see cref="HtmlEditorExecuteEventArgs.CommandName" /> when
/// <see cref="RadzenHtmlEditor.Execute" /> is raised.
/// </summary>
protected virtual string? CommandName { get; }
/// <summary>
/// Specifies the shortcut for the command. Can be in the form of <c>"Ctrl+X"</c> or <c>"Alt+Shift+Z"</c>.
/// </summary>
[Parameter]
public virtual string? Shortcut { get; set; }
/// <summary>
/// Handles the click event of the button. Executes the command.
/// </summary>
protected virtual async Task OnClick()
{
if (Editor != null && CommandName != null)
{
await Editor.ExecuteCommandAsync(CommandName);
}
}
/// <inheritdoc />
protected override void OnInitialized()
{
if (!string.IsNullOrEmpty(Shortcut))
{
Editor?.RegisterShortcut(Shortcut, OnClick);
}
}
/// <summary>
/// IDisposable implementation.
/// </summary>
public void Dispose()
{
if (!string.IsNullOrEmpty(Shortcut))
{
Editor?.UnregisterShortcut(Shortcut);
}
GC.SuppressFinalize(this);
}
}
}