Skip to content

Commit 2d36de4

Browse files
committed
Added some Basic Localization functionality.
Added Language Selector Added Some NavMenu translations Fixed issue on Brands and Producsts where View and Delete option was showing in edit screen duplicated. Added Header conformity to Login,SelfRegister and ForgotPassword
1 parent 8e762f0 commit 2d36de4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4458
-129
lines changed

src/Shared/Constants/LanguageCode.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace FSH.Starter.Shared.Constants;
2+
3+
public class LanguageCode
4+
{
5+
public string DisplayName { get; set; }
6+
public string Code { get; set; }
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace FSH.Starter.Shared.Constants;
2+
3+
public static class LocalizationConstants
4+
{
5+
public static readonly LanguageCode[] SupportedLanguages = {
6+
new LanguageCode
7+
{
8+
Code = "en-US",
9+
DisplayName= "English"
10+
},
11+
new LanguageCode
12+
{
13+
Code = "af-ZA",
14+
DisplayName = "Afrikaans"
15+
}
16+
};
17+
}

src/api/framework/Core/Persistence/DatabaseOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using System.ComponentModel.DataAnnotations;
22

33
namespace FSH.Framework.Core.Persistence;
4+
45
public class DatabaseOptions : IValidatableObject
56
{
6-
public string Provider { get; set; } = "postgresql";
7+
public string Provider { get; set; } = "mssql";
78
public string ConnectionString { get; set; } = string.Empty;
89

910
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)

src/api/framework/Infrastructure/Extensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public static WebApplicationBuilder ConfigureFshFramework(this WebApplicationBui
3737
builder.AddServiceDefaults();
3838
builder.ConfigureSerilog();
3939
builder.ConfigureDatabase();
40+
builder.Services.AddLocalization(options =>
41+
{
42+
options.ResourcesPath = "Resources";
43+
});
4044
builder.Services.ConfigureMultitenancy();
4145
builder.Services.ConfigureIdentity();
4246
builder.Services.AddCorsPolicy(builder.Configuration);

src/api/server/appsettings.Development.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"DatabaseOptions": {
3-
"Provider": "postgresql",
4-
"ConnectionString": "Server=192.168.1.110;Database=fullstackherodb;User Id=postgres;Password=password"
3+
"Provider": "mssql",
4+
"ConnectionString": "Data Source=KALLIE-LT\\SQL2019;Integrated Security=True;User ID=KALLIE-LT\\Kallie;Database=RUMAS_Q;TrustServerCertificate=True;"
55
},
66
"OriginOptions": {
77
"OriginUrl": "https://localhost:7000"

src/apps/blazor/client/Client.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<RootNamespace>FSH.Starter.Blazor.Client</RootNamespace>
88
<AssemblyName>FSH.Starter.Blazor.Client</AssemblyName>
99
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
10+
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

src/apps/blazor/client/Components/Dialogs/DeleteConfirmation.razor

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
<MudDialog>
1+
@inject Microsoft.Extensions.Localization.IStringLocalizer<DeleteConfirmation> _localizer
2+
<MudDialog>
23
<TitleContent>
34
<MudText Typo="Typo.h6">
45
<MudIcon Icon="@Icons.Material.Filled.Delete" Class="mr-3 mb-n1" />
5-
Delete Confirmation
6+
@_localizer["Delete Confirmation"]
67
</MudText>
78
</TitleContent>
89
<DialogContent>
910
<MudText>@ContentText</MudText>
1011
</DialogContent>
1112
<DialogActions>
12-
<MudButton DropShadow=false StartIcon="@Icons.Material.Filled.Cancel" OnClick="Cancel">Cancel</MudButton>
13-
<MudButton DropShadow=false StartIcon="@Icons.Material.Filled.Delete" Color="Color.Error" Variant="Variant.Filled" OnClick="Submit">Confirm</MudButton>
13+
<MudButton DropShadow=false StartIcon="@Icons.Material.Filled.Cancel" OnClick="Cancel">@_localizer["Cancel"]</MudButton>
14+
<MudButton DropShadow=false StartIcon="@Icons.Material.Filled.Delete" Color="Color.Error" Variant="Variant.Filled" OnClick="Submit">@_localizer["Confirm"]</MudButton>
1415
</DialogActions>
1516
</MudDialog>
1617

src/apps/blazor/client/Components/Dialogs/Logout.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
@namespace FSH.Starter.Blazor.Client.Components.Dialogs
2-
2+
@inject Microsoft.Extensions.Localization.IStringLocalizer<Logout> _localizer
33

44
@inject IAuthenticationService AuthService
55

66
<MudDialog Class="py-4 px-4">
77
<TitleContent>
88
<MudText Typo="Typo.h6">
99
<MudIcon Icon="@Icons.Material.Filled.Logout" Class="mr-3 mb-n1" />
10-
Logout Confirmation
10+
@_localizer["Logout Confirmation"]
1111
</MudText>
1212
</TitleContent>
1313
<DialogContent>
1414
<MudText>@ContentText</MudText>
1515
</DialogContent>
1616
<DialogActions>
17-
<MudButton DropShadow=false StartIcon="@Icons.Material.Filled.Cancel" Variant="Variant.Filled" OnClick="Cancel">Cancel</MudButton>
17+
<MudButton DropShadow=false StartIcon="@Icons.Material.Filled.Cancel" Variant="Variant.Filled" OnClick="Cancel">@_localizer["Cancel"]</MudButton>
1818
<MudButton DropShadow=false StartIcon="@Icons.Material.Filled.Logout" Color="@Color" Variant="Variant.Filled" OnClick="Submit">@ButtonText</MudButton>
1919
</DialogActions>
2020
</MudDialog>

src/apps/blazor/client/Components/EntityTable/AddEditModal.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,5 @@
4444
</MudButton>
4545
}
4646
</DialogActions>
47-
4847
</MudDialog>
4948
</EditForm>

src/apps/blazor/client/Components/EntityTable/EntityTable.razor

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@typeparam TEntity
1+
2+
@typeparam TEntity
23
@typeparam TId
34
@typeparam TRequest
45

@@ -12,7 +13,6 @@
1213

1314
<ErrorBoundary>
1415
<ChildContent>
15-
1616
@if (_canSearch && (Context.AdvancedSearchEnabled || AdvancedSearchContent is not null))
1717
{
1818
<MudExpansionPanel @bind-bind-Expanded="_advancedSearchExpanded"
@@ -35,13 +35,11 @@
3535
</div>
3636
} *@
3737
@AdvancedSearchContent
38-
3938
</MudExpansionPanel>
4039
}
4140

4241
<FshTable @ref="_table" Outlined ServerData="@ServerReloadFunc" Items="@_entityList" Filter="LocalSearch"
4342
Loading="@Loading" LoadingProgressColor="@Color.Secondary" ChildRowContent="@ChildRowContent">
44-
4543
<ToolBarContent>
4644
<div class="justify-center mud-text-align-center">
4745
@if (_canCreate)
@@ -136,13 +134,10 @@
136134
}
137135
</MudTd>
138136
</RowTemplate>
139-
140137
<PagerContent>
141138
<TablePager />
142139
</PagerContent>
143-
144140
</FshTable>
145-
146141
</ChildContent>
147142
<ErrorContent>
148143
<FshCustomError />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@using FSH.Starter.Shared.Constants
2+
@using FSH.Starter.Blazor.Infrastructure.Preferences;
3+
@inject Microsoft.Extensions.Localization.IStringLocalizer<LanguageSelector> L
4+
<MudTooltip Text="@CurrentLanguage">
5+
<MudMenu Icon="@Icons.Material.Outlined.Translate" Color="Color.Inherit" Direction="Direction.Bottom" OffsetY="true"
6+
Dense="true">
7+
@foreach (var language in LocalizationConstants.SupportedLanguages)
8+
{
9+
if (language.Code == CurrentLanguage)
10+
{
11+
<MudMenuItem style="background:var(--mud-palette-primary); color:white">@L[language.DisplayName]</MudMenuItem>
12+
}
13+
else
14+
{
15+
<MudMenuItem OnClick="(()=> ChangeLanguageAsync(language.Code))">@L[language.DisplayName]</MudMenuItem>
16+
}
17+
}
18+
</MudMenu>
19+
</MudTooltip>
20+
21+
@code {
22+
public string? CurrentLanguage { get; set; } = "en-US";
23+
24+
protected override async Task OnInitializedAsync()
25+
{
26+
var currentPreference = await ClientPreferences.GetPreference() as ClientPreference;
27+
if (currentPreference != null)
28+
{
29+
CurrentLanguage = currentPreference.LanguageCode;
30+
}
31+
else
32+
{
33+
CurrentLanguage = "en-US";
34+
}
35+
36+
}
37+
private async Task ChangeLanguageAsync(string languageCode)
38+
{
39+
var result = await ClientPreferences.ChangeLanguageAsync(languageCode);
40+
Navigation.NavigateTo(Navigation.Uri, forceLoad: true);
41+
}
42+
}

