Toolbelt.Blazor.I18nText
2.0.0
See the version list below for details.
dotnet add package Toolbelt.Blazor.I18nText --version 2.0.0
NuGet\Install-Package Toolbelt.Blazor.I18nText -Version 2.0.0
<PackageReference Include="Toolbelt.Blazor.I18nText" Version="2.0.0" />
paket add Toolbelt.Blazor.I18nText --version 2.0.0
#r "nuget: Toolbelt.Blazor.I18nText, 2.0.0"
// Install Toolbelt.Blazor.I18nText as a Cake Addin #addin nuget:?package=Toolbelt.Blazor.I18nText&version=2.0.0 // Install Toolbelt.Blazor.I18nText as a Cake Tool #tool nuget:?package=Toolbelt.Blazor.I18nText&version=2.0.0
Blazor Internationalization(I18n) Text
Summary
This is a NuGet package that allows you to localize texts in your Blazor app.
Feature
- It works without Server-Side.
- You can develop only plain text editor - No require .resx
- Static Typing - IntelliSense, Code Hint...
- It also works well on Blazor components libraries.
Live Demo
Notice
Server-side Blazor is not supported at this time.
Quick Start
Step.1 - Add "Toolbelt.Blazor.I18nText" Package
Add Toolbelt.Blazor.I18nText
NuGet package to your Blazor app project.
If you are using dotnet CLI, you can do it by command line bellow.
$ dotnet add package Toolbelt.Blazor.I18nText
You can also do it in Package Manager Console of Visual Studio, if you are using Visual Studio in Windows OS.
PM> Install-Package Toolbelt.Blazor.I18nText
Step.2 - Create localized text source files as JSON or CSV
Add localized text source files for each language in a i18ntext
folder under your Blazor app project folder.
The localized text source files must be simple key-value only JSON file like a bellow example,
{
"Key1": "Localized text 1",
"Key2": "Localized text 2",
...
}
or, 2 column only CSV file without header row like a bellow example.
Key1,Localized text 1
Key2,Localized text 2
NOTICE - The encoding of CSV file must be UTF-8.
And, the naming rule of localized text source files must be bellow.
<Text Table Name>.<Language Code>.{json|csv}
Step.3 - Build the project always when localized text source files are created or updated.
After creating or updating those localized text source files, you have to build your Blazor app project.
After building the project, "Typed Text Table class" C# files will be generated in the i18ntext/@types
folder, by the building process.
And also, "Localized Text Resource JSON" files will be generated at the wwwroot/content/i18ntext
folder, too.
NOTE - If you want to do this automatically whenever those localized text source files (.json or .csv) are changed, you can use dotnet watch
command with following arguments.
$ dotnet watch msbuild -t:CompileI18nText
After entry this dotnet CLI command, dotnet CLI stay in execution state and watch the changing of localized text source files. If it detect the changing of localized text source files, then the dotnet CLI re-compile localized text source files into "Typed Text Table class" files and "Localized Text Resource JSON" files.
Step.4 - Configure your app to use I18nText service
Open the C# source file of the "Startup" class of your Blazor app in your editor, and add using
clause for opening Toolbelt.Blazor.Extensions.DependencyInjection
namespace, and add following code in ConfigureServices()
method of the startup class.
services.AddI18nText<Startup>();
Step.5 - Get the "Text Table" object in your Blazor component
Open your Blazor component file (.cshtml) in your editor, and do this:
- Inject
Toolbelt.Blazor.I18nText.I18nText
service into the component.
@inject Toolbelt.Blazor.I18nText.I18nText I18nText
- Add a filed of the Text Table class generated from localized text source files, and assign the default instance.
@functions {
I18nText.MyText MyText = new I18nText.MyText();
NOTE - The namespace of the Text Table class is <default namespace of your Blazor project>
+ "I18nText"
.
- Override
OnInitAsync()
method of the Blazor component, and assign a Text Table object that's a return value ofGetTextTableAsync<T>()
method ofI18nText
service instance to the Text Table field.
protected override async Task OnInitAsync()
{
MyText = await I18nText.GetTextTableAsync<I18nText.MyText>(this);
Step.6 - Use the Text Table
After doing the these steps, you can reference a field of the Text Table object to get localized text.
If you are using Visual Studio in Windows OS and Blazor extensions is installed in that Visual Studio, you can get "IntelliSense" and "Document comment" support.
Note: Text Table object allows you to get localized text by key string dynamically, with indexer syntax, like this.
<h1>@MyText["HelloWorld"]</h1>
This way is sometimes called "late binding".
This feature is very useful in some cases.
However, if you make some mistakes that typo of key string, these mistakes will not be found at compile time.
In this case, it will just return the key string as is without any runtime exceptions.
Step.7 - Run it!
Build and run your Blazor app.
The I18nText service detects the language settings of the Web browser, and reads the localized text resource JSON which is most suitable for the language detected.
Limitations
The following features are not supported in this version of I18Text
library.
- Plural form support
- Text formatting by place holder. (You can use
System.String.Format(...)
instead.) - Integration with
System.Globalization.Culture.CurrentUICulture
.
The following features will not be supported forever, because these features are not the scope of this library, I think.
- Formatting of date, time, currency. (These features will be provided by
System.Globalization.Culture
.)
Configuration
Fallback language
Fallback language is determined at compile time.
The default fallback language is en
.
If you want to change the fallback language, edit your project file (.csproj) to add <I18nTextFallBackLanguage>
MSBuild property with the language code what you want.
The namespace of the Text Table class
If you want to change the namespace of the Text Table classes that will be generated by the building process, edit your project file (.csproj) to add <I18nTextNamespace>
MSBuild property with the namespace what you want.
Learn More...
Please visit the project site.
Release Note
- v.2.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 4 (not compatible with v.0.9.0 or before.)
- v.1.0.0 - 1st release.
License
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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- Microsoft.AspNetCore.Components.Browser (>= 3.0.0-preview4-19216-03)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Toolbelt.Blazor.I18nText:
Package | Downloads |
---|---|
Densen.Extensions.BootstrapBlazor
Densen Blazor组件库以及BootstrapBlazor服务扩展包 |
|
Toolbelt.Blazor.I18nText.StringLocalizerSupport
This NuGet package allows you to localize your Blazor app even validation messages based on .NET Core localization infrastructure such as "IStringLocalizer". |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Toolbelt.Blazor.I18nText:
Repository | Stars |
---|---|
csharpfritz/csharp_with_csharpfritz
Show notes, slides, and samples from the CSharp with CSharpFritz show
|
|
jsakamoto/Toolbelt.Blazor.I18nText
The class library that provides the ability to localize texts on your Blazor app!
|
Version | Downloads | Last updated | |
---|---|---|---|
13.0.0 | 1,795 | 8/3/2024 | |
12.0.2 | 51,450 | 1/30/2023 | |
12.0.1 | 647 | 1/27/2023 | |
12.0.0 | 15,477 | 8/28/2022 | |
12.0.0-preview.1.10 | 1,576 | 3/27/2022 | |
11.1.4 | 9,470 | 3/23/2022 | |
11.1.3 | 2,609 | 2/5/2022 | |
11.1.2 | 636 | 1/30/2022 | |
11.1.1 | 479 | 1/27/2022 | |
11.1.0 | 462 | 1/26/2022 | |
11.0.0 | 3,747 | 11/11/2021 | |
11.0.0-preview.2 | 551 | 10/9/2021 | |
11.0.0-preview.1 | 360 | 8/21/2021 | |
10.0.0-preview.1 | 485 | 8/16/2021 | |
9.4.1 | 4,048 | 8/14/2021 | |
9.4.1-preview.1.3 | 394 | 5/16/2021 | |
9.4.0 | 25,085 | 1/15/2021 | |
9.3.1 | 1,493 | 11/29/2020 | |
9.3.0 | 7,149 | 9/14/2020 | |
9.2.0 | 13,981 | 8/5/2020 | |
9.1.1 | 4,049 | 6/18/2020 | |
9.1.0 | 721 | 6/11/2020 | |
9.0.1.1 | 3,641 | 4/26/2020 | |
9.0.1 | 10,393 | 4/6/2020 | |
9.0.0.3 | 2,618 | 3/14/2020 | |
8.0.0.2-beta | 889 | 2/14/2020 | |
7.1.0 | 7,238 | 1/9/2020 | |
7.0.1.1 | 4,276 | 10/9/2019 | |
7.0.0.17 | 944 | 10/3/2019 | |
6.0.0 | 1,404 | 9/5/2019 | |
5.0.0.19 | 656 | 8/18/2019 | |
4.0.0 | 1,056 | 7/27/2019 | |
3.0.0.7 | 794 | 6/17/2019 | |
2.0.0 | 687 | 5/1/2019 | |
1.0.0.49 | 747 | 3/21/2019 |
v.2.0.0
- BREAKING CHANGE: Support Blazor v.3.0.0 Preview 4 (not compatible with v.0.9.0 or before.)
v.1.0.0
- 1st release.