Skip to content

Commit de649a6

Browse files
feat(CherryMarkdown): add Language parameter (#486)
* feat(CherryMarkdown): add locale parameter * refactor: 增加语言自适应功能 --------- Co-authored-by: Argo Zhang <argo@live.ca>
1 parent ebc9206 commit de649a6

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 21 additions & 1 deletion
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

@@ -66,6 +67,25 @@ public partial class CherryMarkdown
6667
[Parameter]
6768
public bool IsViewer { get; set; }
6869

70+
/// <summary>
71+
/// 获取/设置 组件语言
72+
/// </summary>
73+
[Parameter]
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+
}
88+
6989
/// <summary>
7090
/// <inheritdoc/>
7191
/// </summary>
@@ -93,7 +113,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
93113
/// </summary>
94114
/// <returns></returns>
95115
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop,
96-
new { Value, IsSupportMath, IsViewer, Editor = EditorSettings ?? new(), Toolbars = ToolbarSettings ?? new() },
116+
new { Value, IsSupportMath, IsViewer, Locale = Language, Editor = EditorSettings ?? new(), Toolbars = ToolbarSettings ?? new() },
97117
nameof(Upload));
98118

99119
/// <summary>

0 commit comments

Comments
 (0)