src/apps/blazor/client/Layout/MainLayout.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</MudButton>
99
<MudSpacer />
1010
<MudHidden Breakpoint="Breakpoint.MdAndUp" Invert="true">
11+
<LanguageSelector />
1112
<MudButton Variant="Variant.Filled" DropShadow="false" Color="Color.Primary"
1213
Href="https://opencollective.com/fullstackhero" Target="_blank" StartIcon="@Icons.Material.Filled.Favorite">
1314
Sponsor</MudButton>
@@ -36,6 +37,7 @@
3637
</MudTooltip>
3738
</MudHidden>
3839
<MudHidden Breakpoint="Breakpoint.SmAndDown" Invert="true">
40+
3941
<MudTooltip Text="Sponsor">
4042
<MudIconButton Icon="@Icons.Material.Filled.Favorite" Color="Color.Inherit"
4143
Href="https://opencollective.com/fullstackhero" Target="_blank" />

src/apps/blazor/client/Layout/NavMenu.razor

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
<PersonCard Style="background-color: var(--mud-palette-drawer-background);color: var(--mud-palette-drawer-text); margin-bottom:0px!important" />
1+
@inject Microsoft.Extensions.Localization.IStringLocalizer<NavMenu> _localizer
2+
<PersonCard Style="background-color: var(--mud-palette-drawer-background);color: var(--mud-palette-drawer-text); margin-bottom:0px!important" />
23
<MudNavMenu>
3-
<MudText Typo="Typo.subtitle2" Color="Color.Surface" Class="ml-4 my-3">Start</MudText>
4-
<MudNavLink Href="" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">Home</MudNavLink>
4+
<MudText Typo="Typo.subtitle2" Color="Color.Surface" Class="ml-4 my-3">@_localizer["Start"]</MudText>
5+
<MudNavLink Href="" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">@_localizer["Home"]</MudNavLink>
56
<MudNavLink Href="counter" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Add">Counter</MudNavLink>
67
@if (_canViewAuditTrails)
78
{
8-
<MudNavLink Match="NavLinkMatch.Prefix" Href="/identity/audit-trail" Icon="@Icons.Material.Filled.WorkHistory">Audit Trail</MudNavLink>
9+
<MudNavLink Match="NavLinkMatch.Prefix" Href="/identity/audit-trail" Icon="@Icons.Material.Filled.WorkHistory">@_localizer["Audit Trail"]</MudNavLink>
910
}
10-
<MudText Typo="Typo.subtitle2" Color="Color.Surface" Class="ml-4 my-3">Modules</MudText>
11-
<MudNavGroup Title="Catalog" Icon="@Icons.Material.Filled.AddBox">
11+
<MudText Typo="Typo.subtitle2" Color="Color.Surface" Class="ml-4 my-3">@_localizer["Modules"]</MudText>
12+
<MudNavGroup Title="@_localizer["Catalog"]" Icon="@Icons.Material.Filled.AddBox">
1213
<MudNavLink Href="/catalog/products" Icon="@Icons.Material.Filled.ShoppingBag" Class="fsh-nav-child">Products</MudNavLink>
1314
<MudNavLink Href="/catalog/brands" Icon="@Icons.Material.Filled.Label" Class="fsh-nav-child">Brands</MudNavLink>
1415
</MudNavGroup>
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
11
@page "/forgot-password"
22
@attribute [AllowAnonymous]
3+
@inject Microsoft.Extensions.Localization.IStringLocalizer<ForgotPassword> _localizer
34

