Skip to main content
Version: v13.x - Umbraco 13

DeepL Glossaries

When map glossaries is selected the connector will try to match the glossary defined for the languages inside DeepL.

By default, the code looks like this:

public virtual TextTranslateOptions GetOptions(string sourceLanguage, string targetLanguage, bool IsHtml)
{
var options = new TextTranslateOptions
{
TagHandling = IsHtml ? "html" : string.Empty,
OutlineDetection = GetSetting("outlineDetection", true),
PreserveFormatting = GetSetting("preserveFormatting", false)
};

options.NonSplittingTags.AddRange(GetSettingsList("ignoreTags"));
options.IgnoreTags.AddRange(GetSettingsList("nonSplittingTags"));
options.SplittingTags.AddRange(GetSettingsList("splittingTags"));

if (GetSetting("mapGlossary", false))
{
var glossaryId = GetGlossaryId(sourceLanguage, targetLanguage);

if (!string.IsNullOrEmpty(glossaryId))
{
options.GlossaryId = glossaryId;
}
}

return options;
}

protected string GetGlossaryId(string sourceLanguageCode, string targetLanguageCode)
{
var glossaries = _deepLService.Value?.GetGlossaries().Result ?? new List<GlossaryInfo>();

var match = glossaries.FirstOrDefault(x =>
x.SourceLanguageCode == sourceLanguageCode
&& x.TargetLanguageCode == targetLanguageCode);

return match?.GlossaryId ?? string.Empty;
}

However, if you want to customize it, you can!

public class CustomDeepLConfigProvider : DeepLConfigurationBase, IDeepLConfigurationProvider
{
public CustomDeepLConfigProvider(
TranslationConfigService configService,
Lazy<IDeepLTranslationService> deepLService) : base(configService, deepLService)
{
}

public override TextTranslateOptions GetOptions(string sourceLanguage, string targetLanguage, bool IsHtml)
{
var options = base.GetOptions(sourceLanguage, targetLanguage, IsHtml);

// custom things here ?
options.GlossaryId = "my-id";

return options;
}
}

You will then need to register your configuration in a composer:

[ComposeAfter(typeof(Jumoo.TranslationManager.Connector.DeepL.DeepLComposer))]
public class CustomDeepLComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddSingleton<IDeepLConfigurationProvider, CustomDeepLConfigProvider>();
}
}