Browse Source

Merge pull request #26471 from abpframework/auto-merge-forward/rel-11.0-to-dev-179

Auto-merge forward rel-11.0 → dev
payment-docs
Volosoft Agent 1 week ago
committed by GitHub
parent
commit
2dbcdeedef
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      docs/en/modules/language-management.md
  2. 32
      modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/DefaultLanguageSettingChangedHandler.cs
  3. 99
      modules/setting-management/test/Volo.Abp.SettingManagement.Tests/Volo/Abp/SettingManagement/DefaultLanguageSettingChangedHandler_Tests.cs

2
docs/en/modules/language-management.md

@ -336,6 +336,6 @@ public class MyHandler :
The module already configures the `Language` to `LanguageEto` and `LanguageText` to `LanguageTextEto` mappings. Language entity changes also publish `LanguageChangedEto`, which consumers can use to refresh their language list. See the [Distributed Event Bus](../framework/infrastructure/event-bus/distributed) document for details of the pre-defined entity events.
The module already configures the `Language` to `LanguageEto` and `LanguageText` to `LanguageTextEto` mappings. Language entity changes also publish `LanguageChangedEto`, which consumers can use to refresh their language list. Changing the application or tenant default language (the `Abp.Localization.DefaultLanguage` setting, including **Set as default language**) likewise publishes `LanguageChangedEto`, so request localization options pick up the new default without an application restart. The default language is used only when the request doesn't select a supported culture (query string, cookie or `Accept-Language` header). See the [Distributed Event Bus](../framework/infrastructure/event-bus/distributed) document for details of the pre-defined entity events.
> Subscribing to distributed events is especially useful for distributed scenarios (like microservice architecture). If you are building a monolithic application or listening for events in the same process that runs the Language Management Module, subscribing to the [Local Event Bus](../framework/infrastructure/event-bus/local) can be simpler.

32
modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/DefaultLanguageSettingChangedHandler.cs

@ -0,0 +1,32 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Localization;
using Volo.Abp.Settings;
namespace Volo.Abp.SettingManagement;
public class DefaultLanguageSettingChangedHandler :
ILocalEventHandler<EntityChangedEventData<Setting>>,
ITransientDependency
{
protected IDistributedEventBus DistributedEventBus { get; }
public DefaultLanguageSettingChangedHandler(IDistributedEventBus distributedEventBus)
{
DistributedEventBus = distributedEventBus;
}
public virtual async Task HandleEventAsync(EntityChangedEventData<Setting> eventData)
{
if (eventData.Entity.Name != LocalizationSettingNames.DefaultLanguage ||
eventData.Entity.ProviderName == UserSettingValueProvider.ProviderName)
{
return;
}
await DistributedEventBus.PublishAsync(new LanguageChangedEto());
}
}

99
modules/setting-management/test/Volo.Abp.SettingManagement.Tests/Volo/Abp/SettingManagement/DefaultLanguageSettingChangedHandler_Tests.cs

@ -0,0 +1,99 @@
using System;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Localization;
using Volo.Abp.Settings;
using Volo.Abp.Uow;
using Xunit;
namespace Volo.Abp.SettingManagement;
public class DefaultLanguageSettingChangedHandler_Tests : SettingsTestBase
{
private readonly ISettingManagementStore _settingManagementStore;
private readonly IDistributedEventBus _distributedEventBus;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public DefaultLanguageSettingChangedHandler_Tests()
{
_settingManagementStore = GetRequiredService<ISettingManagementStore>();
_distributedEventBus = GetRequiredService<IDistributedEventBus>();
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
}
[Fact]
public async Task Should_Publish_LanguageChangedEto_When_DefaultLanguage_Setting_Changed()
{
var languageChanged = false;
using (var uow = _unitOfWorkManager.Begin())
{
_distributedEventBus.Subscribe<LanguageChangedEto>(_ =>
{
languageChanged = true;
return Task.CompletedTask;
});
await _settingManagementStore.SetAsync(
LocalizationSettingNames.DefaultLanguage,
"tr;tr",
GlobalSettingValueProvider.ProviderName,
null);
await uow.CompleteAsync();
}
languageChanged.ShouldBeTrue();
}
[Fact]
public async Task Should_Not_Publish_LanguageChangedEto_When_Other_Setting_Changed()
{
var languageChanged = false;
using (var uow = _unitOfWorkManager.Begin())
{
_distributedEventBus.Subscribe<LanguageChangedEto>(_ =>
{
languageChanged = true;
return Task.CompletedTask;
});
await _settingManagementStore.SetAsync(
"MySetting2",
"MySetting2Value-updated",
GlobalSettingValueProvider.ProviderName,
null);
await uow.CompleteAsync();
}
languageChanged.ShouldBeFalse();
}
[Fact]
public async Task Should_Not_Publish_LanguageChangedEto_When_User_DefaultLanguage_Setting_Changed()
{
var languageChanged = false;
using (var uow = _unitOfWorkManager.Begin())
{
_distributedEventBus.Subscribe<LanguageChangedEto>(_ =>
{
languageChanged = true;
return Task.CompletedTask;
});
await _settingManagementStore.SetAsync(
LocalizationSettingNames.DefaultLanguage,
"tr;tr",
UserSettingValueProvider.ProviderName,
Guid.NewGuid().ToString());
await uow.CompleteAsync();
}
languageChanged.ShouldBeFalse();
}
}
Loading…
Cancel
Save