Created I18N data, part 1 (#404)
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, deb) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2025-04-24 13:50:14 +02:00
1 parent 02c3e4c817
commit 3e13d50302
50 files changed
+1384 -481

No files matched your search

+145 -7
View File
@@ -25,8 +25,8 @@ public sealed partial class CollectI18NKeysCommand
var wwwrootPath = Path.Join(cwd, "wwwroot");
var allFiles = Directory.EnumerateFiles(cwd, "*", SearchOption.AllDirectories);
var counter = 0;
var sb = new StringBuilder();
var allI18NContent = new Dictionary<string, string>();
foreach (var filePath in allFiles)
{
counter++;
@@ -46,17 +46,155 @@ public sealed partial class CollectI18NKeysCommand
var ns = this.DetermineNamespace(filePath);
var fileInfo = new FileInfo(filePath);
var name = fileInfo.Name.Replace(fileInfo.Extension, string.Empty);
var langNamespace = $"{ns}::{name}".ToUpperInvariant().Replace(".", "::");
var name = fileInfo.Name.Replace(fileInfo.Extension, string.Empty).Replace(".razor", string.Empty);
var langNamespace = $"{ns}.{name}".ToUpperInvariant();
foreach (var match in matches)
{
var key = $"root::{langNamespace}::T{match.ToFNV32()}";
// The key in the format A.B.C.D.T{hash}:
var key = $"UI_TEXT_CONTENT.{langNamespace}.T{match.ToFNV32()}";
allI18NContent.TryAdd(key, match);
}
}
Console.WriteLine($" {counter:###,###} files processed.");
Console.WriteLine();
Console.WriteLine($" {counter:###,###} files processed, {allI18NContent.Count:###,###} keys found.");
Console.Write("- Creating Lua code ...");
var luaCode = this.ExportToLuaTable(allI18NContent);
// Build the path, where we want to store the Lua code:
var luaPath = Path.Join(cwd, "Assistants", "I18N", "allTexts.lua");
// Store the Lua code:
await File.WriteAllTextAsync(luaPath, luaCode, Encoding.UTF8);
Console.WriteLine(" done.");
}
private string ExportToLuaTable(Dictionary<string, string> keyValuePairs)
{
// Collect all nodes:
var root = new Dictionary<string, object>();
//
// Split all collected keys into nodes:
//
foreach (var key in keyValuePairs.Keys.Order())
{
var path = key.Split('.');
var current = root;
for (var i = 0; i < path.Length - 1; i++)
{
// We ignore the AISTUDIO segment of the path:
if(path[i] == "AISTUDIO")
continue;
if (!current.TryGetValue(path[i], out var child) || child is not Dictionary<string, object> childDict)
{
childDict = new Dictionary<string, object>();
current[path[i]] = childDict;
}
current = childDict;
}
current[path.Last()] = keyValuePairs[key];
}
//
// Inner method to build Lua code from the collected nodes:
//
void ToLuaTable(StringBuilder sb, Dictionary<string, object> innerDict, int indent = 0)
{
sb.AppendLine("{");
var prefix = new string(' ', indent * 4);
foreach (var kvp in innerDict)
{
if (kvp.Value is Dictionary<string, object> childDict)
{
sb.Append($"{prefix} {kvp.Key}");
sb.Append(" = ");
ToLuaTable(sb, childDict, indent + 1);
}
else if (kvp.Value is string s)
{
sb.AppendLine($"{prefix} -- {s.Trim().Replace("\n", " ")}");
sb.Append($"{prefix} {kvp.Key}");
sb.Append(" = ");
sb.Append($"""
"{s}"
""");
sb.AppendLine(",");
sb.AppendLine();
}
}
sb.AppendLine(prefix + "},");
sb.AppendLine();
}
//
// Write the Lua code:
//
var sbLua = new StringBuilder();
// To make the later parsing easier, we add the mandatory plugin
// metadata:
sbLua.AppendLine(
"""
-- The ID for this plugin:
ID = "77c2688a-a68f-45cc-820e-fa8f3038a146"
-- The icon for the plugin:
ICON_SVG = ""
-- The name of the plugin:
NAME = "Collected I18N keys"
-- The description of the plugin:
DESCRIPTION = "This plugin is not meant to be used directly. Its a collection of all I18N keys found in the project."
-- The version of the plugin:
VERSION = "1.0.0"
-- The type of the plugin:
TYPE = "LANGUAGE"
-- The authors of the plugin:
AUTHORS = {"MindWork AI Community"}
-- The support contact for the plugin:
SUPPORT_CONTACT = "MindWork AI Community"
-- The source URL for the plugin:
SOURCE_URL = "https://github.com/MindWorkAI/AI-Studio"
-- The categories for the plugin:
CATEGORIES = { "CORE" }
-- The target groups for the plugin:
TARGET_GROUPS = { "EVERYONE" }
-- The flag for whether the plugin is maintained:
IS_MAINTAINED = true
-- When the plugin is deprecated, this message will be shown to users:
DEPRECATION_MESSAGE = ""
-- The IETF BCP 47 tag for the language. It's the ISO 639 language
-- code followed by the ISO 3166-1 country code:
IETF_TAG = "en-US"
-- The language name in the user's language:
LANG_NAME = "English (United States)"
""");
sbLua.Append("UI_TEXT_CONTENT = ");
if(root["UI_TEXT_CONTENT"] is Dictionary<string, object> dict)
ToLuaTable(sbLua, dict);
return sbLua.ToString();
}
private List<string> FindAllTextTags(ReadOnlySpan<char> fileContent)
@@ -2,8 +2,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
using Build.Tools;
using SharedTools;
namespace Build.Commands;