Skip to content

Commit b33e499

Browse files
committed
add Upgrade_20210119_DeepL
1 parent 923a469 commit b33e499

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

Signum.Upgrade/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static void Main(string[] args)
4444
new Upgrade_20201231_AnyCPU(),
4545
new Upgrade_20210108_RemoveLangVersion(),
4646
new Upgrade_20210113_TimezoneInDockerfile(),
47+
new Upgrade_20210119_DeepL(),
4748
}.Run(uctx);
4849
}
4950
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using Signum.Utilities;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Security.Cryptography.X509Certificates;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Signum.Upgrade.Upgrades
11+
{
12+
class Upgrade_20210119_DeepL : CodeUpgradeBase
13+
{
14+
public override string Description => "Add DeepL support and parallel translations";
15+
16+
public override void Execute(UpgradeContext uctx)
17+
{
18+
uctx.ChangeCodeFile(@"Southwind.Entities/ApplicationConfiguration.cs ", file =>
19+
{
20+
file.InsertBeforeFirstLine(a => a.Contains("[AutoInit]"),
21+
@"
22+
[Serializable]
23+
public class TranslationConfigurationEmbedded : EmbeddedEntity
24+
{
25+
[Description(""Azure Cognitive Service API Key"")]
26+
[StringLengthValidator(Max = 300), FileNameValidator]
27+
public string? AzureCognitiveServicesAPIKey { get; set; }
28+
29+
[Description(""Azure Cognitive Service Region"")]
30+
[StringLengthValidator(Max = 300), FileNameValidator]
31+
public string? AzureCognitiveServicesRegion { get; set; }
32+
33+
[Description(""DeepL API Key"")]
34+
[StringLengthValidator(Max = 300), FileNameValidator]
35+
public string? DeepLAPIKey { get; set; }
36+
}
37+
38+
");
39+
40+
file.InsertAfterFirstLine(a => a.Contains("public FoldersConfigurationEmbedded Folders { get; set; }"),
41+
@"
42+
public TranslationConfigurationEmbedded Translation { get; set; }");
43+
});
44+
45+
uctx.ChangeCodeFile(@"Southwind.React/App/Agile360/Templates/ApplicationConfiguration.tsx", file =>
46+
{
47+
file.InsertAfterLastLine(a => a.Contains("</Tab>"),
48+
@"<Tab eventKey=""translation"" title={ctx.niceName(a => a.translation)}>
49+
<RenderEntity ctx={ctx.subCtx(a => a.translation)} />
50+
</Tab>");
51+
52+
});
53+
54+
uctx.ChangeCodeFile(@"Southwind.React/Startup.cs", file =>
55+
{
56+
file.ReplaceLine(a => a.Contains("TranslationServer.Start(app, new AlreadyTranslatedTranslator"),
57+
@"TranslationServer.Start(app,
58+
new AlreadyTranslatedTranslator(),
59+
new AzureTranslator(
60+
() => Starter.Configuration.Value.Translation.AzureCognitiveServicesAPIKey,
61+
() => Starter.Configuration.Value.Translation.AzureCognitiveServicesRegion),
62+
new DeepLTranslator(() => Starter.Configuration.Value.Translation.DeepLAPIKey)
63+
);");
64+
65+
});
66+
67+
var azureKey = SafeConsole.AskString("Azure API Key?");
68+
var deeplKey = SafeConsole.AskString("DeepL API Key?");
69+
70+
uctx.ChangeCodeFile(@"Southwind.Terminal\SouthwindMigrations.cs", file =>
71+
{
72+
file.InsertBeforeFirstLine(a => a.Contains("Folders = new FoldersConfigurationEmbedded"),
73+
@$"Translation = new TranslationConfigurationEmbedded
74+
{{
75+
AzureCognitiveServicesAPIKey = ""{azureKey}"",
76+
DeepLAPIKey = ""{deeplKey}"",
77+
}},");
78+
});
79+
80+
uctx.ChangeCodeFile(@"Southwind.Test.Environment/BasicLoader.cs", file =>
81+
{
82+
file.InsertBeforeFirstLine(a => a.Contains("Folders = new FoldersConfigurationEmbedded"),
83+
@$"Translation = new TranslationConfigurationEmbedded
84+
{{
85+
AzureCognitiveServicesAPIKey = ""{azureKey}"",
86+
DeepLAPIKey = ""{deeplKey}"",
87+
}},");
88+
89+
});
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)