在ABP中,本地化资源有两种类型:静态本地化资源和动态本地化资源。静态本地化资源是在应用程序开发期间添加的本地化字符串,它们被嵌入到程序集中。动态本地化资源是在应用程序运行时通过源添加的本地化字符串。
要扩展ABP中的本地化资源源,您可以遵循以下步骤:
IApplicationLocalizationConfiguration
接口。public class MyApplicationLocalizationConfiguration : IApplicationLocalizationConfiguration
{
public List ExternalLocalizationSources { get; } = new List
{
typeof(MyCustomLocalizationDictionaryProvider)
};
}
MyCustomLocalizationDictionaryProvider
,该类继承自 ILocalizationDictionaryProvider
接口,并实现 GetDictionariesAsync
方法。public class MyCustomLocalizationDictionaryProvider : ILocalizationDictionaryProvider
{
private readonly IMyCustomLocalizationSource _myCustomLocalizationSource;
public MyCustomLocalizationDictionaryProvider(IMyCustomLocalizationSource myCustomLocalizationSource)
{
_myCustomLocalizationSource = myCustomLocalizationSource;
}
public async Task> GetDictionariesAsync(
GetLocalizationDictionariesInput input)
{
var dictionary = await _myCustomLocalizationSource.GetDictionaryAsync(input.CultureInfo);
return new List
{
new LocalizationDictionary(dictionary)
};
}
}
MyCustomLocalizationSource
,该类继承自 ILocalizationSource
接口,并实现 GetDictionaryAsync
方法。public class MyCustomLocalizationSource : ILocalizationSource
{
public string Name => "MyCustomLocalizationSource";
public Task> GetDictionaryAsync(CultureInfo culture)
{
// add your custom dictionary here
var dictionary = new Dictionary
{
{"Hello", "你好"},
{"Goodbye", "