Skip to content

Commit

Permalink
Infrastructure Preparation 60
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Jan 22, 2024
1 parent c610f2f commit 9d38e3f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Taiizor.Starterkit" Version="1.1.5.7" />
<PackageReference Include="Taiizor.Starterkit" Version="1.1.5.8" />
</ItemGroup>

</Project>
29 changes: 26 additions & 3 deletions src/Taiizor.Starterkit/Extension/JavascriptInterop.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Extensions.Localization;
using Microsoft.JSInterop;
using System.Reflection;
using Taiizor.Starterkit.Interface;

namespace Taiizor.Starterkit.Extension
Expand Down Expand Up @@ -35,13 +35,13 @@ public JavascriptInterop(IJSRuntime js = null, string module = null, params stri
public async ValueTask<T> InvokeAsync<T>(string identifier, params object[] args)
{
IJSObjectReference module = await GetModuleAsync();
return await module.InvokeAsync<T>(identifier, args);
return await module.InvokeAsync<T>(identifier, TransformLocalizationArgs(args));
}

public async ValueTask InvokeVoidAsync(string identifier, params object[] args)
{
IJSObjectReference module = await GetModuleAsync();
await module.InvokeVoidAsync(identifier, args);
await module.InvokeVoidAsync(identifier, TransformLocalizationArgs(args));
}

private async ValueTask InitializeIdentifiersAsync(string[] identifiers)
Expand All @@ -60,6 +60,29 @@ private async ValueTask<IJSObjectReference> GetModuleAsync()
return await moduler.Value;
}

private object[] TransformLocalizationArgs(object[] args)
{
if (args.Any())
{
for (int i = 0; i < args.Length; i++)
{
if (args[i] is LocalizedString localizedString)
{
if (localizedString.ResourceNotFound)
{
args[i] = $"[{localizedString.Name}]";
}
else
{
args[i] = localizedString.Value;
}
}
}
}

return args;
}

public async ValueTask DisposeAsync()
{
try
Expand Down
2 changes: 1 addition & 1 deletion src/Taiizor.Starterkit/Taiizor.Starterkit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<PropertyGroup>
<ApplicationIcon>Resources\Taiizor.Starterkit.ico</ApplicationIcon>
<Version>1.1.5.8</Version>
<Version>1.1.5.9</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>Taiizor.Starterkit</Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Taiizor.Starterkit" Version="1.1.5.7" />
<PackageReference Include="Taiizor.Starterkit" Version="1.1.5.8" />
</ItemGroup>

</Project>

0 comments on commit 9d38e3f

Please sign in to comment.