This document provides context and guidelines for AI agents working on the BlazorLocalizer project.
BlazorLocalizer is a library that provides asynchronous localization in Blazor WebAssembly applications. It caches localized values in memory and in localStorage for a configurable amount of time.
Repository: https://github.com/JonTvermose/BlazorLocalizer Package: Tvermose.BlazorLocalizer on NuGet Current Version: 10.2.0 Target Framework: .NET 10
/home/runner/work/BlazorLocalizer/BlazorLocalizer/
├── src/
│ └── BlazorLocalizer/ # Main library project
│ ├── BlazorLocalizer.cs # Core implementation
│ ├── IBlazorLocalizer.cs # Public interface
│ ├── IResourceProvider.cs # Resource provider interface
│ ├── Extensions.cs # DI extension methods
│ ├── ResourceCache.cs # Caching logic
│ ├── Components/
│ │ └── Localized.razor # Razor component
│ ├── Models/
│ │ └── CultureCategoryResources.cs
│ └── Options/
│ └── BlazorLocalizerOptions.cs # Configuration options
├── samples/
│ └── BlazorLocalizerSample/
│ ├── Client/ # Blazor WebAssembly client
│ ├── Server/ # ASP.NET Core server host
│ └── Shared/ # Shared models
├── README.md # Main documentation
└── README-nuget.md # NuGet package documentation
- BlazorLocalizer.cs: Main implementation of the IBlazorLocalizer interface
- IBlazorLocalizer.cs: Public interface for localization functionality
- IResourceProvider.cs: Interface that consumers must implement to provide localized resources
- Extensions.cs: Contains
AddBlazorLocalization()extension method for service registration - ResourceCache.cs: Handles caching of localized strings in memory and localStorage
- Components/Localized.razor: Razor component for declarative localization in markup
- Options/BlazorLocalizerOptions.cs: Configuration options including LocalStorageOptions
- Blazored.LocalStorage (v4.4.0): For localStorage functionality
- Microsoft.AspNetCore.Components (.NET 10): Core Blazor components
- Microsoft.AspNetCore.Components.Web (.NET 10): Web-specific Blazor components
- SDK: Microsoft.NET.Sdk.Razor for the main library
- Package Generation: Enabled on build (
GeneratePackageOnBuild=true) - Package README: README.md is included in the NuGet package
- No Test Projects: This project does not have automated tests
- Maintain Simplicity: This is a focused library with ~500 lines of code. Keep it simple.
- No Breaking Changes: The public API (IBlazorLocalizer, IResourceProvider) should remain stable
- Update Documentation: Update both README.md and README-nuget.md when making feature changes
- Version Numbering: Follow the existing versioning scheme (currently 10.2.0)
- Follow standard C# conventions
- Use async/await for asynchronous operations
- Minimal comments (code should be self-explanatory)
- Keep dependencies minimal
Since there are no automated tests:
- Build the library to ensure compilation
- Test with the sample application in
samples/BlazorLocalizerSample/ - Verify NuGet package generation completes successfully
# Build the library
dotnet build src/BlazorLocalizer/BlazorLocalizer.csproj
# Build the sample application
dotnet build samples/BlazorLocalizerSample/Server/BlazorLocalizerSample.Server.csproj
# Build everything
dotnet build- Consumer implements
IResourceProviderto fetch localized strings from their backend/API - Consumer registers their provider and calls
AddBlazorLocalization()in Program.cs - In components, inject
IBlazorLocalizerand use:- Synchronous:
loc["Key"](returns last cached value immediately) - Asynchronous:
await loc.L("Key", "Category")(fetches fresh value)
- Synchronous:
- Localized strings are cached in memory and localStorage
- Memory Cache: Always used for immediate access
- localStorage Cache: Optional, configurable via
LocalStorageOptions- Default: 3 days expiration
- Can be disabled with
CacheDisabled = true - Configurable expiration with
CacheInvalidationTimeSpan
Not Currently Supported - The library is designed specifically for Blazor WebAssembly. The localStorage dependency and async patterns are optimized for WebAssembly scenarios.
When updating .NET versions or package versions:
- Update all .csproj files (main library and all sample projects)
- Update package references to match the .NET version
- Build and verify everything compiles
- Test with the sample application
- Consider if the feature is in scope (localization-focused)
- Implement in the appropriate location (core vs. options vs. components)
- Update both README files with usage examples
- Ensure backward compatibility or increment major version
- README.md: Main documentation for GitHub
- README-nuget.md: Shorter version for NuGet package page
- Keep both files synchronized in terms of core features and examples
- Blazor Server: Not supported (localStorage dependency, async patterns)
- No Tests: Manual testing required
- No CI/CD: No automated build/test pipeline configured
- Author: Jon Tvermose Nielsen
- License: MIT
- Repository: https://github.com/JonTvermose/BlazorLocalizer
- NuGet: https://www.nuget.org/packages/Tvermose.BlazorLocalizer/