mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-20 12:52:14 +00:00
Fixed I18N implementation
This commit is contained in:
parent
7b606e7a18
commit
0c190a072c
@ -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));
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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,
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user