### Defining Localized Text Source - CSV Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md This example demonstrates the expected format for localized text source files when using the CSV format. It specifies a two-column structure without a header row, where the first column represents the text key and the second column contains the localized text. ```text Key1,Localized text 1 Key2,Localized text 2 ``` -------------------------------- ### Getting Current Language (I18nText Service) - C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This method retrieves the language code currently selected in the `I18nText` service instance. The language code is determined either from web browser settings or a previous call to `SetCurrentLanguageAsync()`. It is used by `GetTextTableAsync(...)` to load appropriate language resource files. ```C# public Task GetCurrentLanguageAsync(); ``` -------------------------------- ### Registering I18nText Service (Dependency Injection) - C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This extension method facilitates the registration of the `I18nText` service into the .NET Core Dependency Injection system. An optional `configure` callback function allows for customization of the `I18nText` service's behavior during registration. ```C# public static IServiceCollection AddI18nText( this IServiceCollection services, Action configure = null); ``` -------------------------------- ### Configuring Initial Language Retrieval (I18nTextOptions) - C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This field defines the custom behavior for obtaining the initial language code when the Blazor application first loads. Its type is a delegate, `GetInitialLanguage`, which specifies the signature for the custom logic. By default, it points to a static method that retrieves the language from web browser storage (local/session) or browser language settings if storage is empty. ```C# public GetInitialLanguage GetInitialLanguageAsync; ``` -------------------------------- ### Linking Open Iconic Standalone Stylesheet in HTML Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/Tests/Components/wwwroot/css/open-iconic/README.md This HTML snippet shows how to include the default Open Iconic stylesheet for standalone usage, without Bootstrap or Foundation. This link should be placed in the `` section of your HTML document. ```HTML ``` -------------------------------- ### Adding Blazor I18nText NuGet Package - Shell Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md This command demonstrates how to add the `Toolbelt.Blazor.I18nText` NuGet package to your Blazor application project using the .NET Command Line Interface (CLI). This is the initial step required to integrate the internationalization library into your project. ```shell dotnet add package Toolbelt.Blazor.I18nText ``` -------------------------------- ### Linking Open Iconic Foundation Stylesheet in HTML Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/Tests/Components/wwwroot/css/open-iconic/README.md This HTML snippet shows how to include the Open Iconic stylesheet specifically designed for Foundation integration. This link should be placed in the `` section of your HTML document to enable Foundation-compatible icon styling. ```HTML ``` -------------------------------- ### GetInitialLanguage Delegate Signature (I18nTextOptions) - C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This delegate type defines the signature for custom functions that determine the initial language code for the `I18nText` service. It is used by the `GetInitialLanguageAsync` field within `I18nTextOptions`. ```C# public delegate Task GetInitialLanguage(I18nTextOptions options); ``` -------------------------------- ### Defining ConfigureHttpClient Delegate for I18nText in Blazor WebAssembly (C#) Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This delegate field, applicable only to Blazor WebAssembly apps, allows custom configuration of the named HttpClient used by the I18nText service. The delegate, public delegate void ConfigureHttpClient(IServiceProvider serviceProvider, HttpClient client);, is invoked after the HttpClient is created by IHttpClientFactory, enabling users to set properties like BaseAddress or add handlers. Setting it to null prevents the HttpClient from being registered in DI. ```csharp public ConfigureHttpClient ConfigureHttpClient; ``` ```csharp public delegate void ConfigureHttpClient( IServiceProvider serviceProvider, HttpClient client); ``` -------------------------------- ### Using Open Iconic SVG Sprite in HTML Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/Tests/Components/wwwroot/css/open-iconic/README.md This HTML snippet shows how to display an icon from the Open Iconic SVG sprite. It uses the `` and `` tags, linking to the sprite file and specifying the icon by its ID. A general class for styling and a unique class for the specific icon are suggested. ```HTML ``` -------------------------------- ### Linking Open Iconic Bootstrap Stylesheet in HTML Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/Tests/Components/wwwroot/css/open-iconic/README.md This HTML snippet shows how to include the Open Iconic stylesheet specifically designed for Bootstrap integration. This link should be placed in the `` section of your HTML document to enable Bootstrap-compatible icon styling. ```HTML ``` -------------------------------- ### Configuring Language Persistence (I18nTextOptions) - C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This field allows defining custom behavior for persisting the current language selected in the `I18nText` service instance, specifically when the `SetCurrentLanguageAsync(...)` method is invoked. Its type is a delegate, `PersistCurrentLanguageAsync`, which dictates the signature for the custom persistence logic. The default implementation's behavior depends on the value set in the `PersistenceLevel` field of the `options` argument. ```C# public PersistCurrentLanguageAsync PersistCurrentLanguageAsync; ``` -------------------------------- ### Subscribing to Language Change Event (I18nText Service) - C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This event is triggered after the language has been successfully changed within the `I18nText` service. It fires before the component state has been updated, allowing for custom logic to execute in response to a language switch. ```C# public event EventHandler ChangeLanguage; ``` -------------------------------- ### Configuring Language Persistence Level (I18nTextOptions) - C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This property controls the default persistence behavior for the current language. It specifies where the language code should be stored (e.g., session storage) when `SetCurrentLanguageAsync(...)` is called and the default `PersistCurrentLanguageAsync` implementation is used. The default value is `PersistanceLevel.Session`. ```C# public PersistanceLevel PersistenceLevel { get; set; } ``` -------------------------------- ### Registering I18nText Service in Blazor Program.cs (C#) Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md Registers the Toolbelt.Blazor.I18nText service in the Blazor application's `Program.cs` file. It configures the persistence level for language settings, with `PersistanceLevel.Cookie` recommended for SSR areas to maintain language settings across server-side rendered pages. ```C# // in your Program.cs using Toolbelt.Blazor.Extensions.DependencyInjection; // 👈 Add this, and... ... var builder = WebApplication.CreateDefault(args); ... // 👇 Add the following code to register the I18nText service. builder.Services.AddI18nText( options => options.PersistenceLevel = PersistanceLevel.Cookie); ... ``` -------------------------------- ### Displaying Open Iconic with Standalone Classes in HTML Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/Tests/Components/wwwroot/css/open-iconic/README.md This HTML snippet demonstrates how to display an Open Iconic icon using its default standalone stylesheet. The `oi` class and `data-glyph` attribute are applied to a `` tag, along with `title` and `aria-hidden` attributes for accessibility. ```HTML ``` -------------------------------- ### Specifying HttpClient Name for I18nText in Blazor WebAssembly (C#) Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This string field, effective only in Blazor WebAssembly apps, specifies the name of the HttpClient used by the I18nText service to fetch localized resource JSON files. The HttpClient is created from IHttpClientFactory using this specified name, which defaults to "Toolbelt.Blazor.I18nText.HttpClient". ```csharp public string HttpClientName; ``` -------------------------------- ### Watching for Localized Text File Changes - Shell Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md This command shows how to use `dotnet watch` for .NET CLI users to automatically recompile localized text source files when changes are detected. This ensures that the 'Typed Text Table class' and 'Localized Text Resource JSON' files are always up-to-date during development without manual intervention. ```shell $ dotnet watch ``` -------------------------------- ### PersistCurrentLanguageAsync Delegate Signature (I18nTextOptions) - C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This delegate type defines the signature for custom functions that handle the persistence of the current language code. It is used by the `PersistCurrentLanguageAsync` field within `I18nTextOptions` to store the language when it changes. ```C# public delegate Task PersistCurrentLanguageAsync( string langCode, I18nTextOptions options); ``` -------------------------------- ### Defining Localized Text Source - JSON Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md This snippet illustrates the required structure for localized text source files when using the JSON format. It shows a simple key-value pair mapping, where each 'Key' is a unique identifier for a piece of text, and its corresponding 'Value' is the localized string for a specific language. ```json { "Key1": "Localized text 1", "Key2": "Localized text 2", ... } ``` -------------------------------- ### Initializing Text Table in Blazor Component OnInitializedAsync (C#) Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md Overrides the `OnInitializedAsync` method in a Blazor component to asynchronously retrieve and assign the appropriate Text Table object. It uses the `GetTextTableAsync()` method of the injected `I18nText` service to load localized text based on the current culture. ```C# ... protected override async Task OnInitializedAsync() { MyText = await I18nText.GetTextTableAsync(this); ... ``` -------------------------------- ### Setting Current Language (I18nText Service) - C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This method changes the current language code within the `I18nText` service instance. By default, the specified language code is stored in the web browser's session storage, which is then read upon Blazor app launch to initialize the service. Custom storage behavior can be configured via the `AddI18nText(...)` extension method. ```C# public Task SetCurrentLanguageAsync(string langCode); ``` -------------------------------- ### Displaying Open Iconic with Foundation Classes in HTML Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/Tests/Components/wwwroot/css/open-iconic/README.md This HTML snippet demonstrates how to display an Open Iconic icon when using the Foundation-specific stylesheet. The `fi-icon-name` class is applied to a `` tag, along with `title` and `aria-hidden` attributes for accessibility. ```HTML ``` -------------------------------- ### Embedding Open Iconic SVGs in HTML Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/Tests/Components/wwwroot/css/open-iconic/README.md This snippet demonstrates how to directly embed an Open Iconic SVG file into an HTML document using the `` tag. It's recommended to include the `alt` attribute for accessibility. ```HTML icon name ``` -------------------------------- ### Retrieving Localized Text Table (I18nText Service) - C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md This method returns a 'Text Table' object of the specified type `T`, which is typically an auto-generated class from localized text source files. Its fields are initialized with localized resource text from a JSON file matching the language code returned by `GetCurrentLanguageAsync()`. When the language changes via `SetCurrentLanguageAsync(...)`, this method automatically invokes `StateHasChanged()` on the provided component to refresh its rendering with the new localized text. ```C# public Task GetTextTableAsync(ComponentBase component); ``` -------------------------------- ### Injecting I18nText Service into Blazor Component (C#) Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md Injects the `Toolbelt.Blazor.I18nText.I18nText` service into a Blazor component (`.razor` file). This makes the internationalization service available for use within the component to retrieve localized text. ```C# @inject Toolbelt.Blazor.I18nText.I18nText I18nText ``` -------------------------------- ### Accessing Localized Text with Indexer Syntax in Blazor (HTML) Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md Demonstrates how to access localized text dynamically using the indexer syntax on the `MyText` Text Table object within a Blazor component's HTML. If a key string typo occurs, it returns the key string itself without runtime exceptions. ```HTML

