Skip to content

Commit

Permalink
Elsa Localization Support (#324)
Browse files Browse the repository at this point in the history
* Localization for elsa studio.

* Latest Changes.

* WIP Localization Module

* cleanup

* BlazorServer implementation

* Elsa studio changes for Localization.

* Update localization options

* refactoring

* Added translation for components.

* Deleted Unused resource files.

* Fix build

* Removed extra localization files and added missing translations.

* add controllers

* Fix Imports

* Reconfigure Localization Service with the ResourceManager

* Add Blazor Wasm Localization

* Refactor LocalizationService

* Rename Localization Service

* Translation added for Agents and Secrets.

* refactoring

* merge from soumya

* Refactor localization

* cleanup resources

* additional cleanup

* Delete Japanese localization

* clean up

* remove specific functions

* Add a README for localization

* Update localization

* Fix merge errors

* fix formatting

* Use Timestamp component

* Implement ILocalizer interface and replace ElsaLocalization

Created a new ILocalizer interface for localization purposes. Replaced ElsaLocalization with ILocalizer throughout the codebase for consistency and better readability. Removed unnecessary using statements and simplified namespaces.

* Remove unused using directives across the project

Cleared redundant using directives from ILocalizationProvider, DefaultLocalizer, and ActivityWrapper components. This cleanup improves code readability and may slightly enhance compilation performance.

* Refactor constructors to use parameterized field assignment

Converted multiple class constructors to use parameterized field assignment directly in the constructor. This change reduces boilerplate code and improves readability. Additionally, some unnecessary using directives were removed.

* Add XML documentation to DashboardMenu class

Added summary XML documentation to the DashboardMenu class and the GetMenuItemsAsync method to enhance code readability and maintainability. This documentation provides a brief description of the class's purpose and the method's functionality.

* Update language picker to use customizable formatter

This change updates the `LanguagePicker` component to utilize a customizable formatter defined in `LocalizationOptions`. It allows for more flexibility in how culture names are displayed in the UI, enhancing localization support. The default formatter is set to use the culture's display name.

* Update culture picker to use culture name

Changed the CulturePickerFormatter to use the culture's Name property instead of DisplayName. This ensures consistency in the format used for culture identifiers.

---------

Co-authored-by: Soumya Mandal <[email protected]>
Co-authored-by: Mohamed Ali <[email protected]>
Co-authored-by: Sipke Schoorstra <[email protected]>
  • Loading branch information
4 people authored Nov 25, 2024
1 parent d72092d commit 5ac5272
Show file tree
Hide file tree
Showing 124 changed files with 2,370 additions and 601 deletions.
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<PackageVersion Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
<PackageVersion Include="Microsoft.AspNetCore.App" Version="2.2.8" />
<PackageVersion Include="Microsoft.CodeAnalysis.ResxSourceGenerator" Version="3.11.0-beta1.24454.1" />
<PackageVersion Include="MudBlazor" Version="7.10.0" />
<PackageVersion Include="MudBlazor.Translations" Version="1.3.0" />
<PackageVersion Include="Radzen.Blazor" Version="5.2.12" />
<PackageVersion Include="ShortGuid" Version="2.0.1" />
<PackageVersion Include="ThrottleDebounce" Version="2.0.0" />
Expand Down
97 changes: 63 additions & 34 deletions Elsa.Studio.sln

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Elsa.Studio.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Blazored/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ffffff/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Heroicons/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=localizer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tabler/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
48 changes: 24 additions & 24 deletions src/framework/Elsa.Studio.Core/Elsa.Studio.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Core Elsa Studio services.</Description>
<PackageTags>elsa studio core</PackageTags>
<RootNamespace>Elsa.Studio</RootNamespace>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization"/>
<PackageReference Include="Microsoft.AspNetCore.Components.CustomElements"/>
<PackageReference Include="Microsoft.AspNetCore.Components.Web"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions"/>
<PackageReference Include="Microsoft.JSInterop"/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization"/>
<PackageReference Include="Microsoft.AspNetCore.Components.CustomElements"/>
<PackageReference Include="Microsoft.AspNetCore.Components.Web"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions"/>
<PackageReference Include="Microsoft.JSInterop"/>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" />
<PackageReference Include="Microsoft.AspNetCore.Components.CustomElements" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" />
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.JSInterop" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Blazored.FluentValidation"/>
<PackageReference Include="Blazored.LocalStorage"/>
<PackageReference Include="CodeBeam.MudBlazor.Extensions"/>
<PackageReference Include="FluentValidation"/>
<PackageReference Include="MudBlazor"/>
<PackageReference Include="Radzen.Blazor"/>
<PackageReference Include="ShortGuid"/>
<PackageReference Include="ThrottleDebounce"/>
<PackageReference Include="Blazored.FluentValidation" />
<PackageReference Include="Blazored.LocalStorage" />
<PackageReference Include="CodeBeam.MudBlazor.Extensions" />
<PackageReference Include="FluentValidation" />
<PackageReference Include="MudBlazor" />
<PackageReference Include="Radzen.Blazor" />
<PackageReference Include="ShortGuid" />
<PackageReference Include="ThrottleDebounce" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="**\*.resx"></EmbeddedResource>
</ItemGroup>

<!-- <ItemGroup Label="Elsa">-->
<!-- <ProjectReference Include="..\..\..\..\..\elsa-core\main\src\clients\Elsa.Api.Client\Elsa.Api.Client.csproj"/>-->
<!-- </ItemGroup>-->

<ItemGroup Label="Elsa">
<PackageReference Include="Elsa.Api.Client"/>
<PackageReference Include="Elsa.Api.Client" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Elsa.Api.Client.Extensions;
using Elsa.Api.Client.Options;
using Elsa.Studio.Contracts;
using Elsa.Studio.Localization;
using Elsa.Studio.Models;
using Elsa.Studio.Options;
using Elsa.Studio.Services;
Expand Down Expand Up @@ -36,7 +37,10 @@ public static IServiceCollection AddCoreInternal(this IServiceCollection service

// Mediator.
services.AddScoped<IMediator, DefaultMediator>();


//Localization
services.AddSingleton<ILocalizationProvider, DefaultLocalizationProvider>();
services.AddSingleton<ILocalizer, DefaultLocalizer>();
return services;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Globalization;
using Elsa.Studio.Resources;

namespace Elsa.Studio.Localization
{
internal class DefaultLocalizationProvider : ILocalizationProvider
{
public string? GetTranslation(string key)
{
return ResourceLocalization.ResourceManager.GetString(key, CultureInfo.CurrentUICulture);
}
}
}
26 changes: 26 additions & 0 deletions src/framework/Elsa.Studio.Core/Localization/DefaultLocalizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.Extensions.Localization;

namespace Elsa.Studio.Localization
{
/// <inheritdoc />
public class DefaultLocalizer(ILocalizationProvider provider) : ILocalizer
{
/// <inheritdoc />
public LocalizedString this[string key]
{
get
{
var notFound = false;
var translation = provider.GetTranslation(key);

if (translation is null)
{
translation = key;
notFound = true;
}

return new LocalizedString(key, translation, notFound);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Elsa.Studio.Localization
{
public interface ILocalizationProvider
{
string? GetTranslation(string key);
}
}
15 changes: 15 additions & 0 deletions src/framework/Elsa.Studio.Core/Localization/ILocalizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Extensions.Localization;

namespace Elsa.Studio.Localization;

/// <summary>
/// Interface for localization.
/// </summary>
public interface ILocalizer
{
/// <summary>
/// Gets the localized string for the given key.
/// </summary>
/// <param name="key"></param>
LocalizedString this[string key] { get; }
}
Loading

0 comments on commit 5ac5272

Please sign in to comment.