Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/BootstrapBlazor.Server/Components/Samples/Tabs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
op.Binders.Add("/settings/users", new TabItemOptionAttribute() { Text = "Users", Icon = "fas fa-users" });
})</Pre>

<p class="code-label">@((MarkupString)Localizer["TabsOnTabHeaderTextLocalizerTitle"].Value)</p>

<p>@((MarkupString)Localizer["TabsOnTabHeaderTextLocalizerIntro"].Value)</p>

<p class="code-label">@Localizer["TabsQATitle"]</p>

<ul class="ul-demo">
Expand Down
4 changes: 3 additions & 1 deletion src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,9 @@
"AttributeContextMenuCloseAllIcon": "the icon of tab item context menu close all button",
"AttributeContextMenuFullScreenIcon": "the icon of tab item context menu full screen button",
"AttributeOnBeforeShowContextMenu": "before popup context menu callback",
"ShowTabInHeaderDesc": "After enabling the multi-tab function in the <code>Layout</code> component, you can render the <code>Tab</code> tag header into the <code>Layout</code> Header template by setting <code>ShowTabInHeader=\"true\"</code>. The effect can be viewed by creating a new project in the <a href=\"template\" target=\"_blank\">Project Template</a>"
"ShowTabInHeaderDesc": "After enabling the multi-tab function in the <code>Layout</code> component, you can render the <code>Tab</code> tag header into the <code>Layout</code> Header template by setting <code>ShowTabInHeader=\"true\"</code>. The effect can be viewed by creating a new project in the <a href=\"template\" target=\"_blank\">Project Template</a>",
"TabsOnTabHeaderTextLocalizerTitle": "<code>TabItemOption</code> Localizer",
"TabsOnTabHeaderTextLocalizerIntro": "Localization of `TabItemOption` is achieved by setting the `OnTabHeaderTextLocalizer` callback delegate method. The input parameter is the `TabItemOption` parameter `Text`, and the return value is the localized value"
},
"BootstrapBlazor.Server.Components.Components.DemoTabItem": {
"Info": "Reset the title of this <code>TabItem</code> by click the button",
Expand Down
4 changes: 3 additions & 1 deletion src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,9 @@
"AttributeContextMenuCloseAllIcon": "右键菜单关闭全部按钮图标",
"AttributeContextMenuFullScreenIcon": "右键菜单全屏按钮图标",
"AttributeOnBeforeShowContextMenu": "右键菜单弹出前回调方法",
"ShowTabInHeaderDesc": "<code>Layout</code> 组件中开启多标签功能后,可以通过设置 <code>ShowTabInHeader=\"true\"</code> 将 <code>Tab</code> 标签头渲染到 <code>Layout</code> Header 模板中,效果可以通过 <a href=\"template\" target=\"_blank\">项目模板</a> 新建工程查看"
"ShowTabInHeaderDesc": "<code>Layout</code> 组件中开启多标签功能后,可以通过设置 <code>ShowTabInHeader=\"true\"</code> 将 <code>Tab</code> 标签头渲染到 <code>Layout</code> Header 模板中,效果可以通过 <a href=\"template\" target=\"_blank\">项目模板</a> 新建工程查看",
"TabsOnTabHeaderTextLocalizerTitle": "<code>TabItemOption</code> 本地化问题",
"TabsOnTabHeaderTextLocalizerIntro": "通过设置 <code>OnTabHeaderTextLocalizer</code> 回调委托方法实现 <code>TabItemOption</code> 本地化,入参为 <code>TabItemOption</code> 参数 <code>Text</code> 值,返回值为本地化后值"
},
"BootstrapBlazor.Server.Components.Components.DemoTabItem": {
"Info": "点击下方按钮,本 <code>TabItem</code> 标题更改为当前分钟与秒",
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup Condition="'$(VisualStudioVersion)' == '17.0'">
<Version>9.12.1</Version>
<Version>9.12.2-beta01</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(VisualStudioVersion)' == '18.0'">
Expand Down
11 changes: 11 additions & 0 deletions src/BootstrapBlazor/Components/Tab/Tab.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public partial class Tab
[Parameter]
public bool IsLazyLoadTabItem { get; set; }

/// <summary>
/// 获得/设置 Tab 标签头文本本地化回调方法
/// </summary>
[Parameter]
public Func<string?, string?>? OnTabHeaderTextLocalizer { get; set; }

/// <summary>
/// 获得/设置 组件高度 默认值为 0 高度自动
/// </summary>
Expand Down Expand Up @@ -862,6 +868,11 @@ private void AddTabItem(string url)

void SetTabItemParameters(string? text, string? icon, bool closable, bool active)
{
// 增加 TabItemOptionAttribute 多语言支持
if (OnTabHeaderTextLocalizer != null)
{
text = OnTabHeaderTextLocalizer(text);
}
parameters.Add(nameof(TabItem.Text), text);
parameters.Add(nameof(TabItem.Icon), icon);
parameters.Add(nameof(TabItem.Closable), closable);
Expand Down
15 changes: 15 additions & 0 deletions test/UnitTest/Components/TabTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,21 @@ public void TabHeader_Ok()
tab.DoesNotContain("tabs-header");
}

[Fact]
public void OnTabHeaderTextLocalizer_Ok()
{
var cut = Context.RenderComponent<Tab>(pb =>
{
pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly });
pb.Add(a => a.OnTabHeaderTextLocalizer, text =>
{
return $"Localized-{text}";
});
pb.Add(a => a.DefaultUrl, "/Cat");
});
cut.Contains("Localized-Cat");
}

class DisableTabItemButton : ComponentBase
{
[CascadingParameter, NotNull]
Expand Down
Loading