4-
<PageTitle>Forgot Password</PageTitle>
5+
<PageHeader Title="@_localizer["Title"]" Header="@_localizer["Header"]" SubHeader="@_localizer["SubHeader"]" />
56

67
<EditForm Model="@_forgotPasswordRequest" OnValidSubmit="SubmitAsync">
78
<MudCard Elevation="0">
89
<MudCardHeader>
910
<CardHeaderContent>
10-
<MudTooltip Text="Go Back">
11+
<MudTooltip Text="@_localizer["GoBack"]">
1112
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" Color="Color.Inherit" Edge="Edge.Start"
1213
Href="/" />
1314
</MudTooltip>
14-
<div class="fsh-center-text" style="padding-top: 20px;">
15-
<MudText Typo="Typo.h4" GutterBottom="true" style="margin-bottom:5px">Forgot Password?
16-
</MudText>
17-
<MudText>We can help you by resetting your password.</MudText>
18-
</div>
1915
</CardHeaderContent>
2016
</MudCardHeader>
2117
<MudCardContent>
2218
<MudGrid>
2319
<DataAnnotationsValidator />
2420
<FshValidation @ref="_customValidation" />
2521
<MudItem xs="12">
26-
<MudTextField T="string" Label="Tenant" Variant="Variant.Outlined" @bind-Value="Tenant"
22+
<MudTextField T="string" Label="@_localizer["Tenant"]" Variant="Variant.Outlined" @bind-Value="Tenant"
2723
For="@(() => Tenant)" Required />
2824
</MudItem>
2925
<MudItem xs="12">
30-
<MudTextField T="string" Label="E-mail" Variant="Variant.Outlined"
26+
<MudTextField T="string" Label="@_localizer["Email"]" Variant="Variant.Outlined"
3127
@bind-Value="_forgotPasswordRequest.Email" For="@(() => _forgotPasswordRequest.Email)"
3228
InputType="InputType.Email" Adornment="Adornment.End" />
3329
</MudItem>
3430
</MudGrid>
3531
</MudCardContent>
3632
<MudCardActions Class="pb-4 pl-4">
3733
<MudButton DropShadow="false" Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.LockReset" ButtonType="ButtonType.Submit" Disabled="BusySubmitting" Class="ml-auto">
38-
Forgot Password</MudButton>
34+
@_localizer["ForgotPassword"]
35+
</MudButton>
3936
</MudCardActions>
4037
</MudCard>
4138
</EditForm>
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,39 @@
11
@page "/login"
22
@attribute [AllowAnonymous]
33
@inject IAuthenticationService authService
4+
@inject Microsoft.Extensions.Localization.IStringLocalizer<Login> _localizer
45

