mirror of
https://github.com/dotnetcore/BootstrapBlazor.git
synced 2025-12-20 02:16:40 +08:00
!612 feat(#I22IX5): DropdownList 组件增加本地化功能
* feat: DropdownList 组件增加本地化功能 * doc: DropdownList 组件增加本地化资源文件
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
@@ -73,24 +75,9 @@ namespace BootstrapBlazor.Components
|
||||
/// <summary>
|
||||
/// 获得 PlaceHolder 属性
|
||||
/// </summary>
|
||||
protected string? PlaceHolder
|
||||
{
|
||||
get
|
||||
{
|
||||
var placeHolder = "请选择 ...";
|
||||
if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("placeholder", out var ph) && !string.IsNullOrEmpty(Convert.ToString(ph)))
|
||||
{
|
||||
placeHolder = ph.ToString();
|
||||
}
|
||||
return placeHolder;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string DefaultText { get; set; } = "请选择 ...";
|
||||
[NotNull]
|
||||
public string? PlaceHolder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 按钮颜色
|
||||
@@ -122,6 +109,10 @@ namespace BootstrapBlazor.Components
|
||||
[Parameter]
|
||||
public EventCallback<TValue> OnSelectedItemChanged { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IStringLocalizer<DropdownList<TModel, TValue>>? Localizer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SetParametersAsync 方法
|
||||
/// </summary>
|
||||
@@ -146,6 +137,16 @@ namespace BootstrapBlazor.Components
|
||||
await base.SetParametersAsync(ParameterView.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnInitialized 方法
|
||||
/// </summary>
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
PlaceHolder ??= Localizer[nameof(PlaceHolder)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnInitialized 方法
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"PlaceHolder":"Please select ..."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"PlaceHolder":"请选择 ..."
|
||||
}
|
||||
Reference in New Issue
Block a user