Toolbelt.Blazor.I18nText 5.0.0.19

This NuGet package allows you to localize texts in your Blazor app.

There is a newer version of this package available.
See the version list below for details.
This package is considered a SemVer 2.0.0 package as it has a package dependency on SemVer 2.0.0 package(s).
This package will only be available to download with SemVer 2.0.0 compatible NuGet clients, such as Visual Studio 2017 (version 15.3) and above or NuGet client 4.3.0 and above. Read more
Install-Package Toolbelt.Blazor.I18nText -Version 5.0.0.19
dotnet add package Toolbelt.Blazor.I18nText --version 5.0.0.19
<PackageReference Include="Toolbelt.Blazor.I18nText" Version="5.0.0.19" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Toolbelt.Blazor.I18nText --version 5.0.0.19
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Blazor Internationalization(I18n) Text NuGet Package

Summary

This is a NuGet package that allows you to localize texts in your Blazor app.

movie.1

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}

fig.1

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 in the output folder, too.

fig.2

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.

fig.2-2

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>();

fig.3

Step.5 - Get the "Text Table" object in your Blazor component

Open your Blazor component file (.razor) in your editor, and do this:

  1. Inject Toolbelt.Blazor.I18nText.I18nText service into the component.
@inject Toolbelt.Blazor.I18nText.I18nText I18nText
  1. Add a filed of the Text Table class generated from localized text source files, and assign the default instance.
@code {

    I18nText.MyText MyText = new I18nText.MyText();

NOTE - The namespace of the Text Table class is &lt;default namespace of your Blazor project&gt; + &quot;I18nText&quot;.

  1. Override OnInitAsync() method of the Blazor component, and assign a Text Table object that's a return value of GetTextTableAsync&lt;T&gt;() method of I18nText service instance to the Text Table field.
protected override async Task OnInitializedAsync()
{
  MyText = await I18nText.GetTextTableAsync<I18nText.MyText>(this);

fig.4

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.

movie.2

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.

fig.5

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.)

Lean more

Check out project site.

Release Note

  • v.5.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 8 (not compatible with v.3.0.0 Preview 7 or before.)
  • v.4.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 7 (not compatible with v.3.0.0 Preview 6 or before.)
  • v.3.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 6 (not compatible with v.3.0.0 Preview 5 or before.)
  • 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

Mozilla Public License Version 2.0

Blazor Internationalization(I18n) Text NuGet Package

Summary

This is a NuGet package that allows you to localize texts in your Blazor app.

movie.1

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}

fig.1

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 in the output folder, too.

fig.2

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.

fig.2-2

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>();

fig.3

Step.5 - Get the "Text Table" object in your Blazor component

Open your Blazor component file (.razor) in your editor, and do this:

  1. Inject Toolbelt.Blazor.I18nText.I18nText service into the component.
@inject Toolbelt.Blazor.I18nText.I18nText I18nText
  1. Add a filed of the Text Table class generated from localized text source files, and assign the default instance.
@code {

    I18nText.MyText MyText = new I18nText.MyText();

NOTE - The namespace of the Text Table class is &lt;default namespace of your Blazor project&gt; + &quot;I18nText&quot;.

  1. Override OnInitAsync() method of the Blazor component, and assign a Text Table object that's a return value of GetTextTableAsync&lt;T&gt;() method of I18nText service instance to the Text Table field.
protected override async Task OnInitializedAsync()
{
  MyText = await I18nText.GetTextTableAsync<I18nText.MyText>(this);

fig.4

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.

movie.2

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.

fig.5

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.)

Lean more

Check out project site.

Release Note

  • v.5.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 8 (not compatible with v.3.0.0 Preview 7 or before.)
  • v.4.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 7 (not compatible with v.3.0.0 Preview 6 or before.)
  • v.3.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 6 (not compatible with v.3.0.0 Preview 5 or before.)
  • 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

Mozilla Public License Version 2.0

Release Notes

v.5.0.0
- BREAKING CHANGE: Support Blazor v.3.0.0 Preview 8 (not compatible with v.3.0.0 Preview 7 or before.)
v.4.0.0
- BREAKING CHANGE: Support Blazor v.3.0.0 Preview 7 (not compatible with v.3.0.0 Preview 6 or before.)
v.3.0.0
- BREAKING CHANGE: Support Blazor v.3.0.0 Preview 6 (not compatible with v.3.0.0 Preview 5 or before.)
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.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
7.0.1.1 1,872 10/9/2019
7.0.0.17 406 10/3/2019
6.0.0 906 9/5/2019
5.0.0.19 355 8/18/2019
4.0.0 758 7/27/2019
3.0.0.7 497 6/17/2019
2.0.0 182 5/1/2019
1.0.0.49 135 3/21/2019