Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<ResourceInclude Source="/Resources/Icons.axaml"/>
<ResourceInclude Source="/Resources/Themes.axaml"/>
</ResourceDictionary.MergedDictionaries>

<ResourceInclude x:Key="en_US" Source="/Resources/Locales/en_US.axaml"/>
<ResourceInclude x:Key="zh_CN" Source="/Resources/Locales/zh_CN.axaml"/>
</ResourceDictionary>
</Application.Resources>

Expand Down
24 changes: 21 additions & 3 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
using System.IO;
using System.Reflection;
using System.Text;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading;

using Avalonia;
using Avalonia.Controls;
Expand Down Expand Up @@ -84,9 +88,23 @@ public static void SendNotification(string context, string message)
public static void SetLocale(string localeKey)
{
var app = Current as App;
var targetLocale = app.Resources[localeKey] as ResourceDictionary;
if (targetLocale == null || targetLocale == app._activeLocale)
{

localeKey = localeKey.Replace("_", "-");

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(localeKey);
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture ;
SourceGit.Resources.Locales.Culture = Thread.CurrentThread.CurrentUICulture;

var locale = new ResourceDictionary();
var res = new Resources.Locales();
var props = typeof(Resources.Locales).GetProperties()
.Where(m=> m.PropertyType == typeof(string))
.ToDictionary(k=> k.Name.Replace("_", "."), v=> v.GetValue(res));
foreach (var prop in props)
locale.Add(prop.Key, prop.Value);

var targetLocale = locale;
if (targetLocale == null || targetLocale == app._activeLocale) {
return;
}

Expand Down
Loading