5-
<PageTitle>Login</PageTitle>
6+
<PageHeader Title="@_localizer["Title"]" Header="@_localizer["Header"]" SubHeader="@_localizer["SubHeader"]" />
67

7-
<div class="fsh-center-text">
8-
<MudText Typo="Typo.h4" GutterBottom="true">Sign In</MudText>
9-
<MudText>
10-
Enter your credentials to get started.
11-
</MudText>
12-
</div>
13-
<br />
148
<EditForm Model="@_tokenRequest" OnValidSubmit="SubmitAsync">
159
<MudGrid>
1610
<DataAnnotationsValidator />
1711
<FshValidation @ref="_customValidation" />
1812
<MudItem xs="12">
19-
<MudTextField T="string" Label="E-mail" Variant="Variant.Outlined" @bind-Value="_tokenRequest.Email"
13+
<MudTextField T="string" Label="@_localizer["Email"]" Variant="Variant.Outlined" @bind-Value="_tokenRequest.Email"
2014
For="@(() => _tokenRequest.Email)" />
2115
</MudItem>
2216
<MudItem xs="12">
23-
<MudTextField Label="Password" Variant="Variant.Outlined" @bind-Value="_tokenRequest.Password"
17+
<MudTextField Label="@_localizer["Password"]" Variant="Variant.Outlined" @bind-Value="_tokenRequest.Password"
2418
For="@(() => _tokenRequest.Password)" InputType="@_passwordInput" Adornment="Adornment.End"
2519
AdornmentIcon="@_passwordInputIcon" OnAdornmentClick="TogglePasswordVisibility" />
2620
</MudItem>
2721
<MudItem xs="12">
28-
<MudTextField T="string" Label="Tenant" Variant="Variant.Outlined" @bind-Value="TenantId"
22+
<MudTextField T="string" Label="@_localizer["Tenant"]" Variant="Variant.Outlined" @bind-Value="TenantId"
2923
For="@(() => TenantId)" Required />
3024
</MudItem>
31-
3225
<MudItem xs="12" md="6">
33-
<MudButton StartIcon="@Icons.Material.Filled.AppRegistration" Href="/register">Register?</MudButton>
26+
<MudButton StartIcon="@Icons.Material.Filled.AppRegistration" Href="/register">@_localizer["Register?"]</MudButton>
3427
</MudItem>
3528
<MudItem xs="12" md="6">
36-
<MudButton StartIcon="@Icons.Material.Filled.LockReset" Href="/forgot-password">Forgot password?</MudButton>
29+
<MudButton StartIcon="@Icons.Material.Filled.LockReset" Href="/forgot-password">@_localizer["Forgot password?"]</MudButton>
3730
</MudItem>
3831
<MudItem xs="12" Class="d-flex justify-center">
3932
<MudButton ButtonType="ButtonType.Submit" Disabled="BusySubmitting" Variant="Variant.Filled"
40-
Color="Color.Primary" DropShadow="false" Size="Size.Large" StartIcon="@Icons.Material.Filled.Login" Style="width: 100%;">Sign In</MudButton>
33+
Color="Color.Primary" DropShadow="false" Size="Size.Large" StartIcon="@Icons.Material.Filled.Login" Style="width: 100%;">@_localizer["Sign In"]</MudButton>
4134
</MudItem>
4235
<MudItem xs="12" Class="d-flex justify-center">
43-
<MudButton DropShadow="false" StartIcon="@Icons.Material.Filled.Password" OnClick="FillAdministratorCredentials">Fill Administrator Credentials</MudButton>
36+
<MudButton DropShadow="false" StartIcon="@Icons.Material.Filled.Password" OnClick="FillAdministratorCredentials">@_localizer["Fill Administrator Credentials"]</MudButton>
4437
</MudItem>
4538
</MudGrid>
4639
</EditForm>

0 commit comments

Comments
 (0)