Skip to content
This repository was archived by the owner on May 29, 2023. It is now read-only.

Commit 0891015

Browse files
committed
多语言支持
1 parent add80ea commit 0891015

18 files changed

+399
-149
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A convenitent and beautiful Windows StikyNotes Application </br></br>
1414
## 2022年新开发目标
1515

1616
1. ~~升级依赖库,用MahApp为主体重构项目UI~~(完成)
17-
2. 支持多语言切换
17+
2. ~~支持多语言切换~~(完成)
1818
3. 支持夜间、日间模式
1919
4. ~~新增列表功能,不需要显示的可以暂时隐藏起来~~(完成)
2020
5. 用web端的markdown文本编辑器或富文本编辑器替换现有WPF的富文本控件(WPF的富文本控件实在是不太行,暂时找不到新方案,欢迎大家提issue交流)
@@ -53,15 +53,15 @@ Support global hotkey.</br></br>
5353

5454
[更新日志](更新日志.md)
5555

56+
## ⚡功能更新 2022年1月24日
57+
58+
1. 支持多语言切换(英语、中文)
59+
5660
## ✔功能修复 2022年1月23日
5761

5862
1. 修复便签列表删除便签时需要打开后再删除的问题
5963

60-
## ⚡功能更新 2022年1月22日
6164

62-
1. 新增便签列表功能、支持暂时不显示的便签隐藏
63-
1. 新增更多主题颜色
64-
1. 界面UI更新,更加扁平化,符合WIN10的审美
6565

6666
## 程序截图
6767

StickyNotes/App.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
<ResourceDictionary Source="Style/Window.xaml" />
1919
<ResourceDictionary Source="Style/Label.xaml" />
2020
<ResourceDictionary Source="Style/Themes/Blue.xaml" />
21+
<!--<ResourceDictionary Source="Style/Languages/Lan-cn.xaml" />-->
22+
<!--<ResourceDictionary Source="Style/Languages/Lan-en.xaml" />-->
23+
2124

22-
2325
<!--<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />-->
2426
<!--<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />-->
2527
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
@@ -31,9 +33,9 @@
3133

3234
</ResourceDictionary.MergedDictionaries>
3335
<vm:ViewModelLocator
34-
xmlns:vm="clr-namespace:StickyNotes.ViewModel"
35-
x:Key="Locator"
36-
d:IsDataSource="True" />
36+
xmlns:vm="clr-namespace:StickyNotes.ViewModel"
37+
x:Key="Locator"
38+
d:IsDataSource="True" />
3739
<ContextMenu x:Key="NotifyIconMenu" StaysOpen="False">
3840
<MenuItem
3941
Name="MenuOpen"

