Skip to content

Commit

Permalink
Globalization
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Feb 27, 2021
1 parent 46bd059 commit cbba13a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Avalonia\System.Application.SteamTools.Client.Desktop.Avalonia.csproj"/>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop\System.Application.SteamTools.Client.Desktop.csproj"/>
<ProjectReference Include="..\System.Common.CoreLib\System.Common.CoreLib.csproj"/>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Avalonia\System.Application.SteamTools.Client.Desktop.Avalonia.csproj" />
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop\System.Application.SteamTools.Client.Desktop.csproj" />
<ProjectReference Include="..\System.Common.CoreLib\System.Common.CoreLib.csproj" />
</ItemGroup>

<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`win`)) Or ('$(OS)' == 'Windows_NT' And !$(DefineConstants.Contains(`PUBLISH`))) ">
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Windows\System.Application.SteamTools.Client.Desktop.Windows.csproj"/>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Windows\System.Application.SteamTools.Client.Desktop.Windows.csproj" />
</ItemGroup>

<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`osx`)) Or ('$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true' And !$(DefineConstants.Contains(`PUBLISH`))) ">
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Mac\System.Application.SteamTools.Client.Desktop.Mac.csproj"/>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Mac\System.Application.SteamTools.Client.Desktop.Mac.csproj" />
</ItemGroup>

<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`linux`)) Or ('$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true' And !$(DefineConstants.Contains(`PUBLISH`))) ">
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Linux\System.Application.SteamTools.Client.Desktop.Linux.csproj"/>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Linux\System.Application.SteamTools.Client.Desktop.Linux.csproj" />
</ItemGroup>

<ItemGroup>
Expand All @@ -53,7 +53,7 @@
<AvaloniaResource Include="**\*.xaml">
<SubType>Designer</SubType>
</AvaloniaResource>
<AvaloniaResource Include="Assets\**"/>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>

<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`win`)) Or ('$(OS)' == 'Windows_NT' And !$(DefineConstants.Contains(`PUBLISH`))) ">
Expand Down
20 changes: 12 additions & 8 deletions System.Application.SteamTools.Client.Desktop/UI/Resx/R.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using ReactiveUI;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reactive.Linq;

namespace System.Application.UI.Resx
{
Expand All @@ -14,7 +16,7 @@ public sealed class R : ReactiveObject
public static R Current { get; }

public static readonly IList<KeyValuePair<string, string>> Languages;
public static readonly IList<KeyValuePair<string, string>> SteamLanguages;
public static readonly Dictionary<string, string> SteamLanguages;

public static CultureInfo DefaultCurrentUICulture { get; }

Expand All @@ -25,9 +27,9 @@ static R()
Languages = new Dictionary<string, string>()
{
{ "", "Auto" },
{ "en", "English" },
{ "zh-Hans", "Chinese(Simplified)" },
{ "zh-Hant", "Chinese(Traditional)" },
{ "en", "English" },
{ "ko", "Koreana" },
{ "ja", "Japanese" },
{ "ru", "Russian" },
Expand All @@ -40,7 +42,7 @@ static R()
{ "ko", "koreana" },
{ "ja", "japanese" },
{ "ru", "russian" },
}.ToList();
};
}

static bool IsMatch(CultureInfo cultureInfo, string cultureName)
Expand Down Expand Up @@ -68,18 +70,20 @@ public static void ChangeLanguage(string cultureName)
void ChangeLanguage()
{
if (IsMatch(CultureInfo.CurrentUICulture, cultureName)) return;
CultureInfo.CurrentUICulture = new CultureInfo(cultureName);
AppResources.Culture = CultureInfo.CurrentUICulture;
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(cultureName);
AppResources.Culture = CultureInfo.GetCultureInfo(cultureName);
Current.Res = new AppResources();
Current.RaisePropertyChanged(nameof(Res));
}
MainThreadDesktop.BeginInvokeOnMainThread(ChangeLanguage);
}

R()
public string GetCurrentCultureSteamLanguageName()
{
Res = new AppResources();
return AppResources.Culture == null ? Languages.First().Value : SteamLanguages[AppResources.Culture.Name];
}

public AppResources Res { get; }
//public AppResources Res => new AppResources();
public AppResources Res { get; set; } = new AppResources();
}
}

0 comments on commit cbba13a

Please sign in to comment.