Automated localization updates for selected languages (#599)
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, appimage deb updater) (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-12-16 18:37:57 +01:00
1 parent bf41e3a937
commit 23594cdda6
5 files changed
+134 -4

No files matched your search

@@ -56,10 +56,18 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
[
new ButtonData
{
#if DEBUG
Text = T("Write Lua code to language plugin file"),
#else
Text = T("Copy Lua code to clipboard"),
#endif
Icon = Icons.Material.Filled.Extension,
Color = Color.Default,
#if DEBUG
AsyncAction = async () => await this.WriteToPluginFile(),
#else
AsyncAction = async () => await this.RustService.CopyText2Clipboard(this.Snackbar, this.finalLuaCode.ToString()),
#endif
DisabledActionParam = () => this.finalLuaCode.Length == 0,
},
];
@@ -368,10 +376,71 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
{
this.finalLuaCode.Clear();
LuaTable.Create(ref this.finalLuaCode, "UI_TEXT_CONTENT", this.localizedContent, commentContent, this.cancellationTokenSource!.Token);
// Next, we must remove the `root::` prefix from the keys:
this.finalLuaCode.Replace("""UI_TEXT_CONTENT["root::""", """
UI_TEXT_CONTENT["
""");
}
#if DEBUG
private async Task WriteToPluginFile()
{
if (this.selectedLanguagePlugin is null)
{
this.Snackbar.Add(T("No language plugin selected."), Severity.Error);
return;
}
if (this.finalLuaCode.Length == 0)
{
this.Snackbar.Add(T("No Lua code generated yet."), Severity.Error);
return;
}
try
{
// Determine the plugin file path based on the selected language plugin:
var pluginDirectory = Path.Join(Environment.CurrentDirectory, "Plugins", "languages");
var pluginId = this.selectedLanguagePluginId.ToString();
var ietfTag = this.selectedLanguagePlugin.IETFTag.ToLowerInvariant();
var pluginFolderName = $"{ietfTag}-{pluginId}";
var pluginFilePath = Path.Join(pluginDirectory, pluginFolderName, "plugin.lua");
if (!File.Exists(pluginFilePath))
{
this.Logger.LogError("Plugin file not found: {PluginFilePath}.", pluginFilePath);
this.Snackbar.Add(T("Plugin file not found."), Severity.Error);
return;
}
// Read the existing plugin file:
var existingContent = await File.ReadAllTextAsync(pluginFilePath);
// Find the position of "UI_TEXT_CONTENT = {}":
const string MARKER = "UI_TEXT_CONTENT = {}";
var markerIndex = existingContent.IndexOf(MARKER, StringComparison.Ordinal);
if (markerIndex == -1)
{
this.Logger.LogError("Could not find 'UI_TEXT_CONTENT = {{}}' marker in plugin file: {PluginFilePath}", pluginFilePath);
this.Snackbar.Add(T("Could not find 'UI_TEXT_CONTENT = {}' marker in plugin file."), Severity.Error);
return;
}
// Keep everything before the marker and replace everything from the marker onwards:
var metadataSection = existingContent[..markerIndex];
var newContent = metadataSection + this.finalLuaCode;
// Write the updated content back to the file:
await File.WriteAllTextAsync(pluginFilePath, newContent);
this.Snackbar.Add(T("Successfully updated plugin file."), Severity.Success);
}
catch (Exception ex)
{
this.Logger.LogError(ex, "Error writing to plugin file.");
this.Snackbar.Add(T("Error writing to plugin file."), Severity.Error);
}
}
#endif
}
@@ -1042,21 +1042,36 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T1214535771"] = "Rem
-- Added Content ({0} entries)
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T1258080997"] = "Added Content ({0} entries)"
-- No Lua code generated yet.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T1365137848"] = "No Lua code generated yet."
-- Localized Content ({0} entries of {1})
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T1492071634"] = "Localized Content ({0} entries of {1})"
-- Select the language plugin used for comparision.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T1523568309"] = "Select the language plugin used for comparision."
-- Successfully updated plugin file.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T1524590750"] = "Successfully updated plugin file."
-- Was not able to load the language plugin for comparison ({0}). Please select a valid, loaded & running language plugin.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T1893011391"] = "Was not able to load the language plugin for comparison ({0}). Please select a valid, loaded & running language plugin."
-- No language plugin selected.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T237325294"] = "No language plugin selected."
-- Target language
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T237828418"] = "Target language"
-- Write Lua code to language plugin file
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T253827221"] = "Write Lua code to language plugin file"
-- Language plugin used for comparision
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T263317578"] = "Language plugin used for comparision"
-- Plugin file not found.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T2938065913"] = "Plugin file not found."
-- Localize AI Studio & generate the Lua code
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T3055634395"] = "Localize AI Studio & generate the Lua code"
@@ -1087,6 +1102,9 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T453060723"] = "The
-- The selected language plugin for comparison uses the IETF tag '{0}' which does not match the selected target language '{1}'. Please select a valid, loaded & running language plugin which matches the target language.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T458999393"] = "The selected language plugin for comparison uses the IETF tag '{0}' which does not match the selected target language '{1}'. Please select a valid, loaded & running language plugin which matches the target language."
-- Could not find 'UI_TEXT_CONTENT = {}' marker in plugin file.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T628596031"] = "Could not find 'UI_TEXT_CONTENT = {}' marker in plugin file."
-- Please provide a custom language.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T656744944"] = "Please provide a custom language."
@@ -1096,6 +1114,9 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T851515643"] = "Plea
-- Localization
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T897888480"] = "Localization"
-- Error writing to plugin file.
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::I18N::ASSISTANTI18N::T948564909"] = "Error writing to plugin file."
-- Your icon source
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::ICONFINDER::ASSISTANTICONFINDER::T1302165948"] = "Your icon source"