mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
update: localizations
* fix Locales.Designer.cs NOT updated when compile after Locale.*.resx changed in Visual Studio 2022. * use PublicResXFileCodeGenerator instead of ResXFileCodeGenerator to make sure access modifier is 'public' in Visual Studio 2022. * use ResourceManager.GetResourceSet instead of collecting properties by reflection. * remove translation warnings in Visual Studio's ResXManager extension.
This commit is contained in:
parent
5567a8bc08
commit
44c141be7c
6 changed files with 3885 additions and 1557 deletions
|
@ -1,10 +1,9 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
|
@ -87,24 +86,18 @@ namespace SourceGit
|
|||
public static void SetLocale(string localeKey)
|
||||
{
|
||||
var app = Current as App;
|
||||
var rd = new ResourceDictionary();
|
||||
|
||||
localeKey = localeKey.Replace("_", "-");
|
||||
var culture = CultureInfo.GetCultureInfo(localeKey.Replace("_", "-"));
|
||||
SourceGit.Resources.Locales.Culture = culture;
|
||||
|
||||
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;
|
||||
var sets = SourceGit.Resources.Locales.ResourceManager.GetResourceSet(culture, true, true);
|
||||
foreach (var obj in sets)
|
||||
{
|
||||
if (obj is DictionaryEntry entry)
|
||||
{
|
||||
rd.Add(entry.Key, entry.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (app._activeLocale != null)
|
||||
|
@ -112,8 +105,8 @@ namespace SourceGit
|
|||
app.Resources.MergedDictionaries.Remove(app._activeLocale);
|
||||
}
|
||||
|
||||
app.Resources.MergedDictionaries.Add(targetLocale);
|
||||
app._activeLocale = targetLocale;
|
||||
app.Resources.MergedDictionaries.Add(rd);
|
||||
app._activeLocale = rd;
|
||||
}
|
||||
|
||||
public static void SetTheme(string theme)
|
||||
|
|
16
src/Resources/Locales.Designer.cs
generated
16
src/Resources/Locales.Designer.cs
generated
|
@ -1,6 +1,7 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
|
@ -18,7 +19,7 @@ namespace SourceGit.Resources {
|
|||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
public class Locales {
|
||||
|
@ -28,7 +29,7 @@ namespace SourceGit.Resources {
|
|||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
public Locales() {
|
||||
internal Locales() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -924,7 +925,7 @@ namespace SourceGit.Resources {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Conflict detected! Press 'Abort' to restore original HEAD.
|
||||
/// Looks up a localized string similar to Conflict detected! Press 'Abort' to restore original HEAD..
|
||||
/// </summary>
|
||||
public static string Text_Conflict_Tip {
|
||||
get {
|
||||
|
@ -3200,15 +3201,6 @@ namespace SourceGit.Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Save File to ....
|
||||
/// </summary>
|
||||
public static string Text_SaveFileTo {
|
||||
get {
|
||||
return ResourceManager.GetString("Text.SaveFileTo", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Squash HEAD Into Parent.
|
||||
/// </summary>
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -29,6 +29,22 @@
|
|||
<AvaloniaResource Include="Resources/Fonts/*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Resources/Locales.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Locales.resx</DependentUpon>
|
||||
</Compile>
|
||||
<EmbeddedResource Update="Resources/Locales.resx">
|
||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Locales.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Update="Resources/Locales.*.resx">
|
||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||
<DependentUpon>Locales.resx</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.0.10" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.10" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
|
||||
|
@ -46,12 +62,4 @@
|
|||
<TrimmerRootAssembly Include="SourceGit" />
|
||||
<TrimmerRootAssembly Include="Avalonia.Themes.Fluent" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Resources\Locales.*.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<DependentUpon>Locales.resx</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Loading…
Reference in a new issue