mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-12 20:33:48 +00:00
Improved the user language detection, especially for Linux (#663)
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
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:
1 parent
3671444d28
commit
53f657da71
3 files changed
+146
-14
No files matched your search
@@ -172,17 +172,31 @@ public sealed class SettingsManager
|
||||
{
|
||||
case LangBehavior.AUTO:
|
||||
var languageCode = await this.rustService.ReadUserLanguage();
|
||||
var languagePlugin = PluginFactory.RunningPlugins.FirstOrDefault(x => x is ILanguagePlugin langPlug && langPlug.IETFTag == languageCode);
|
||||
if (languagePlugin is null)
|
||||
var languagePlugins = PluginFactory.RunningPlugins.OfType<ILanguagePlugin>().ToList();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(languageCode))
|
||||
{
|
||||
this.logger.LogWarning($"The language plugin for the language '{languageCode}' is not available.");
|
||||
return PluginFactory.BaseLanguage;
|
||||
var exactMatch = languagePlugins.FirstOrDefault(x => string.Equals(x.IETFTag, languageCode, StringComparison.OrdinalIgnoreCase));
|
||||
if (exactMatch is not null)
|
||||
return exactMatch;
|
||||
|
||||
var primaryLanguage = GetPrimaryLanguage(languageCode);
|
||||
if (!string.IsNullOrWhiteSpace(primaryLanguage))
|
||||
{
|
||||
var primaryLanguageMatch = languagePlugins
|
||||
.Where(x => string.Equals(GetPrimaryLanguage(x.IETFTag), primaryLanguage, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(x => x.IETFTag, StringComparer.OrdinalIgnoreCase)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (primaryLanguageMatch is not null)
|
||||
{
|
||||
this.logger.LogWarning($"No exact language plugin found for '{languageCode}'. Use language fallback '{primaryLanguageMatch.IETFTag}'.");
|
||||
return primaryLanguageMatch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (languagePlugin is ILanguagePlugin langPlugin)
|
||||
return langPlugin;
|
||||
|
||||
this.logger.LogError("The language plugin is not a language plugin.");
|
||||
this.logger.LogWarning($"The language plugin for the language '{languageCode}' (normalized='{languageCode}') is not available.");
|
||||
return PluginFactory.BaseLanguage;
|
||||
|
||||
case LangBehavior.MANUAL:
|
||||
@@ -204,6 +218,18 @@ public sealed class SettingsManager
|
||||
this.logger.LogError("The language behavior is unknown.");
|
||||
return PluginFactory.BaseLanguage;
|
||||
}
|
||||
|
||||
private static string GetPrimaryLanguage(string localeTag)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(localeTag))
|
||||
return string.Empty;
|
||||
|
||||
var separatorIndex = localeTag.IndexOf('-');
|
||||
if (separatorIndex < 0)
|
||||
return localeTag;
|
||||
|
||||
return localeTag[..separatorIndex];
|
||||
}
|
||||
|
||||
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
|
||||
public Provider GetPreselectedProvider(Tools.Components component, string? currentProviderId = null, bool usePreselectionBeforeCurrentProvider = false)
|
||||
@@ -365,4 +391,4 @@ public sealed class SettingsManager
|
||||
// Return the full name of the property, including the class name:
|
||||
return $"{typeof(TIn).Name}.{memberExpr.Member.Name}";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user