Notifications service: How to get the saved/published culture
When an editor publishes a node with several languages Umbraco logs this message:
[17:43:11 INF] Document Test (id=1458) cultures: en have been published.
I.e. here the editor was editing the en (English ) version of the document.
And if the editor updates a Danish version of the node Umbraco logs:
[17:43:11 INF] Document Test (id=1458) cultures: da have been published.
I try to implement an automatic AI generated translation from then English version of a sites' nodes to all other language versions for the node and for that I need to detect if the editor has been editing an en version (because then the updated en data should be translated and written to each other language versions of that node) or if the editor is editing an version that is not English (since then my code should do nothing as editors should be able to make changes to the individual language versions without my translate code overwriting it).
I have tried a lot of things, but it seems to be hard to get the same culture as the one that Umbraco's built-in log message returns. Has anyone got a suggestion?
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Models;
using Microsoft.Extensions.Logging;
namespace MartinRud.AI.Translate
{
public class ContentSavedHandler : INotificationHandler<ContentSavedNotification>
{
private readonly ILogger<ContentSavedHandler> _logger;
private readonly IContentService _contentService;
private readonly ILocalizationService _localizationService;
public ContentSavedHandler(
ILogger<ContentSavedHandler> logger,
IContentService contentService,
ILocalizationService localizationService)
{
_logger = logger;
_contentService = contentService;
_localizationService = localizationService;
}
public void Handle(ContentSavedNotification notification)
{
foreach (var entity in notification.SavedEntities)
{
_logger.LogInformation($"Processing entity {entity.Id} ({entity.ContentType.Alias})");
// Log the language version here
}
}
}
}
Notifications service: How to get the saved/published culture
When an editor publishes a node with several languages Umbraco logs this message:
I.e. here the editor was editing the en (English ) version of the document.
And if the editor updates a Danish version of the node Umbraco logs:
I try to implement an automatic AI generated translation from then English version of a sites' nodes to all other language versions for the node and for that I need to detect if the editor has been editing an en version (because then the updated en data should be translated and written to each other language versions of that node) or if the editor is editing an version that is not English (since then my code should do nothing as editors should be able to make changes to the individual language versions without my translate code overwriting it).
I have tried a lot of things, but it seems to be hard to get the same culture as the one that Umbraco's built-in log message returns. Has anyone got a suggestion?
is working on a reply...