Sparkdo.Localization 1.0.3

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Sparkdo.Localization --version 1.0.3
                    
NuGet\Install-Package Sparkdo.Localization -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sparkdo.Localization" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sparkdo.Localization" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Sparkdo.Localization" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sparkdo.Localization --version 1.0.3
                    
#r "nuget: Sparkdo.Localization, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sparkdo.Localization@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sparkdo.Localization&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Sparkdo.Localization&version=1.0.3
                    
Install as a Cake Tool

Sparkdo.Localization

Sparkdo 本地化模块,提供完整的本地化功能实现。

功能特性

  • 多语言支持
  • 资源文件管理
  • 枚举本地化
  • 动态本地化贡献者
  • 与 Sparkdo 框架无缝集成

安装

<PackageReference Include="Sparkdo.Localization" Version="x.x.x" />

核心组件

本地化资源

  • LocalizationResource: 基于类型的本地化资源
  • NonTypedLocalizationResource: 非类型化本地化资源
  • LocalizationResourceBase: 本地化资源基类

本地化器

  • ISparkdoStringLocalizer: Sparkdo字符串本地化器接口
  • SparkdoDictionaryBasedStringLocalizer: 基于字典的字符串本地化器
  • SparkdoStringLocalizerFactory: 字符串本地化器工厂

枚举本地化

  • IEnumLocalizer: 枚举本地化器接口
  • DefaultEnumLocalizer: 默认枚举本地化器实现

语言管理

  • ILanguageProvider: 语言提供者接口
  • DefaultLanguageProvider: 默认语言提供者实现
  • ILanguageInfo: 语言信息接口
  • LanguageInfo: 语言信息实现

资源贡献者

  • ILocalizationResourceContributor: 本地化资源贡献者接口
  • LocalizationResourceContributorList: 本地化资源贡献者列表

使用方法

基本本地化配置

// 在模块配置中添加本地化资源
public override void Configure(IConfigureContext context)
{
    context.Services.Configure<SparkdoLocalizationOptions>(options =>
    {
        options
            .Resources
            .Add<MyResource>("zh-Hans")
            .AddVirtualJson("/Localization/Resources/MyResource");
    });
}

使用本地化器

// 注入字符串本地化器
public class MyService
{
    private readonly IStringLocalizer _localizer;
    
    public MyService(IStringLocalizer<MyResource> localizer)
    {
        _localizer = localizer;
    }
    
    public string GetLocalizedMessage()
    {
        return _localizer["MyKey"];
    }
}

枚举本地化

// 使用枚举本地化器
public class MyService
{
    private readonly IEnumLocalizer _enumLocalizer;
    
    public MyService(IEnumLocalizer enumLocalizer)
    {
        _enumLocalizer = enumLocalizer;
    }
    
    public string GetLocalizedEnumValue(MyEnum enumValue)
    {
        return _enumLocalizer.GetString(typeof(MyEnum), enumValue);
    }
}

扩展性

该库提供了完整的本地化功能实现,可以通过以下方式扩展:

  1. 实现自定义的 ILocalizationResourceContributor 来提供特定的本地化资源贡献者
  2. 实现自定义的 ILanguageProvider 来提供特定的语言列表
  3. 实现自定义的 IEnumLocalizer 来提供特定的枚举本地化逻辑
  4. 实现自定义的本地化资源管理逻辑

代码结构说明

本项目包含以下主要组件:

本地化核心

  • SparkdoStringLocalizerFactory: 字符串本地化器工厂,负责创建和管理本地化器实例
  • SparkdoDictionaryBasedStringLocalizer: 基于字典的字符串本地化器,提供核心本地化功能
  • LocalizationResource: 本地化资源,表示一个具体的本地化资源
  • LocalizationResourceBase: 本地化资源基类,定义资源的基本结构

枚举本地化

  • IEnumLocalizer: 枚举本地化器接口,定义枚举本地化的方法
  • DefaultEnumLocalizer: 默认枚举本地化器实现,提供基本的枚举本地化功能

语言管理

  • ILanguageProvider: 语言提供者接口,定义获取语言列表的方法
  • DefaultLanguageProvider: 默认语言提供者实现
  • ILanguageInfo: 语言信息接口,定义语言的基本信息
  • LanguageInfo: 语言信息实现

资源贡献者

  • ILocalizationResourceContributor: 本地化资源贡献者接口,定义贡献者的功能
  • LocalizationResourceContributorList: 本地化资源贡献者列表,管理多个贡献者

配置选项

  • SparkdoLocalizationOptions: 本地化选项,配置本地化功能的各种选项
  • SparkdoLocalizationOptionsExtensions: 本地化选项扩展方法

所有公共接口和类都添加了详细的 XML 文档注释,便于开发者理解和使用。

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on Sparkdo.Localization:

Package Downloads
Sparkdo.ExceptionHandling

Sparkdo 异常元数据解析、观察分发、问题投影与调用边界运行时。

Sparkdo.Ddd.Application.Contracts

Sparkdo DDD应用层契约库,提供应用服务接口定义和数据传输对象(DTO)基类

Sparkdo.Features

Sparkdo 功能系统库,提供功能定义、管理、检查和拦截功能

Sparkdo.GlobalFeatures

Sparkdo 全局特性库,提供应用程序级别的特性开关管理和模块化特性控制功能

Sparkdo.Emailing

Sparkdo 邮件发送库,提供基于 SMTP 的邮件发送功能,支持同步/异步发送、后台队列发送和模板邮件

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-preview.2 52 7/20/2026
2.0.0-preview.1 46 7/18/2026
1.0.4-preview.3 456 6/8/2026
1.0.4-preview.2 436 6/7/2026
1.0.4-preview.1 409 6/7/2026
1.0.3 992 6/6/2026
1.0.3-preview.1 430 5/17/2026
1.0.2 795 4/27/2026
1.0.2-preview.5 168 4/15/2026
1.0.2-preview.4 171 2/8/2026
1.0.2-preview.3 185 2/1/2026
1.0.2-preview.2 193 1/31/2026
1.0.2-preview.1 236 12/4/2025
1.0.1 2,927 11/27/2025
1.0.0 2,835 11/25/2025
1.0.0-preview.5 162 10/24/2025