Refactored I18N key handling in build script (#443)

This commit is contained in:
Thorsten Sommer 2025-05-03 16:17:23 +02:00 committed by GitHub
parent 10dc03f33b
commit 6041b42510
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 29 deletions

View File

@ -10,6 +10,29 @@ namespace Build.Commands;
public sealed partial class CollectI18NKeysCommand
{
private const string START_TAG1 = """
T("
""";
private const string START_TAG2 = """
TB("
""";
private const string START_TAG3 = """
T(@"
""";
private const string END_TAG = """
")
""";
private static readonly (string Tag, int Length)[] START_TAGS =
[
(START_TAG1, START_TAG1.Length),
(START_TAG2, START_TAG2.Length),
(START_TAG3, START_TAG3.Length)
];
[Command("collect-i18n", Description = "Collect I18N keys")]
public async Task CollectI18NKeys()
{
@ -133,36 +156,22 @@ public sealed partial class CollectI18NKeysCommand
private List<string> FindAllTextTags(ReadOnlySpan<char> fileContent)
{
const string START_TAG1 = """
T("
""";
const string START_TAG2 = """
TB("
""";
const string END_TAG = """
")
""";
(int Index, int Len) FindNextStart(ReadOnlySpan<char> content)
{
var startIdx1 = content.IndexOf(START_TAG1);
var startIdx2 = content.IndexOf(START_TAG2);
if (startIdx1 == -1 && startIdx2 == -1)
return (-1, 0);
if (startIdx1 == -1)
return (startIdx2, START_TAG2.Length);
if (startIdx2 == -1)
return (startIdx1, START_TAG1.Length);
if (startIdx1 < startIdx2)
return (startIdx1, START_TAG1.Length);
return (startIdx2, START_TAG2.Length);
var bestIndex = -1;
var bestLength = 0;
foreach (var (tag, length) in START_TAGS)
{
var index = content.IndexOf(tag);
if (index != -1 && (bestIndex == -1 || index < bestIndex))
{
bestIndex = index;
bestLength = length;
}
}
return (bestIndex, bestLength);
}
var matches = new List<string>();

View File

@ -445,6 +445,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CHATCOMPONENT::T636393754"] = "Move the c
-- Show your workspaces
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CHATCOMPONENT::T733672375"] = "Show your workspaces"
-- Start new chat in workspace "{0}"
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CHATCOMPONENT::T896906391"] = "Start new chat in workspace \"{0}\""
-- Region
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CONFIDENCEINFO::T1227782301"] = "Region"

View File

@ -270,7 +270,9 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
private bool CanThreadBeSaved => this.ChatThread is not null && this.ChatThread.Blocks.Count > 0;
private string TooltipAddChatToWorkspace => string.Format(T(@"Start new chat in workspace ""{0}"""), this.currentWorkspaceName);
private string TooltipAddChatToWorkspace => string.Format(T("""
Start new chat in workspace "{0}"
"""), this.currentWorkspaceName);
private string UserInputStyle => this.SettingsManager.ConfigurationData.LLMProviders.ShowProviderConfidence ? this.Provider.UsedLLMProvider.GetConfidence(this.SettingsManager).SetColorStyle(this.SettingsManager) : string.Empty;