Skip to content

Commit

Permalink
Added support for IStringLocalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
dyatlov-a committed Oct 18, 2024
1 parent fd20ae8 commit 8dad95b
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/Inc.TeamAssistant.Gateway/Apps/MainApp.razor
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
Blazor.start({
webAssembly: {
environment: "@HostEnvironment.EnvironmentName"
environment: "@HostEnvironment.EnvironmentName",
applicationCulture: "@_lang"
}
});
</script>
Expand All @@ -86,7 +87,10 @@
protected override void OnInitialized()
{
var languageContext = RenderContext.GetLanguageContext();
var culture = new CultureInfo(languageContext.CurrentLanguage.Value);

_lang = languageContext.CurrentLanguage.Value;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
_lang = culture.Name;
}
}
1 change: 1 addition & 0 deletions src/Inc.TeamAssistant.Gateway/Apps/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
@using Inc.TeamAssistant.Primitives.Languages
@using Inc.TeamAssistant.WebUI.Contracts
@using Microsoft.AspNetCore.Components.Web
@using System.Globalization
@using Inc.TeamAssistant.WebUI.Features
1 change: 0 additions & 1 deletion src/Inc.TeamAssistant.Gateway/wwwroot/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
"GUI_VideoNotSupported": "Your browser does not support HTML5 video.",
"GUI_DataRefreshed": "Successfully updated",

"Navigation_Login": "Login",
"Navigation_Logout": "Logout",

"CheckIn_GetStarted": "To get started, please add the bot to your chat room",
Expand Down
3 changes: 1 addition & 2 deletions src/Inc.TeamAssistant.Gateway/wwwroot/langs/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@
"GUI_CreateBotLink": "Создать бота",
"GUI_VideoNotSupported": "Ваш браузер не поддерживает видео в формате HTML5.",
"GUI_DataRefreshed": "Успешно обновлено",

"Navigation_Login": "Войти",

"Navigation_Logout": "Выйти",

"CheckIn_GetStarted": "Добавьте бота в чат для начала работы",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/Inc.TeamAssistant.WebUI/Features/Layouts/LayoutResources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Login" xml:space="preserve">
<value>Login</value>
</data>
</root>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Login" xml:space="preserve">
<value>Войти</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@inject IRenderContext RenderContext
@inject ResourcesManager Resources
@inject NavRouter NavRouter
@inject IStringLocalizer<LayoutResources> Localizer

<div class="navbar">
<div class="navbar-container">
Expand Down Expand Up @@ -59,7 +60,7 @@
<div class="navbar__item">
<RouterLink Href="@NavRouter.CreateRoute($"login?returnUrl={NavRouter.CurrentUrl}")">
<Content>
@Resources[Messages.Navigation_Login]
@Localizer["Login"].Value
</Content>
</RouterLink>
</div>
Expand Down
23 changes: 23 additions & 0 deletions src/Inc.TeamAssistant.WebUI/Inc.TeamAssistant.WebUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Inc.TeamAssistant.Appraiser.Model\Inc.TeamAssistant.Appraiser.Model.csproj" />
Expand Down Expand Up @@ -39,4 +40,26 @@
<AdditionalFiles Include="Icons\TrashIcon.razor" />
<AdditionalFiles Include="Icons\UnknownIcon.razor" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Features\Layouts\LayoutResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>LayoutResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Features\Layouts\LayoutResources.ru.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>LayoutResources.ru.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Update="Features\Layouts\LayoutResources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>LayoutResources.resx</DependentUpon>
</Compile>
<Compile Update="Features\Layouts\LayoutResources.ru.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>LayoutResources.ru.resx</DependentUpon>
</Compile>
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions src/Inc.TeamAssistant.WebUI/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ internal static class Messages
public static readonly MessageId GUI_CreateBotLink = new(nameof(GUI_CreateBotLink));
public static readonly MessageId GUI_VideoNotSupported = new(nameof(GUI_VideoNotSupported));
public static readonly MessageId GUI_DataRefreshed = new(nameof(GUI_DataRefreshed));

public static readonly MessageId Navigation_Login = new(nameof(Navigation_Login));

public static readonly MessageId Navigation_Logout = new(nameof(Navigation_Logout));

public static readonly MessageId Constructor_NewBot = new(nameof(Constructor_NewBot));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static IServiceCollection AddIsomorphicServices(this IServiceCollection s
services
.AddOptions()
.AddAuthorizationCore()
.AddLocalization()
.AddScoped<AuthenticationStateProvider, AuthStateProvider>()
.AddScoped<ResourcesManager>()
.AddScoped<FeaturesFactory>()
Expand Down
3 changes: 2 additions & 1 deletion src/Inc.TeamAssistant.WebUI/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
@using Blazored.FluentValidation
@using Microsoft.AspNetCore.Components.QuickGrid
@using ApexCharts
@using System.Text
@using System.Text
@using Microsoft.Extensions.Localization

0 comments on commit 8dad95b

Please sign in to comment.