85 lines
2.6 KiB
Plaintext
85 lines
2.6 KiB
Plaintext
@using System.Globalization
|
|
|
|
<div class="space-y-2">
|
|
@if (!HideTabs)
|
|
{
|
|
<div class="flex flex-wrap gap-2 mb-2">
|
|
@foreach (var culture in SupportedCultures)
|
|
{
|
|
<button type="button" @onclick="() => SelectCulture(culture.Key)"
|
|
class="btn btn-sm @(ActiveCulture == culture.Key ? "btn-primary" : "btn-ghost")">
|
|
@culture.Value
|
|
</button>
|
|
}
|
|
</div>
|
|
}
|
|
|
|
<div class="relative">
|
|
@if (IsTextArea)
|
|
{
|
|
<textarea @bind="CurrentValue" @bind:event="oninput" class="textarea textarea-bordered w-full h-24"
|
|
placeholder="@Placeholder"></textarea>
|
|
}
|
|
else
|
|
{
|
|
<input type="text" @bind="CurrentValue" @bind:event="oninput" class="input input-bordered w-full"
|
|
placeholder="@Placeholder" />
|
|
}
|
|
</div>
|
|
|
|
@if (Value != null && Value.ContainsKey(ActiveCulture))
|
|
{
|
|
<div class="text-xs opacity-50 text-right">
|
|
Chars: @Value[ActiveCulture].Length
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter] public Dictionary<string, string> Value { get; set; } = new();
|
|
[Parameter] public EventCallback<Dictionary<string, string>> ValueChanged { get; set; }
|
|
[Parameter] public string Placeholder { get; set; } = "";
|
|
[Parameter] public bool IsTextArea { get; set; } = false;
|
|
|
|
[Parameter] public string ActiveCulture { get; set; } = "en";
|
|
[Parameter] public EventCallback<string> ActiveCultureChanged { get; set; }
|
|
[Parameter] public bool HideTabs { get; set; } = false;
|
|
|
|
private static readonly Dictionary<string, string> SupportedCultures = new()
|
|
{
|
|
{ "en", "English" },
|
|
{ "ar", "العربية" },
|
|
{ "es", "Español" },
|
|
{ "de", "Deutsch" }
|
|
};
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
if (string.IsNullOrEmpty(ActiveCulture))
|
|
{
|
|
// Default to current culture if supported, otherwise en
|
|
var current = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
|
|
if (SupportedCultures.ContainsKey(current))
|
|
{
|
|
ActiveCulture = current;
|
|
}
|
|
}
|
|
}
|
|
|
|
private string CurrentValue
|
|
{
|
|
get => Value != null && Value.TryGetValue(ActiveCulture, out var v) ? v : "";
|
|
set
|
|
{
|
|
if (Value == null) Value = new();
|
|
Value[ActiveCulture] = value;
|
|
ValueChanged.InvokeAsync(Value);
|
|
}
|
|
}
|
|
|
|
private async Task SelectCulture(string culture)
|
|
{
|
|
ActiveCulture = culture;
|
|
await ActiveCultureChanged.InvokeAsync(culture);
|
|
}
|
|
} |