Skip to content

Commit

Permalink
Add option to translate CLI command to stop loop and save collected c…
Browse files Browse the repository at this point in the history
…hanges
  • Loading branch information
tjementum committed Oct 9, 2024
1 parent 649dc9d commit 2965e17
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions developer-cli/Commands/TranslateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,28 @@ public async Task<IReadOnlyCollection<POSingularEntry>> Translate(IReadOnlyColle
foreach (var nonTranslatedEntry in nonTranslatedEntries)
{
var translated = await TranslateSingleEntry(translatedEntries.AsReadOnly(), nonTranslatedEntry);
if (translated == null) // User chose to stop
{
AnsiConsole.MarkupLine("[yellow]Translation process stopped. Saving changes collected so far.[/]");
break;
}
if (!translated.HasTranslation()) continue;
translatedEntries.Add(translated);
toReturn.Add(translated);
}

AnsiConsole.MarkupLine("[green]All missing values have been translated.[/]");
if (toReturn.Count > 0)
{
AnsiConsole.MarkupLine($"[green]{toReturn.Count} entries have been translated.[/]");
}
else
{
AnsiConsole.MarkupLine("[yellow]No entries were translated.[/]");
}
return toReturn;
}

private async Task<POSingularEntry> TranslateSingleEntry(
private async Task<POSingularEntry?> TranslateSingleEntry(
IReadOnlyCollection<POSingularEntry> translatedEntries,
POSingularEntry nonTranslatedEntry
)
Expand Down Expand Up @@ -199,7 +211,7 @@ await AnsiConsole.Status().StartAsync("Initialize translation...", async context
var choice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("What would you like to do?")
.AddChoices("Accept translation", "Try again", "Provide context for retranslation", "Input own translation", "Skip")
.AddChoices("Accept translation", "Try again", "Provide context for retranslation", "Input own translation", "Skip", "Stop and save")
);

switch (choice)
Expand All @@ -226,6 +238,9 @@ await AnsiConsole.Status().StartAsync("Initialize translation...", async context
case "Skip":
AnsiConsole.MarkupLine("[yellow]Translation skipped.[/]");
return translated.ApplyTranslation(string.Empty);
case "Stop and save":
AnsiConsole.MarkupLine("[yellow]Stopping translation process.[/]");
return null;
}
}
}
Expand Down

0 comments on commit 2965e17

Please sign in to comment.