Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions assets/Squidex.Assets.ImageSharp/ImageSharpThumbnailGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ protected override async Task CreateThumbnailCoreAsync(Stream source, string mim
if (w > 0 || h > 0)
{
var resizeMode = GetResizeMode(options, w, h, image);
var resizeOptions = new ImageSharpOptions { Size = new Size(w, h), Mode = resizeMode, PremultiplyAlpha = true };
var bgColor = options.Background != null && Color.TryParse(options.Background, out var color) ? color : Color.Transparent;
Comment thread
thornch marked this conversation as resolved.
var resizeOptions = new ImageSharpOptions { Size = new Size(w, h), Mode = resizeMode, PremultiplyAlpha = true, PadColor = bgColor };

if (options.FocusX.HasValue && options.FocusY.HasValue)
{
Expand All @@ -89,14 +90,7 @@ protected override async Task CreateThumbnailCoreAsync(Stream source, string mim

operation.Resize(resizeOptions);

if (options.Background != null && Color.TryParse(options.Background, out var color))
{
operation.BackgroundColor(color);
}
else
{
operation.BackgroundColor(Color.Transparent);
}
operation.BackgroundColor(bgColor);
Comment thread
thornch marked this conversation as resolved.
}

if (watermark != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public sealed class DeepLTranslationOptions
{
public string AuthKey { get; set; }

public string GlossaryById { get; set; } // glossary_id
Comment thread
thornch marked this conversation as resolved.
public string GlossaryByName { get; set; }
public string TagHandling { get; set; } // tag_handling

public decimal CostsPerCharacterInEUR { get; set; } = 20m / 1_000_000;

public Dictionary<string, string> Mapping { get; set; }
Expand Down
69 changes: 69 additions & 0 deletions text/Squidex.Text/Translations/DeepL/DeepLTranslationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ private sealed class TranslationDto
public string DetectedSourceLanguage { get; set; }
}

private sealed class GlossariesDto
{
[JsonPropertyName("glossaries")]
public GlossaryDto[] Glossaries { get; set; }
}

private sealed class GlossaryDto
{
[JsonPropertyName("glossary_id")]
public string GlossaryId { get; set; } // "def3a26b-3e84-45b3-84ae-0c0aaf3525f7"
Comment thread
thornch marked this conversation as resolved.

[JsonPropertyName("name")]
public string Name { get; set; } // "My Glossary"

[JsonPropertyName("ready")]
public bool Ready { get; set; } // true

[JsonPropertyName("source_lang")]
public string SourceLang { get; set; } // "EN"

[JsonPropertyName("target_lang")]
public string TargetLang { get; set; } // "DE"

[JsonPropertyName("creation_time")]
public DateTime CreationTime { get; set; } // "2021-08-03T14:16:18.329Z"

[JsonPropertyName("entry_count")]
public int EntryCount { get; set; } // 1
}

public bool IsConfigured { get; } = !string.IsNullOrWhiteSpace(options.Value.AuthKey);

public async Task<IReadOnlyList<TranslationResult>> TranslateAsync(IEnumerable<string> texts, string targetLanguage, string? sourceLanguage = null,
Expand Down Expand Up @@ -80,6 +110,45 @@ public async Task<IReadOnlyList<TranslationResult>> TranslateAsync(IEnumerable<s
UrlPaid;

using var httpClient = CreateClient();

if (!string.IsNullOrWhiteSpace(options.GlossaryByName) && string.IsNullOrWhiteSpace(options.GlossaryById))
Comment thread
thornch marked this conversation as resolved.
{
var gl_url = url.Replace("/translate", "/glossaries");
Comment thread
thornch marked this conversation as resolved.
using var gl_httpRequest = new HttpRequestMessage(HttpMethod.Get, gl_url);
using var gl_httpResponse = await httpClient.SendAsync(gl_httpRequest, ct);

try
{
gl_httpResponse.EnsureSuccessStatusCode();

var gl_jsonString = await gl_httpResponse.Content.ReadAsStringAsync(ct);
var gl_jsonResponse = JsonSerializer.Deserialize<GlossariesDto>(gl_jsonString)!;

foreach (var glossary in gl_jsonResponse.Glossaries)
{
if (options.GlossaryByName.Equals(glossary.Name, StringComparison.Ordinal))
{
options.GlossaryById = glossary.GlossaryId;
Comment thread
thornch marked this conversation as resolved.
break;
}
}
}
catch (Exception ex)
{
AddError(TranslationResult.Failed(ex));
}
}

if (!string.IsNullOrWhiteSpace(options.GlossaryById))
{
parameters.Add(new KeyValuePair<string, string>("glossary_id", options.GlossaryById));
}

if (!string.IsNullOrWhiteSpace(options.TagHandling))
{
parameters.Add(new KeyValuePair<string, string>("tag_handling", options.TagHandling));
}

using var httpRequest = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = new FormUrlEncodedContent(parameters!),
Expand Down