StickyNotes/App.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ protected override void OnStartup(StartupEventArgs e)
5252
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
5353
//Messenger.Default.Register<SaveMessage>(this, SaveDataMessage);
5454
var systemtray = SystemTray.Instance;
55-
5655
var programData = XMLHelper.DecodeXML<ProgramData>(ConstData.SaveSettingDataName);
56+
LanguageManager.ChangeLanguage(programData.Language);
57+
5758
if (programData != null)
5859
{
5960
var windowsDatas = programData.Datas;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Data;
8+
9+
namespace StickyNotes
10+
{
11+
internal class LanguageConverter : IValueConverter
12+
{
13+
/// <summary>
14+
/// 从DataContext中的数据转换到View中的数据
15+
/// </summary>
16+
/// <param name="value"></param>
17+
/// <param name="targetType"></param>
18+
/// <param name="parameter"></param>
19+
/// <param name="culture"></param>
20+
/// <returns></returns>
21+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
22+
{
23+
string result = value.ToString();
24+
return result;
25+
}
26+
/// <summary>
27+
/// 不需要这个
28+
/// </summary>
29+
/// <param name="value"></param>
30+
/// <param name="targetType"></param>
31+
/// <param name="parameter"></param>
32+
/// <param name="culture"></param>
33+
/// <returns></returns>
34+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
35+
{
36+
throw new Exception("不需要转换语言,只允许单向绑定");
37+
}
38+
}
39+
}

StickyNotes/Converter/ThemeConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace StickyNotes
1111
public class ThemeConverter:IValueConverter
1212
{
1313
/// <summary>
14-
/// 从DataContent中的数据转换到View中的数据
14+
/// 从DataContext中的数据转换到View中的数据
1515
/// </summary>
1616
/// <param name="value">DataContent中的数据</param>
1717
/// <param name="targetType"></param>

StickyNotes/Data/ProgramData.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using GalaSoft.MvvmLight.Messaging;
22
using StickyNotes.Annotations;
3+
using StickyNotes.Utils;
34
using StickyNotes.Utils.HotKeyUtil;
45
using System;
56
using System.Collections.ObjectModel;
@@ -14,8 +15,10 @@ public class ProgramData : INotifyPropertyChanged
1415
public ObservableCollection<WindowsData> Datas { get; set; }
1516
public ObservableCollection<WindowsData> HideWindowData { get; set; }
1617

17-
18-
18+
/// <summary>
19+
/// 系统语言
20+
/// </summary>
21+
public Language Language { get; set; }
1922
/// <summary>
2023
/// 窗体是否置顶
2124
/// </summary>
@@ -64,6 +67,7 @@ private ProgramData()
6467
IsAutoCheckUpdate = true;
6568
Datas.CollectionChanged += Datas_CollectionChanged;
6669
BaseTheme = "Light";
70+
Language = Language.English;
6771
CurrentTheme = "Blue";
6872
ShowAllHotKey = new HotKeyModel()
6973
{ IsSelectAlt = false, IsSelectCtrl = true, IsSelectShift = false, IsUsable = true, SelectKey = EKey.Q, Name = EHotKeySetting.ShowAllWindow.ToString() };

StickyNotes/Properties/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StickyNotes/Properties/Resources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<data name="Version" xml:space="preserve">
121-
<value>v4.6.1</value>
121+
<value>v4.7.1</value>
122122
<comment>程序版本</comment>
123123
</data>
124124
</root>

StickyNotes/StickyNotes.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
</ApplicationDefinition>
105105
<Compile Include="Converter\boolToVisibilityConverter.cs" />
106106
<Compile Include="Converter\DeleteWindowMessageConverter.cs" />
107+
<Compile Include="Converter\LanguageConverter.cs" />
107108
<Compile Include="Converter\ShowAllHotKeyConverter.cs" />
108109
<Compile Include="Converter\ThemeConverter.cs" />
109110
<Compile Include="Data\ConstData.cs" />
@@ -119,6 +120,7 @@
119120
<Compile Include="Utils\HotKeyUtil\HotKeySettingManager.cs" />
120121
<Compile Include="Utils\Logger.cs" />
121122
<Compile Include="Utils\Messages\ChangeWindowMessage.cs" />
123+
<Compile Include="Utils\LanguageManager.cs" />
122124
<Compile Include="Utils\ThemeAssist.cs" />
123125
<Compile Include="Utils\TimerUtil.cs" />
124126
<Compile Include="Utils\WindowHide.cs" />
@@ -141,6 +143,14 @@
141143
<DependentUpon>SettingWindow.xaml</DependentUpon>
142144
</Compile>
143145
<Compile Include="ViewModel\ViewModelLocator.cs" />
146+
<Page Include="Style\Languages\Lan-en.xaml">
147+
<Generator>MSBuild:Compile</Generator>
148+
<SubType>Designer</SubType>
149+
</Page>
150+
<Page Include="Style\Languages\Lan-cn.xaml">
151+
<SubType>Designer</SubType>
152+
<Generator>MSBuild:Compile</Generator>
153+
</Page>
144154
<Page Include="Style\Themes\Blue.xaml">
145155
<SubType>Designer</SubType>
146156
<Generator>MSBuild:Compile</Generator>
@@ -308,5 +318,6 @@
308318
<Version>2.6.0</Version>
309319
</PackageReference>
310320
</ItemGroup>
321+
<ItemGroup />
311322
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
312323
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<ResourceDictionary
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:sys="clr-namespace:System;assembly=mscorlib">
5+
<sys:String x:Key="menuList">笔记列表</sys:String>
6+
<sys:String x:Key="menuSetting">设置</sys:String>
7+
<sys:String x:Key="menuAbout">关于</sys:String>
8+
<sys:String x:Key="setting-AllWindowTop">所有窗体置顶</sys:String>
9+
<sys:String x:Key="setting-AutoStartUp">开机自启动</sys:String>
10+
<sys:String x:Key="setting-AutoCheckUpdate">自动检查更新</sys:String>
11+
<sys:String x:Key="setting-Theme">主题颜色</sys:String>
12+
<sys:String x:Key="setting-ShortCut">快捷键</sys:String>
13+
<sys:String x:Key="setting-ShortCutExplain">显示/隐藏所有便签</sys:String>
14+
15+
<sys:String x:Key="about-about">关于</sys:String>
16+
<sys:String x:Key="about-projectAddress">项目地址</sys:String>
17+
<sys:String x:Key="about-githubLabel">Github地址</sys:String>
18+
<sys:String x:Key="about-versionInfo">版本信息:</sys:String>
19+
<sys:String x:Key="about-aboutContent">使用过程中出现什么BUG或者好的建议,欢迎在github上提建议</sys:String>
20+
<sys:String x:Key="about-addressContent">后续更新都会在上面的地址中发布,好用的话欢迎点个Star~</sys:String>
21+
22+
23+
<sys:String x:Key="tooltip-addNote">新增便签</sys:String>
24+
<sys:String x:Key="tooltip-menu">菜单</sys:String>
25+
<sys:String x:Key="tooltip-delNote">删除便签</sys:String>
26+
<sys:String x:Key="tooltip-hideNote">隐藏便签</sys:String>
27+
<sys:String x:Key="main-confirmDelLabel">是否删除当前便签?</sys:String>
28+
<sys:String x:Key="main-confirm">确定</sys:String>
29+
<sys:String x:Key="main-cancel">取消</sys:String>
30+
<sys:String x:Key="main-warnning">警告</sys:String>
31+
32+
<sys:String x:Key="setting-Language">语言</sys:String>
33+
34+
35+
</ResourceDictionary>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<ResourceDictionary
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:sys="clr-namespace:System;assembly=mscorlib">
5+
<sys:String x:Key="menuList">Note List</sys:String>
6+
<sys:String x:Key="menuSetting">Setting</sys:String>
7+
<sys:String x:Key="menuAbout">About</sys:String>
8+
<sys:String x:Key="setting-AllWindowTop">All Notes TopMost</sys:String>
9+
<sys:String x:Key="setting-AutoStartUp">Auto Startup</sys:String>
10+
<sys:String x:Key="setting-AutoCheckUpdate">Auto Check Update</sys:String>
11+
<sys:String x:Key="setting-Theme">Theme</sys:String>
12+
<sys:String x:Key="setting-ShortCut">Shortcut</sys:String>
13+
<sys:String x:Key="setting-ShortCutExplain">Show/Hidden All Notes</sys:String>
14+
15+
<sys:String x:Key="about-about">About</sys:String>
16+
<sys:String x:Key="about-projectAddress">Project Address</sys:String>
17+
<sys:String x:Key="about-githubLabel">Github Address</sys:String>
18+
<sys:String x:Key="about-versionInfo">Version :</sys:String>
19+
<sys:String x:Key="about-aboutContent">If there are any bugs or good suggestions during use, please let me know on github</sys:String>
20+
<sys:String x:Key="about-addressContent">Subsequent updates will be released at the above address. If it is useful, please give me a star~</sys:String>
21+
22+
<sys:String x:Key="tooltip-addNote">add note</sys:String>
23+
<sys:String x:Key="tooltip-menu">menu</sys:String>
24+
25+
<sys:String x:Key="tooltip-delNote">delete note</sys:String>
26+
<sys:String x:Key="tooltip-hideNote">hide note</sys:String>
27+
<sys:String x:Key="main-confirmDelLabel">Are you sure you to delete?</sys:String>
28+
<sys:String x:Key="main-confirm">Yes</sys:String>
29+
<sys:String x:Key="main-cancel">Cancel</sys:String>
30+
<sys:String x:Key="main-warnning">Warning</sys:String>
31+
32+
<sys:String x:Key="setting-Language">Language</sys:String>
33+
34+
35+
36+
37+
</ResourceDictionary>

StickyNotes/Utils/LanguageManager.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
8+
namespace StickyNotes.Utils
9+
{
10+
public enum Language{
11+
Chinese,
12+
English
13+
}
14+
public class LanguageManager
15+
{
16+
private const string _resourceStrFomart = "pack://application:,,,/Style/Languages/Lan-{0}.xaml";
17+
public static string Translate(string key)
18+
{
19+
return Application.Current.FindResource(key).ToString();
20+
}
21+
22+
public static void ChangeLanguage(Language lan)
23+
{
24+
switch (lan)
25+
{
26+
case Language.Chinese:
27+
RemoveCurLan();
28+
AddResource(string.Format(_resourceStrFomart, "cn"));
29+
break;
30+
case Language.English:
31+
default:
32+
RemoveCurLan();
33+
AddResource(string.Format(_resourceStrFomart, "en"));
34+
break;
35+
36+
}
37+
}
38+
39+
private static void AddResource(string uri)
40+
{
41+
var dictionaries=Application.Current.Resources.MergedDictionaries;
42+
foreach (var item in dictionaries)
43+
{
44+
if (item?.Source?.OriginalString == uri)
45+
return;
46+
}
47+
ResourceDictionary resourceDictionary = new ResourceDictionary()
48+
{
49+
Source = new Uri(uri,UriKind.Absolute)
50+
};
51+
dictionaries.Add(resourceDictionary);
52+
53+
}
54+
private static void RemoveCurLan()
55+
{
56+
var dictionaries = Application.Current.Resources.MergedDictionaries;
57+
foreach (var item in dictionaries)
58+
{
59+
if (item == null || item.Source == null || item.Source.OriginalString == null)
60+
continue;
61+
if ((bool)(item?.Source?.OriginalString?.Contains("Style/Languages")))
62+
{
63+
dictionaries.Remove(item);
64+
break;
65+
}
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)