Fixed I18N implementation

This commit is contained in:
Thorsten Sommer 2026-04-14 13:23:14 +02:00
parent 7b606e7a18
commit 0c190a072c
No known key found for this signature in database
GPG Key ID: B0B7E2FC074BF1F5
5 changed files with 14 additions and 10 deletions

View File

@ -180,7 +180,7 @@ public sealed class ContentText : IContent
var modelLoadResult = await provider.GetTextModels(token: token);
if (!modelLoadResult.Success)
{
var userMessage = modelLoadResult.FailureReason.ToUserMessage(TB, provider.InstanceName);
var userMessage = modelLoadResult.FailureReason.ToUserMessage(provider.InstanceName);
if (!string.IsNullOrWhiteSpace(userMessage))
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.CloudOff, userMessage));

View File

@ -287,7 +287,7 @@ public partial class EmbeddingProviderDialog : MSGComponentBase, ISecretId
{
var result = await provider.GetEmbeddingModels(this.dataAPIKey);
if (!result.Success)
this.dataLoadingModelsIssue = result.FailureReason.ToUserMessage(T, provider.InstanceName);
this.dataLoadingModelsIssue = result.FailureReason.ToUserMessage(provider.InstanceName);
// Order descending by ID means that the newest models probably come first:
var orderedModels = result.Models.OrderByDescending(n => n.Id);

View File

@ -314,7 +314,7 @@ public partial class ProviderDialog : MSGComponentBase, ISecretId
{
var result = await provider.GetTextModels(this.dataAPIKey);
if (!result.Success)
this.dataLoadingModelsIssue = result.FailureReason.ToUserMessage(T, provider.InstanceName);
this.dataLoadingModelsIssue = result.FailureReason.ToUserMessage(provider.InstanceName);
// Order descending by ID means that the newest models probably come first:
var orderedModels = result.Models.OrderByDescending(n => n.Id);

View File

@ -302,7 +302,7 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
{
var result = await provider.GetTranscriptionModels(this.dataAPIKey);
if (!result.Success)
this.dataLoadingModelsIssue = result.FailureReason.ToUserMessage(T, provider.InstanceName);
this.dataLoadingModelsIssue = result.FailureReason.ToUserMessage(provider.InstanceName);
// Order descending by ID means that the newest models probably come first:
var orderedModels = result.Models.OrderByDescending(n => n.Id);

View File

@ -1,14 +1,18 @@
using AIStudio.Tools.PluginSystem;
namespace AIStudio.Provider;
public static class ModelLoadFailureReasonExtensions
{
public static string ToUserMessage(this ModelLoadFailureReason failureReason, Func<string, string> translate, string providerName) => failureReason switch
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ModelLoadFailureReasonExtensions).Namespace, nameof(ModelLoadFailureReasonExtensions));
public static string ToUserMessage(this ModelLoadFailureReason failureReason, string providerName) => failureReason switch
{
ModelLoadFailureReason.INVALID_OR_MISSING_API_KEY => string.Format(translate("We could not load models from '{0}'. The API key is probably missing, invalid, or expired."), providerName),
ModelLoadFailureReason.AUTHENTICATION_OR_PERMISSION_ERROR => string.Format(translate("We could not load models from '{0}'. The account or API key does not have the required permissions."), providerName),
ModelLoadFailureReason.PROVIDER_UNAVAILABLE => string.Format(translate("We could not load models from '{0}' because the provider is currently unavailable or could not be reached."), providerName),
ModelLoadFailureReason.INVALID_RESPONSE => string.Format(translate("We could not load models from '{0}' because the provider returned an unexpected response."), providerName),
ModelLoadFailureReason.UNKNOWN => string.Format(translate("We could not load models from '{0}' due to an unknown error."), providerName),
ModelLoadFailureReason.INVALID_OR_MISSING_API_KEY => string.Format(TB("We could not load models from '{0}'. The API key is probably missing, invalid, or expired."), providerName),
ModelLoadFailureReason.AUTHENTICATION_OR_PERMISSION_ERROR => string.Format(TB("We could not load models from '{0}'. The account or API key does not have the required permissions."), providerName),
ModelLoadFailureReason.PROVIDER_UNAVAILABLE => string.Format(TB("We could not load models from '{0}' because the provider is currently unavailable or could not be reached."), providerName),
ModelLoadFailureReason.INVALID_RESPONSE => string.Format(TB("We could not load models from '{0}' because the provider returned an unexpected response."), providerName),
ModelLoadFailureReason.UNKNOWN => string.Format(TB("We could not load models from '{0}' due to an unknown error."), providerName),
_ => string.Empty,
};