Refactored process step descriptions & added them to I18N

This commit is contained in:
Thorsten Sommer 2025-09-03 22:13:01 +02:00
parent 317c039e98
commit 3ccd02887f
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
6 changed files with 138 additions and 27 deletions

View File

@ -1714,6 +1714,24 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENT::T3825586228"] = "Please p
-- Show web content options -- Show web content options
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENT::T4249712357"] = "Show web content options" UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENT::T4249712357"] = "Show web content options"
-- Loading
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T1404011351"] = "Loading"
-- Start
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T182978943"] = "Start"
-- Done
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T2379421585"] = "Done"
-- Parsing
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T3151033983"] = "Parsing"
-- Cleaning
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T3420573362"] = "Cleaning"
-- n/a
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T907272257"] = "n/a"
-- Hide content -- Hide content
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::SECRETINPUTFIELD::T1273315904"] = "Hide content" UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::SECRETINPUTFIELD::T1273315904"] = "Hide content"

View File

@ -0,0 +1,24 @@
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Components;
public static class ReadWebContentStepsExtensions
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ReadWebContentStepsExtensions).Namespace, nameof(ReadWebContentStepsExtensions));
/// <summary>
/// Gets the text representation of a given ReadWebContentSteps enum value.
/// </summary>
/// <param name="step">The ReadWebContentSteps enum value.</param>
/// <returns>>The text representation of the process step.</returns>
public static string GetText(this ReadWebContentSteps step) => step switch
{
ReadWebContentSteps.START => TB("Start"),
ReadWebContentSteps.LOADING => TB("Loading"),
ReadWebContentSteps.PARSING => TB("Parsing"),
ReadWebContentSteps.CLEANING => TB("Cleaning"),
ReadWebContentSteps.DONE => TB("Done"),
_ => TB("n/a")
};
}

View File

@ -1716,6 +1716,24 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENT::T3825586228"] = "Bitte ge
-- Show web content options -- Show web content options
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENT::T4249712357"] = "Optionen für Webinhalte anzeigen" UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENT::T4249712357"] = "Optionen für Webinhalte anzeigen"
-- Loading
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T1404011351"] = "Laden"
-- Start
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T182978943"] = "Start"
-- Done
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T2379421585"] = "Fertig"
-- Parsing
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T3151033983"] = "Zerlegen"
-- Cleaning
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T3420573362"] = "Bereinigen"
-- n/a
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T907272257"] = "n/a"
-- Hide content -- Hide content
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::SECRETINPUTFIELD::T1273315904"] = "Inhalt ausblenden" UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::SECRETINPUTFIELD::T1273315904"] = "Inhalt ausblenden"

View File

@ -1716,6 +1716,24 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENT::T3825586228"] = "Please p
-- Show web content options -- Show web content options
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENT::T4249712357"] = "Show web content options" UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENT::T4249712357"] = "Show web content options"
-- Loading
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T1404011351"] = "Loading"
-- Start
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T182978943"] = "Start"
-- Done
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T2379421585"] = "Done"
-- Parsing
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T3151033983"] = "Parsing"
-- Cleaning
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T3420573362"] = "Cleaning"
-- n/a
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::READWEBCONTENTSTEPSEXTENSIONS::T907272257"] = "n/a"
-- Hide content -- Hide content
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::SECRETINPUTFIELD::T1273315904"] = "Hide content" UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::SECRETINPUTFIELD::T1273315904"] = "Hide content"

View File

@ -1,5 +1,3 @@
using System.Text;
namespace AIStudio.Tools; namespace AIStudio.Tools;
public sealed class Process<T> where T : struct, Enum public sealed class Process<T> where T : struct, Enum
@ -20,7 +18,7 @@ public sealed class Process<T> where T : struct, Enum
{ {
var value = values[i]; var value = values[i];
var stepValue = Convert.ToInt32(value); var stepValue = Convert.ToInt32(value);
var stepName = DeriveName(value); var stepName = ProcessStepTextRouter.GetText(value);
this.labels[i] = stepName; this.labels[i] = stepName;
this.stepsData[value] = new ProcessStepValue(stepValue, stepName); this.stepsData[value] = new ProcessStepValue(stepValue, stepName);
@ -33,30 +31,6 @@ public sealed class Process<T> where T : struct, Enum
} }
} }
private static string DeriveName(T value)
{
var text = value.ToString();
if (!text.Contains('_'))
{
text = text.ToLowerInvariant();
text = char.ToUpperInvariant(text[0]) + text[1..];
}
else
{
var parts = text.Split('_');
var sb = new StringBuilder();
foreach (var part in parts)
{
sb.Append(char.ToUpperInvariant(part[0]));
sb.Append(part[1..].ToLowerInvariant());
}
text = sb.ToString();
}
return text;
}
public string[] Labels => this.labels; public string[] Labels => this.labels;
public int Min => this.min; public int Min => this.min;

View File

@ -0,0 +1,59 @@
using System.Text;
using AIStudio.Components;
namespace AIStudio.Tools;
/// <summary>
/// Routes process step enums to their corresponding text representations, when possible.
/// </summary>
public static class ProcessStepTextRouter
{
/// <summary>
/// Gets the text representation of a given process step enum.
/// </summary>
/// <remarks>
/// Gets the text representation of a given process step enum.
/// When the enum type has a specific extension method for text retrieval, it uses that;
/// otherwise, it derives a name based on the enum value.
/// </remarks>
/// <param name="step">The process step enum value.</param>
/// <typeparam name="T">The enum type representing the process steps.</typeparam>
/// <returns>The text representation of the process step.</returns>
public static string GetText<T>(T step) where T : struct, Enum => step switch
{
ReadWebContentSteps x => x.GetText(),
_ => DeriveName(step)
};
/// <summary>
/// Derives a name from the enum value by converting it to a more human-readable format.
/// It handles both single-word and multi-word enum values (separated by underscores).
/// </summary>
/// <param name="value">The enum value to derive the name from.</param>
/// <typeparam name="T">The enum type.</typeparam>
/// <returns>A human-readable name derived from the enum value.</returns>
private static string DeriveName<T>(T value) where T : struct, Enum
{
var text = value.ToString();
if (!text.Contains('_'))
{
text = text.ToLowerInvariant();
text = char.ToUpperInvariant(text[0]) + text[1..];
}
else
{
var parts = text.Split('_');
var sb = new StringBuilder();
foreach (var part in parts)
{
sb.Append(char.ToUpperInvariant(part[0]));
sb.Append(part[1..].ToLowerInvariant());
}
text = sb.ToString();
}
return text;
}
}