@MyText["HelloWorld"]

``` -------------------------------- ### Configuring RequestLocalization Middleware in Blazor Program.cs (C#) Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md Configures and uses the `RequestLocalization` middleware in `Program.cs` for Blazor applications with SSR areas, server-side pre-rendering, or cookie-based language persistence. It sets up supported cultures and the default request culture, ensuring language settings are applied correctly. ```C# // in your Program.cs ... // 👇 Add the following code to configure // the RequestLocalization middleware, and... builder.Services.Configure(options => { // This is an example. // You should configure the supported cultures as you like. var supportedCultures = new[] { "en", "ja" }; options.DefaultRequestCulture = new("en"); options.AddSupportedCultures(supportedCultures); options.AddSupportedUICultures(supportedCultures); }); ... var app = builder.Build(); ... // 👇 Add the following code to use the RequestLocalization middleware. app.UseRequestLocalization(); ... ``` -------------------------------- ### Localized Text File Naming Convention - Text Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md This snippet outlines the mandatory naming convention for localized text source files. The format `..{json|csv}` is crucial for the C# source generator to correctly identify, process, and generate the corresponding typed text table classes and localized resource files. ```text ..{json|csv} ``` -------------------------------- ### Displaying Open Iconic with Bootstrap Classes in HTML Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/Tests/Components/wwwroot/css/open-iconic/README.md This HTML snippet demonstrates how to display an Open Iconic icon when using the Bootstrap-specific stylesheet. The `oi` and `oi-icon-name` classes are applied to a `` tag, along with `title` and `aria-hidden` attributes for accessibility. ```HTML ``` -------------------------------- ### Defining Language Persistence Level Enum in C# Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/API-REFERENCE.md Defines the PersistanceLevel enum, which controls where the current language selection is stored when SetCurrentLanguageAsync is called. It offers options like None, Session, SessionAndLocal, Cookie, and PersistentCookie. For Blazor apps with SSR areas, PersistanceLevel.Cookie is recommended to maintain language settings. ```csharp public enum PersistanceLevel { None, Session, SessionAndLocal, Cookie, PersistentCookie } ``` -------------------------------- ### Sizing Open Iconic SVG Sprite Icons with CSS Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/Tests/Components/wwwroot/css/open-iconic/README.md This CSS rule demonstrates how to set the dimensions for icons displayed using the Open Iconic SVG sprite. Since all icons are square, setting equal `width` and `height` on the `` tag ensures proper scaling. ```CSS .icon { width: 16px; height: 16px; } ``` -------------------------------- ### Coloring Open Iconic SVG Sprite Icons with CSS Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/Tests/Components/wwwroot/css/open-iconic/README.md This CSS rule illustrates how to change the color of a specific icon from the Open Iconic SVG sprite. By applying the `fill` property to the `` tag, the icon's color can be easily customized. ```CSS .icon-account-login { fill: #f00; } ``` -------------------------------- ### Declaring Text Table Field in Blazor Component (C#) Source: https://github.com/jsakamoto/toolbelt.blazor.i18ntext/blob/master/README.md Declares a private field for the generated Text Table class (`I18nText.MyText`) within the `@code` block of a Blazor component. This field will hold the localized text data retrieved by the `I18nText` service. ```C# @code { private I18nText.MyText MyText = new(); ... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.