SoloX.BlazorJsonLocalization
1.0.0-alpha.1
See the version list below for details.
dotnet add package SoloX.BlazorJsonLocalization --version 1.0.0-alpha.1
NuGet\Install-Package SoloX.BlazorJsonLocalization -Version 1.0.0-alpha.1
<PackageReference Include="SoloX.BlazorJsonLocalization" Version="1.0.0-alpha.1" />
paket add SoloX.BlazorJsonLocalization --version 1.0.0-alpha.1
#r "nuget: SoloX.BlazorJsonLocalization, 1.0.0-alpha.1"
// Install SoloX.BlazorJsonLocalization as a Cake Addin #addin nuget:?package=SoloX.BlazorJsonLocalization&version=1.0.0-alpha.1&prerelease // Install SoloX.BlazorJsonLocalization as a Cake Tool #tool nuget:?package=SoloX.BlazorJsonLocalization&version=1.0.0-alpha.1&prerelease
BlazorJsonLocalization
Provides JSON-based Blazor localization support.
Don't hesitate to post issue, pull request on the project or to fork and improve the project.
License and credits
BlazorJsonLocalization project is written by Xavier Solau. It's licensed under the MIT license.
Installation
You can checkout this Github repository or you can use the NuGet package:
Install using the command line from the Package Manager:
Install-Package SoloX.BlazorJsonLocalization -version 1.0.0-alpha.1
Install using the .Net CLI:
dotnet add package SoloX.BlazorJsonLocalization --version 1.0.0-alpha.1
Install editing your project file (csproj):
<PackageReference Include="SoloX.BlazorJsonLocalization" Version="1.0.0-alpha.1" />
How to use it
Note that you can find code examples in this repository in this location: src/examples
.
Setup the localizer using embedded Json resources file
Blazor Wasm Version
A few lines of code are actually needed to setup the BlazorJsonLocalizer.
You just need to use the name space SoloX.BlazorJsonLocalization
to get access to
right extension methods and to setup the services in you Program.cs
file :
// Here we are going to store the Json files in the project 'Resources' folder.
builder.Services.AddJsonLocalization(
builder => builder.UseEmbeddedJson(
options => options.ResourcesPath = "Resources"));
Let's say that we are going to use the localization in the Index
page. The first thing to do
is to create your Json resource files that are actually going to contain the translated text.
You will add the Json files in the project "Resources" folder (since we have defined it in the
options ResourcesPath
property).
The file must be named with the component name (In our case Index
) and suffixed with the
ISO2 language code:
File name | Description |
---|---|
Index-fr.json | French translated text. |
Index-de.json | German translated text. |
Index-en.json | English translated text. |
Index.json | Since there is no language code, this file is going to be used as fallback when the language is unknown. |
For example the English Json file will look like this:
{
"Hello": "Hello world!",
"Welcome": "Welcome to your new app."
}
and the French file:
{
"Hello": "Bonjour tout le monde!",
"Welcome": "Bienvenue dans votre nouvelle application."
}
The Json file need to be declared as Embedded resources in order to be shipped in the Assembly. You can do it this way in your csproj file:
<ItemGroup>
<Content Remove="Resources\Index-fr.json" />
<Content Remove="Resources\Index.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Index-fr.json" />
<EmbeddedResource Include="Resources\Index.json" />
</ItemGroup>
Then you will need to inject the IStringLocalizer<Index>
in the Index class:
[Inject]
private IStringLocalizer<Index> L { get; set; }
or using the razor syntax:
@inject IStringLocalizer<Index> L
with the using declared in your _Imorts.razor
:
@using Microsoft.Extensions.Localization
Once the localizer is available you can just use it like this:
@page "/"
<h1>@L["Hello"]</h1>
@L["Welcome"]
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.AspNetCore.Components (>= 3.1.12)
- Microsoft.Extensions.FileProviders.Embedded (>= 5.0.3)
- Microsoft.Extensions.Localization (>= 5.0.3)
- System.Text.Json (>= 5.0.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on SoloX.BlazorJsonLocalization:
Package | Downloads |
---|---|
SoloX.BlazorJsonLocalization.WebAssembly
Package Description |
|
SoloX.BlazorJsonLocalization.ServerSide
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.9 | 590 | 11/25/2024 |
2.0.8 | 7,609 | 7/18/2024 |
2.0.7 | 331 | 6/28/2024 |
2.0.6 | 4,248 | 4/28/2024 |
2.0.5 | 260 | 4/21/2024 |
2.0.4 | 1,523 | 3/18/2024 |
2.0.3 | 218 | 3/16/2024 |
2.0.2 | 2,415 | 2/6/2024 |
2.0.1 | 162 | 1/31/2024 |
2.0.0 | 5,098 | 10/19/2023 |
2.0.0-alpha.4 | 4,149 | 2/12/2023 |
2.0.0-alpha.3 | 223 | 11/6/2022 |
2.0.0-alpha.2 | 121 | 10/17/2022 |
2.0.0-alpha.1 | 136 | 10/3/2022 |
1.0.4 | 23,173 | 12/6/2022 |
1.0.3 | 1,670 | 9/28/2022 |
1.0.3-alpha.3 | 330 | 5/17/2022 |
1.0.3-alpha.2 | 190 | 4/3/2022 |
1.0.3-alpha.1 | 125 | 4/1/2022 |
1.0.2 | 2,661 | 12/21/2021 |
1.0.2-alpha.5 | 2,146 | 11/25/2021 |
1.0.2-alpha.4 | 145 | 11/16/2021 |
1.0.2-alpha.3 | 160 | 11/16/2021 |
1.0.2-alpha.2 | 159 | 11/11/2021 |
1.0.2-alpha.1 | 183 | 11/2/2021 |
1.0.1 | 580 | 10/19/2021 |
1.0.1-alpha.2 | 165 | 10/18/2021 |
1.0.1-alpha.1 | 225 | 10/1/2021 |
1.0.0 | 646 | 3/27/2021 |
1.0.0-alpha.5 | 196 | 3/27/2021 |
1.0.0-alpha.4 | 190 | 3/25/2021 |
1.0.0-alpha.3 | 175 | 3/21/2021 |
1.0.0-alpha.2 | 155 | 3/17/2021 |
1.0.0-alpha.1 | 232 | 3/12/2021 |