Skip to content

Commit

Permalink
add Upgrade_20210119_DeepL
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Jan 19, 2021
1 parent 923a469 commit b33e499
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions Signum.Upgrade/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static void Main(string[] args)
new Upgrade_20201231_AnyCPU(),
new Upgrade_20210108_RemoveLangVersion(),
new Upgrade_20210113_TimezoneInDockerfile(),
new Upgrade_20210119_DeepL(),
}.Run(uctx);
}
}
Expand Down
92 changes: 92 additions & 0 deletions Signum.Upgrade/Upgrades/Upgrade_20210119_DeepL.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Signum.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace Signum.Upgrade.Upgrades
{
class Upgrade_20210119_DeepL : CodeUpgradeBase
{
public override string Description => "Add DeepL support and parallel translations";

public override void Execute(UpgradeContext uctx)
{
uctx.ChangeCodeFile(@"Southwind.Entities/ApplicationConfiguration.cs ", file =>
{
file.InsertBeforeFirstLine(a => a.Contains("[AutoInit]"),
@"
[Serializable]
public class TranslationConfigurationEmbedded : EmbeddedEntity
{
[Description(""Azure Cognitive Service API Key"")]
[StringLengthValidator(Max = 300), FileNameValidator]
public string? AzureCognitiveServicesAPIKey { get; set; }
[Description(""Azure Cognitive Service Region"")]
[StringLengthValidator(Max = 300), FileNameValidator]
public string? AzureCognitiveServicesRegion { get; set; }
[Description(""DeepL API Key"")]
[StringLengthValidator(Max = 300), FileNameValidator]
public string? DeepLAPIKey { get; set; }
}
");
file.InsertAfterFirstLine(a => a.Contains("public FoldersConfigurationEmbedded Folders { get; set; }"),
@"
public TranslationConfigurationEmbedded Translation { get; set; }");
});

uctx.ChangeCodeFile(@"Southwind.React/App/Agile360/Templates/ApplicationConfiguration.tsx", file =>
{
file.InsertAfterLastLine(a => a.Contains("</Tab>"),
@"<Tab eventKey=""translation"" title={ctx.niceName(a => a.translation)}>
<RenderEntity ctx={ctx.subCtx(a => a.translation)} />
</Tab>");
});

uctx.ChangeCodeFile(@"Southwind.React/Startup.cs", file =>
{
file.ReplaceLine(a => a.Contains("TranslationServer.Start(app, new AlreadyTranslatedTranslator"),
@"TranslationServer.Start(app,
new AlreadyTranslatedTranslator(),
new AzureTranslator(
() => Starter.Configuration.Value.Translation.AzureCognitiveServicesAPIKey,
() => Starter.Configuration.Value.Translation.AzureCognitiveServicesRegion),
new DeepLTranslator(() => Starter.Configuration.Value.Translation.DeepLAPIKey)
);");
});

var azureKey = SafeConsole.AskString("Azure API Key?");
var deeplKey = SafeConsole.AskString("DeepL API Key?");

uctx.ChangeCodeFile(@"Southwind.Terminal\SouthwindMigrations.cs", file =>
{
file.InsertBeforeFirstLine(a => a.Contains("Folders = new FoldersConfigurationEmbedded"),
@$"Translation = new TranslationConfigurationEmbedded
{{
AzureCognitiveServicesAPIKey = ""{azureKey}"",
DeepLAPIKey = ""{deeplKey}"",
}},");
});

uctx.ChangeCodeFile(@"Southwind.Test.Environment/BasicLoader.cs", file =>
{
file.InsertBeforeFirstLine(a => a.Contains("Folders = new FoldersConfigurationEmbedded"),
@$"Translation = new TranslationConfigurationEmbedded
{{
AzureCognitiveServicesAPIKey = ""{azureKey}"",
DeepLAPIKey = ""{deeplKey}"",
}},");
});
}
}
}

2 comments on commit b33e499

@olmobrutall
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvements in Translations (DeepL)

This commit adds the Upgrade for some changes in Translation module:

  • Out of the box support for DeepL API (great results for european languages)
  • Upgrade of Azure Cognitive Services API from XML to Json (XML will be deprecated soon)
  • API Keys are now stored in ApplicationConfiguration instead of hardcoded in Starter.cs
  • Support for parallel translators (like Azure and DeepL). If all the available Translators x Support languages agree on the same translation is autos elected.

Note: You can check from where the translation is comming by hovering over the select option:

image

Migration

Just run Upgrade_20210119_DeepL, it will ask for your Azure / DeepL API Keys

@MehdyKarimpour
Copy link
Contributor

@MehdyKarimpour MehdyKarimpour commented on b33e499 Jan 19, 2021 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.