support for dynamic switching languages
This commit is contained in:
1 parent
7a39b18f0b
commit
95f35c7366
89 files changed
+3697
-549
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,73 @@
|
||||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Collections.Generic"#>
|
||||
<#@ assembly name="$(TargetPath)" #>
|
||||
<#@ import namespace="HandyControlDemo.Properties.Langs" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
var resourceType = typeof(Lang);
|
||||
var propertyNameList = resourceType.GetProperties().Where(item => item.PropertyType == typeof(string)).Select(item => item.Name);
|
||||
var langDic = new Dictionary<string, string>();
|
||||
foreach(var item in propertyNameList)
|
||||
{
|
||||
langDic[item] =
|
||||
@$"/// <summary>
|
||||
/// 查找类似 {Lang.ResourceManager.GetString(item, Lang.Culture)} 的本地化字符串。
|
||||
/// </summary>";
|
||||
}
|
||||
#>
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControlDemo.Properties.Langs
|
||||
{
|
||||
public class LangDecorator : INotifyPropertyChanged
|
||||
{
|
||||
internal static LangDecorator Instance => ResourceHelper.GetResource<LangDecorator>("DemoLangs");
|
||||
|
||||
private static string CultureInfoStr;
|
||||
|
||||
public static CultureInfo Culture
|
||||
{
|
||||
get => Lang.Culture;
|
||||
set
|
||||
{
|
||||
if (value == null) return;
|
||||
if (Equals(CultureInfoStr, value.EnglishName)) return;
|
||||
Lang.Culture = value;
|
||||
CultureInfoStr = value.EnglishName;
|
||||
|
||||
Instance.UpdateLangs();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLangs()
|
||||
{
|
||||
<#foreach(var item in propertyNameList){#>
|
||||
OnPropertyChanged(nameof(<#=item#>));
|
||||
<#}#>
|
||||
}
|
||||
|
||||
<#foreach(var item in propertyNameList){#>
|
||||
<#=langDic[item]#>
|
||||
public string <#=item#> => Lang.<#=item#>;
|
||||
|
||||
<#}#>
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName) =>
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public class LangKeys
|
||||
{
|
||||
<#foreach(var item in propertyNameList){#>
|
||||
<#=langDic[item]#>
|
||||
public static string <#=item#> = nameof(<#=item#>);
|
||||
|
||||
<#}#>
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user