-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
923a469
commit b33e499
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"", | ||
}},"); | ||
|
||
}); | ||
} | ||
} | ||
} |
b33e499
There was a problem hiding this comment.
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:
Note: You can check from where the translation is comming by hovering over the select option:
Migration
Just run
Upgrade_20210119_DeepL
, it will ask for your Azure / DeepL API Keysb33e499
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.