Skip to content

Commit 8208a96

Browse files
committed
refactor: 增加语言自适应功能
1 parent 721f2b9 commit 8208a96

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/components/BootstrapBlazor.CherryMarkdown/Components/CherryMarkdown/CherryMarkdown.razor.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

55
using Microsoft.AspNetCore.Components;
6+
using System.Globalization;
67

78
namespace BootstrapBlazor.Components;
89

@@ -70,7 +71,20 @@ public partial class CherryMarkdown
7071
/// 获取/设置 组件语言
7172
/// </summary>
7273
[Parameter]
73-
public string Locale { get; set; } = "zh-CN";
74+
public string? Language { get; set; }
75+
76+
/// <summary>
77+
/// <inheritdoc/>
78+
/// </summary>
79+
protected override void OnParametersSet()
80+
{
81+
base.OnParametersSet();
82+
83+
if (string.IsNullOrEmpty(Language))
84+
{
85+
Language = CultureInfo.CurrentUICulture.Name;
86+
}
87+
}
7488

7589
/// <summary>
7690
/// <inheritdoc/>
@@ -99,7 +113,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
99113
/// </summary>
100114
/// <returns></returns>
101115
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop,
102-
new { Value, IsSupportMath, IsViewer, Locale, Editor = EditorSettings ?? new(), Toolbars = ToolbarSettings ?? new() },
116+
new { Value, IsSupportMath, IsViewer, Locale = Language, Editor = EditorSettings ?? new(), Toolbars = ToolbarSettings ?? new() },
103117
nameof(Upload));
104118

105119
/// <summary>

0 commit comments

Comments
 (0)