Skip to content

Commit

Permalink
Add localization (#181)
Browse files Browse the repository at this point in the history
* add locale

* page resource

* update resx

* update

* refresh language in layout

* update
  • Loading branch information
ElderJames authored Jun 23, 2024
1 parent bb37624 commit ccc5c4a
Show file tree
Hide file tree
Showing 28 changed files with 364 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

<ItemGroup>
<PackageReference Include="AntDesign.Charts" Version="0.4.0" />
<PackageReference Include="AntDesign.ProLayout" Version="0.16.2" />
<PackageReference Include="AntDesign.Extensions.Localization" Version="0.19.0" />
<PackageReference Include="AntDesign.ProLayout" Version="0.19.0" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>

Expand Down
71 changes: 0 additions & 71 deletions .template.config/templates/server/Layouts/BasicLayout.razor

This file was deleted.

2 changes: 2 additions & 0 deletions .template.config/templates/server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
BaseAddress = new Uri(sp.GetService<NavigationManager>()!.BaseUri)
});
builder.Services.Configure<ProSettings>(builder.Configuration.GetSection("ProSettings"));
builder.Services.AddInteractiveStringLocalizer();
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
//#if (full)
builder.Services.AddScoped<IChartService, ChartService>();
builder.Services.AddScoped<IProjectService, ProjectService>();
Expand Down
2 changes: 2 additions & 0 deletions .template.config/templates/server/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using AntDesign.Pro.Template
@using AntDesign.Extensions.Localization
@using System.Globalization
//#if (full)
@using AntDesign.Pro.Template.Models
@using AntDesign.Pro.Template.Services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

<ItemGroup>
<PackageReference Include="AntDesign.Charts" Version="0.4.0" />
<PackageReference Include="AntDesign.ProLayout" Version="0.16.2" />
<PackageReference Include="AntDesign.Extensions.Localization" Version="0.19.0" />
<PackageReference Include="AntDesign.ProLayout" Version="0.19.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
Expand Down
70 changes: 0 additions & 70 deletions .template.config/templates/wasm/Layouts/BasicLayout.razor

This file was deleted.

3 changes: 3 additions & 0 deletions .template.config/templates/wasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public static async Task Main(string[] args)
builder.Services.AddAntDesign();
builder.Services.Configure<ProSettings>(builder.Configuration.GetSection("ProSettings"));
//#if (full)
builder.Services.AddInteractiveStringLocalizer();
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");

builder.Services.AddScoped<IChartService, ChartService>();
builder.Services.AddScoped<IProjectService, ProjectService>();
builder.Services.AddScoped<IUserService, UserService>();
Expand Down
2 changes: 2 additions & 0 deletions .template.config/templates/wasm/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using AntDesign.Pro.Template
@using AntDesign.Extensions.Localization
@using System.Globalization
//#if (full)
@using AntDesign.Pro.Template.Models
@using AntDesign.Pro.Template.Services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

<ItemGroup>
<PackageReference Include="AntDesign.Charts" Version="0.4.0" />
<PackageReference Include="AntDesign.ProLayout" Version="0.16.2" />
<PackageReference Include="AntDesign.Extensions.Localization" Version="0.19.0" />
<PackageReference Include="AntDesign.ProLayout" Version="0.19.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link href="_content/AntDesign/css/ant-design-blazor.css" rel="stylesheet" />
<link href="_content/AntDesign.ProLayout/css/ant-design-pro-layout-blazor.css" rel="stylesheet" />
<link rel="stylesheet" href="AntDesign.Pro.Template.bundle.scp.css" />
<link href="./css/site.css" rel="stylesheet" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="AntDesign.Pro.Template.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet @rendermode="InteractiveAuto" />
</head>
Expand Down

This file was deleted.

This file was deleted.

Binary file not shown.
4 changes: 4 additions & 0 deletions src/AntDesign.Pro.WebApp/AntDesign.Pro.WebApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
<ProjectReference Include="..\AntDesign.Pro\AntDesign.Pro.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions src/AntDesign.Pro.WebApp/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="AntDesign.Pro.Template.bundle.scp.css" />
<link href="./css/site.css" rel="stylesheet" />
<link rel="stylesheet" href="AntDesign.Pro.WebApp.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="icon" type="image/png" href="favicon.ico" />
<HeadOutlet @rendermode="InteractiveAuto" />
</head>

Expand Down
18 changes: 17 additions & 1 deletion src/AntDesign.Pro.WebApp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,21 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ProSettings": {
"NavTheme": "dark",
"Layout": "side",
"ContentWidth": "Fluid",
"FixedHeader": false,
"FixSiderbar": true,
"Title": "Ant Design Pro",
"PrimaryColor": "daybreak",
"ColorWeak": false,
"SplitMenus": false,
"HeaderRender": true,
"FooterRender": true,
"MenuRender": true,
"MenuHeaderRender": true,
"HeaderHeight": 48
}
}
51 changes: 0 additions & 51 deletions src/AntDesign.Pro.WebApp/wwwroot/app.css

This file was deleted.

7 changes: 0 additions & 7 deletions src/AntDesign.Pro.WebApp/wwwroot/bootstrap/bootstrap.min.css

This file was deleted.

This file was deleted.

Binary file removed src/AntDesign.Pro.WebApp/wwwroot/favicon.png
Binary file not shown.
1 change: 1 addition & 0 deletions src/AntDesign.Pro/AntDesign.Pro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="AntDesign.Charts" Version="0.5.1" />
<PackageReference Include="AntDesign.Extensions.Localization" Version="0.19.0" />
<PackageReference Include="AntDesign.ProLayout" Version="0.19.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
Expand Down
2 changes: 2 additions & 0 deletions src/AntDesign.Pro/App.razor
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
@namespace AntDesign.Pro.Template

<Routes />
22 changes: 15 additions & 7 deletions src/AntDesign.Pro/Components/GlobalHeader/RightContent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
using AntDesign.Extensions.Localization;
using System.Globalization;
using System;
using AntDesign;

namespace AntDesign.Pro.Template.Components
Expand Down Expand Up @@ -36,20 +40,23 @@ public partial class RightContent
}
};

public AvatarMenuItem[] AvatarMenuItems { get; set; } = new AvatarMenuItem[]
{
new() { Key = "center", IconType = "user", Option = "个人中心"},
new() { Key = "setting", IconType = "setting", Option = "个人设置"},
new() { IsDivider = true },
new() { Key = "logout", IconType = "logout", Option = "退出登录"}
};
private AvatarMenuItem[] AvatarMenuItems =>
[
new() { Key = "center", IconType = "user", Option = L["menu.account.center"]},
new() { Key = "setting", IconType = "setting", Option = L["menu.account.settings"] },
new() { IsDivider = true },
new() { Key = "logout", IconType = "logout", Option = L["menu.account.logout"]}
];

[Inject] protected NavigationManager NavigationManager { get; set; }

[Inject] protected IUserService UserService { get; set; }
[Inject] protected IProjectService ProjectService { get; set; }
[Inject] protected MessageService MessageService { get; set; }

[Inject] private IStringLocalizer<App> L { get; set; }
[Inject] private ILocalizationService LocalizationService { get; set; }

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
Expand Down Expand Up @@ -87,6 +94,7 @@ public void HandleSelectUser(MenuItem item)

public void HandleSelectLang(MenuItem item)
{
LocalizationService.SetLanguage(CultureInfo.GetCultureInfo(item.Key));
}

public async Task HandleClear(string key)
Expand Down
Loading

0 comments on commit ccc5c4a

Please sign in to comment.