Skip to content

Commit 47b6a89

Browse files
Add German localization (#430)
1 parent 2494ee2 commit 47b6a89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3392
-260
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Things we are currently working on:
3333
- [x] ~~Added hot-reload support for plugins ([PR #377](https://github.com/MindWorkAI/AI-Studio/pull/377), [PR #391](https://github.com/MindWorkAI/AI-Studio/pull/391))~~
3434
- [ ] Add support for other languages (I18N) to AI Studio (~~[PR #381](https://github.com/MindWorkAI/AI-Studio/pull/381), [PR #400](https://github.com/MindWorkAI/AI-Studio/pull/400), [PR #404](https://github.com/MindWorkAI/AI-Studio/pull/404), [PR #429](https://github.com/MindWorkAI/AI-Studio/pull/429))~~
3535
- [x] ~~Add an I18N assistant to translate all AI Studio texts to a certain language & culture ([PR #422](https://github.com/MindWorkAI/AI-Studio/pull/422))~~
36-
- [ ] Provide MindWork AI Studio in German ([#31](https://github.com/MindWorkAI/Planning/issues/31))
36+
- [ ] Provide MindWork AI Studio in German ([PR #430](https://github.com/MindWorkAI/AI-Studio/pull/430))
3737
- [ ] Add configuration plugins, which allow pre-defining some LLM providers in organizations
3838
- [ ] Add an app store for plugins, showcasing community-contributed plugins from public GitHub and GitLab repositories. This will enable AI Studio users to discover, install, and update plugins directly within the platform.
3939
- [ ] Add assistant plugins

app/Build/Commands/CollectI18NKeysCommand.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,48 @@ private string ExportToLuaAssignments(Dictionary<string, string> keyValuePairs)
133133

134134
private List<string> FindAllTextTags(ReadOnlySpan<char> fileContent)
135135
{
136-
const string START_TAG = """
136+
const string START_TAG1 = """
137137
T("
138138
""";
139139

140+
const string START_TAG2 = """
141+
TB("
142+
""";
143+
140144
const string END_TAG = """
141145
")
142146
""";
143147

148+
(int Index, int Len) FindNextStart(ReadOnlySpan<char> content)
149+
{
150+
var startIdx1 = content.IndexOf(START_TAG1);
151+
var startIdx2 = content.IndexOf(START_TAG2);
152+
153+
if (startIdx1 == -1 && startIdx2 == -1)
154+
return (-1, 0);
155+
156+
if (startIdx1 == -1)
157+
return (startIdx2, START_TAG2.Length);
158+
159+
if (startIdx2 == -1)
160+
return (startIdx1, START_TAG1.Length);
161+
162+
if (startIdx1 < startIdx2)
163+
return (startIdx1, START_TAG1.Length);
164+
165+
return (startIdx2, START_TAG2.Length);
166+
}
167+
144168
var matches = new List<string>();
145-
var startIdx = fileContent.IndexOf(START_TAG);
169+
var startIdx = FindNextStart(fileContent);
146170
var content = fileContent;
147-
while (startIdx > -1)
171+
while (startIdx.Index > -1)
148172
{
149173
//
150174
// In some cases, after the initial " there follow more " characters.
151175
// We need to skip them:
152176
//
153-
content = content[(startIdx + START_TAG.Length)..];
177+
content = content[(startIdx.Index + startIdx.Len)..];
154178
while(content[0] == '"')
155179
content = content[1..];
156180

@@ -163,7 +187,7 @@ private List<string> FindAllTextTags(ReadOnlySpan<char> fileContent)
163187
match = match[..^1];
164188

165189
matches.Add(match.ToString());
166-
startIdx = content.IndexOf(START_TAG);
190+
startIdx = FindNextStart(content);
167191
}
168192

169193
return matches;

app/MindWork AI Studio.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OS/@EntryIndexedValue">OS</s:String>
1212
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RAG/@EntryIndexedValue">RAG</s:String>
1313
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RID/@EntryIndexedValue">RID</s:String>
14+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TB/@EntryIndexedValue">TB</s:String>
1415
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UI/@EntryIndexedValue">UI</s:String>
1516
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=URL/@EntryIndexedValue">URL</s:String>
1617
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=I18N/@EntryIndexedValue">I18N</s:String>

app/MindWork AI Studio/Assistants/AssistantBase.razor

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</MudButton>
3535
@if (this.isProcessing && this.cancellationTokenSource is not null)
3636
{
37-
<MudTooltip Text="Stop generation">
37+
<MudTooltip Text="@TB("Stop generation")">
3838
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Filled.Stop" Color="Color.Error" OnClick="() => this.CancelStreaming()"/>
3939
</MudTooltip>
4040
}
@@ -80,7 +80,7 @@
8080
{
8181
@if (this.ShowSendTo)
8282
{
83-
<MudMenu AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="Send to ..." Variant="Variant.Filled" Style="@this.GetSendToColor()" Class="rounded">
83+
<MudMenu AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="@TB("Send to ...")" Variant="Variant.Filled" Style="@this.GetSendToColor()" Class="rounded">
8484
@foreach (var assistant in Enum.GetValues<Components>().Where(n => n.AllowSendTo()).OrderBy(n => n.Name().Length))
8585
{
8686
<MudMenuItem OnClick="() => this.SendToAssistant(assistant, new())">
@@ -110,7 +110,7 @@
110110
break;
111111

112112
case SendToButton sendToButton:
113-
<MudMenu AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="Send to ..." Variant="Variant.Filled" Style="@this.GetSendToColor()" Class="rounded">
113+
<MudMenu AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.BottomLeft" StartIcon="@Icons.Material.Filled.Apps" EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="@TB("Send to ...")" Variant="Variant.Filled" Style="@this.GetSendToColor()" Class="rounded">
114114
@foreach (var assistant in Enum.GetValues<Components>().Where(n => n.AllowSendTo()).OrderBy(n => n.Name().Length))
115115
{
116116
<MudMenuItem OnClick="() => this.SendToAssistant(assistant, sendToButton)">
@@ -125,14 +125,14 @@
125125
@if (this.ShowCopyResult)
126126
{
127127
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.ContentCopy" OnClick="() => this.CopyToClipboard()">
128-
Copy result
128+
@TB("Copy result")
129129
</MudButton>
130130
}
131131

132132
@if (this.ShowReset)
133133
{
134134
<MudButton Variant="Variant.Filled" Style="@this.GetResetColor()" StartIcon="@Icons.Material.Filled.Refresh" OnClick="() => this.InnerResetForm()">
135-
Reset
135+
@TB("Reset")
136136
</MudButton>
137137
}
138138

app/MindWork AI Studio/Assistants/AssistantBase.razor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
103103

104104
protected override async Task OnInitializedAsync()
105105
{
106+
await base.OnInitializedAsync();
107+
106108
this.formChangeTimer.AutoReset = false;
107109
this.formChangeTimer.Elapsed += async (_, _) =>
108110
{
@@ -113,7 +115,6 @@ protected override async Task OnInitializedAsync()
113115
this.MightPreselectValues();
114116
this.providerSettings = this.SettingsManager.GetPreselectedProvider(this.Component);
115117
this.currentProfile = this.SettingsManager.GetPreselectedProfile(this.Component);
116-
await base.OnInitializedAsync();
117118
}
118119

119120
protected override async Task OnParametersSetAsync()
@@ -136,6 +137,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
136137

137138
#endregion
138139

140+
private string TB(string fallbackEN) => this.T(fallbackEN, typeof(AssistantBase<TSettings>).Namespace, nameof(AssistantBase<TSettings>));
141+
139142
private string SubmitButtonStyle => this.SettingsManager.ConfigurationData.LLMProviders.ShowProviderConfidence ? this.providerSettings.UsedLLMProvider.GetConfidence(this.SettingsManager).StyleBorder(this.SettingsManager) : string.Empty;
140143

141144
protected string? ValidatingProvider(AIStudio.Settings.Provider provider)

app/MindWork AI Studio/Assistants/I18N/AssistantI18N.razor.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,23 @@ private async Task LocalizeTextContent()
306306
if(this.cancellationTokenSource!.IsCancellationRequested)
307307
return;
308308

309-
// Phase 2: Create the Lua code
310-
this.Phase2CreateLuaCode();
309+
//
310+
// Phase 2: Create the Lua code. We want to use the base language
311+
// for the comments, though:
312+
//
313+
var commentContent = new Dictionary<string, string>(this.addedContent);
314+
foreach (var keyValuePair in PluginFactory.BaseLanguage.Content)
315+
{
316+
if (this.cancellationTokenSource!.IsCancellationRequested)
317+
break;
318+
319+
if (this.removedContent.ContainsKey(keyValuePair.Key))
320+
continue;
321+
322+
commentContent.TryAdd(keyValuePair.Key, keyValuePair.Value);
323+
}
324+
325+
this.Phase2CreateLuaCode(commentContent);
311326
}
312327

313328
private async Task Phase1TranslateAddedContent()
@@ -346,10 +361,9 @@ private async Task Phase1TranslateAddedContent()
346361
}
347362
}
348363

349-
private void Phase2CreateLuaCode()
364+
private void Phase2CreateLuaCode(IReadOnlyDictionary<string, string> commentContent)
350365
{
351366
this.finalLuaCode.Clear();
352-
var commentContent = this.addedContent.Concat(PluginFactory.BaseLanguage.Content).ToDictionary();
353367
LuaTable.Create(ref this.finalLuaCode, "UI_TEXT_CONTENT", this.localizedContent, commentContent, this.cancellationTokenSource!.Token);
354368

355369
// Next, we must remove the `root::` prefix from the keys:

0 commit comments

Comments
 (0)