Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5f0a1c5

Browse files
Merge pull request #23 from ennerperez/feature/resx
Resx Localization
2 parents 18aaa0a + aa4c7be commit 5f0a1c5

File tree

9 files changed

+5437
-993
lines changed

9 files changed

+5437
-993
lines changed

‎src/App.axaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
<ResourceInclude Source="/Resources/Icons.axaml"/>
1010
<ResourceInclude Source="/Resources/Themes.axaml"/>
1111
</ResourceDictionary.MergedDictionaries>
12-
13-
<ResourceInclude x:Key="en_US" Source="/Resources/Locales/en_US.axaml"/>
14-
<ResourceInclude x:Key="zh_CN" Source="/Resources/Locales/zh_CN.axaml"/>
1512
</ResourceDictionary>
1613
</Application.Resources>
1714

‎src/App.axaml.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
using System.IO;
33
using System.Reflection;
44
using System.Text;
5+
using System.Globalization;
6+
using System.Linq;
7+
using System.Reflection;
8+
using System.Threading;
59

610
using Avalonia;
711
using Avalonia.Controls;
@@ -84,9 +88,23 @@ public static void SendNotification(string context, string message)
8488
public static void SetLocale(string localeKey)
8589
{
8690
var app = Current as App;
87-
var targetLocale = app.Resources[localeKey] as ResourceDictionary;
88-
if (targetLocale == null || targetLocale == app._activeLocale)
89-
{
91+
92+
localeKey = localeKey.Replace("_", "-");
93+
94+
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(localeKey);
95+
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture ;
96+
SourceGit.Resources.Locales.Culture = Thread.CurrentThread.CurrentUICulture;
97+
98+
var locale = new ResourceDictionary();
99+
var res = new Resources.Locales();
100+
var props = typeof(Resources.Locales).GetProperties()
101+
.Where(m=> m.PropertyType == typeof(string))
102+
.ToDictionary(k=> k.Name.Replace("_", "."), v=> v.GetValue(res));
103+
foreach (var prop in props)
104+
locale.Add(prop.Key, prop.Value);
105+
106+
var targetLocale = locale;
107+
if (targetLocale == null || targetLocale == app._activeLocale) {
90108
return;
91109
}
92110

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /