-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from SyncfusionExamples/861193-localization
Localization sample updated suitable for Blazor Web App.
- Loading branch information
Showing
69 changed files
with
90,791 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...alization-with-dynamic-culture/LocalizationSample.Client/LocalizationSample.Client.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile> | ||
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" /> | ||
<PackageReference Include="Syncfusion.Blazor.Grid" Version="23.2.4" /> | ||
<PackageReference Include="Syncfusion.Blazor.Themes" Version="23.2.4" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Update="Resources\SfResources.Designer.cs"> | ||
<DesignTime>True</DesignTime> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>SfResources.resx</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Update="Resources\SfResources.resx"> | ||
<Generator>PublicResXFileCodeGenerator</Generator> | ||
<LastGenOutput>SfResources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
</Project> |
38 changes: 38 additions & 0 deletions
38
...r Web App/Localization-with-dynamic-culture/LocalizationSample.Client/Pages/Counter.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@page "/counter" | ||
@rendermode InteractiveAuto | ||
|
||
<h2>Syncfusion Blazor Grid Component</h2> | ||
<br /> | ||
|
||
<SfGrid DataSource="@Orders" AllowFiltering="true" AllowPaging="true" Height="315"> | ||
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Menu"></GridFilterSettings> | ||
<GridColumns> | ||
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn> | ||
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> | ||
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> | ||
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> | ||
</GridColumns> | ||
</SfGrid> | ||
|
||
@code { | ||
public List<Order> Orders { get; set; } | ||
|
||
protected override void OnInitialized () | ||
{ | ||
Orders = Enumerable.Range(1, 75).Select(x => new Order() | ||
{ | ||
OrderID = 1000 + x, | ||
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)], | ||
Freight = 2.1 * x, | ||
OrderDate = (new DateTime[] { new DateTime(2010, 5, 1), new DateTime(2010, 5, 2), new DateTime(2010, 5, 3), })[new Random().Next(3)], | ||
}).ToList(); | ||
} | ||
|
||
public class Order | ||
{ | ||
public int? OrderID { get; set; } | ||
public string CustomerID { get; set; } | ||
public DateTime? OrderDate { get; set; } | ||
public double? Freight { get; set; } | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...p/Localization-with-dynamic-culture/LocalizationSample.Client/Pages/CultureSwitcher.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@using System.Globalization | ||
@inject IJSRuntime JSRuntime | ||
@inject NavigationManager NavigationManager | ||
|
||
<select @bind="Culture"> | ||
@foreach (var culture in supportedCultures) | ||
{ | ||
<option value="@culture">@culture.DisplayName</option> | ||
} | ||
</select> | ||
|
||
@code { | ||
private CultureInfo[] supportedCultures = new[] | ||
{ | ||
new CultureInfo("en-US"), | ||
new CultureInfo("de"), | ||
new CultureInfo("fr"), | ||
new CultureInfo("ar"), | ||
new CultureInfo("zh") | ||
}; | ||
|
||
private CultureInfo Culture | ||
{ | ||
get => CultureInfo.CurrentCulture; | ||
set | ||
{ | ||
if (CultureInfo.CurrentCulture != value) | ||
{ | ||
var js = (IJSInProcessRuntime)JSRuntime; | ||
js.InvokeVoid("cultureInfo.set", value.Name); | ||
|
||
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true); | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
.NET 8 Blazor Web App/Localization-with-dynamic-culture/LocalizationSample.Client/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using LocalizationSample.Client; | ||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
using Microsoft.JSInterop; | ||
using Syncfusion.Blazor; | ||
using System.Globalization; | ||
|
||
var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||
builder.Services.AddSyncfusionBlazor(); | ||
builder.Services.AddSingleton(typeof(ISyncfusionStringLocalizer), typeof(SyncfusionLocalizer)); | ||
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR LICENSE KEY"); | ||
var host = builder.Build(); | ||
//Setting culture of the application | ||
var jsInterop = host.Services.GetRequiredService<IJSRuntime>(); | ||
var result = await jsInterop.InvokeAsync<string>("cultureInfo.get"); | ||
CultureInfo culture; | ||
if (result != null) | ||
{ | ||
culture = new CultureInfo(result); | ||
} | ||
else | ||
{ | ||
culture = new CultureInfo("en-US"); | ||
await jsInterop.InvokeVoidAsync("cultureInfo.set", "en-US"); | ||
} | ||
CultureInfo.DefaultThreadCurrentCulture = culture; | ||
CultureInfo.DefaultThreadCurrentUICulture = culture; | ||
await builder.Build().RunAsync(); |
Oops, something went wrong.