Skip to content

Commit 7b001c5

Browse files
committed
Add translations and localize DbViewer UI
1 parent ce2bd1d commit 7b001c5

7 files changed

Lines changed: 442 additions & 17 deletions

File tree

‎QuickLook.Plugin/QuickLook.Plugin.DbViewer/DbViewerPanel.xaml.cs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using Microsoft.Data.Sqlite;
33
using Microsoft.Win32;
44
using MiniExcelLibs;
5+
using QuickLook.Common.Helpers;
56
using System;
67
using System.Collections.Generic;
78
using System.Data;
89
using System.IO;
910
using System.Linq;
11+
using System.Reflection;
1012
using System.Windows;
1113
using System.Windows.Controls;
1214

@@ -15,6 +17,7 @@ namespace QuickLook.Plugin.DbViewer;
1517
public partial class DbViewerPanel : UserControl
1618
{
1719
private const int DefaultPageSize = 200;
20+
private static readonly string Domain = Assembly.GetExecutingAssembly().GetName().Name;
1821
private string _path;
1922
private string _sqlitePassword;
2023
private DatabaseType _databaseType;
@@ -62,7 +65,7 @@ public void LoadDatabase(string path, string password = null)
6265
}
6366
else
6467
{
65-
MessageBox.Show("数据库中没有可显示的表或集合");
68+
MessageBox.Show(TranslationHelper.Get("MSG_NoTables", domain: Domain));
6669
}
6770
}
6871

@@ -93,16 +96,16 @@ public void ExportCurrentTableToExcel(string sourcePath)
9396

9497
if (table is null)
9598
{
96-
MessageBox.Show("无法导出数据。", "QuickLook", MessageBoxButton.OK, MessageBoxImage.Warning);
99+
MessageBox.Show(TranslationHelper.Get("MSG_ExportCannotExport", domain: Domain), "QuickLook", MessageBoxButton.OK, MessageBoxImage.Warning);
97100
return;
98101
}
99102

100103
MiniExcel.SaveAs(dialog.FileName, table);
101-
MessageBox.Show($"导出成功:{dialog.FileName}", "QuickLook", MessageBoxButton.OK, MessageBoxImage.Information);
104+
MessageBox.Show(string.Format(TranslationHelper.Get("MSG_ExportSuccess", domain: Domain), dialog.FileName), "QuickLook", MessageBoxButton.OK, MessageBoxImage.Information);
102105
}
103106
catch (Exception ex)
104107
{
105-
MessageBox.Show($"导出失败:{ex.Message}", "QuickLook", MessageBoxButton.OK, MessageBoxImage.Error);
108+
MessageBox.Show(string.Format(TranslationHelper.Get("MSG_ExportError", domain: Domain), ex.Message), "QuickLook", MessageBoxButton.OK, MessageBoxImage.Error);
106109
}
107110
}
108111

‎QuickLook.Plugin/QuickLook.Plugin.DbViewer/Pagination.cs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
using QuickLook.Common.Helpers;
12
using System.Windows;
23
using System.Windows.Controls;
34
using System.Windows.Controls.Primitives;
45
using System.Windows.Input;
5-
using Wpf.Ui.Violeta.Resources.Localization;
66

77
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
88

@@ -97,19 +97,21 @@ public event RoutedPropertyChangedEventHandler<int> CurrentPageChanged
9797
typeof(Pagination),
9898
new PropertyMetadata(false));
9999

100+
private const string Domain = "QuickLook.Plugin.DbViewer";
101+
100102
public static readonly DependencyProperty QuickJumpPrefixTextProperty =
101103
DependencyProperty.Register(
102104
nameof(QuickJumpPrefixText),
103105
typeof(string),
104106
typeof(Pagination),
105-
new PropertyMetadata(SH.PaginationQuickJumpPrefix));
107+
new PropertyMetadata(TranslationHelper.Get("Pagination_GoTo", domain: Domain)));
106108

107109
public static readonly DependencyProperty QuickJumpSuffixTextProperty =
108110
DependencyProperty.Register(
109111
nameof(QuickJumpSuffixText),
110112
typeof(string),
111113
typeof(Pagination),
112-
new PropertyMetadata(SH.PaginationQuickJumpSuffix));
114+
new PropertyMetadata(TranslationHelper.Get("Pagination_Page", domain: Domain)));
113115

114116
public static readonly DependencyProperty ShowPageSizeSelectorProperty =
115117
DependencyProperty.Register(
@@ -220,12 +222,12 @@ public Pagination()
220222
{
221223
if (ReadLocalValue(QuickJumpPrefixTextProperty) == DependencyProperty.UnsetValue)
222224
{
223-
SetCurrentValue(QuickJumpPrefixTextProperty, SH.PaginationQuickJumpPrefix);
225+
SetCurrentValue(QuickJumpPrefixTextProperty, TranslationHelper.Get("Pagination_GoTo", domain: Domain));
224226
}
225227

226228
if (ReadLocalValue(QuickJumpSuffixTextProperty) == DependencyProperty.UnsetValue)
227229
{
228-
SetCurrentValue(QuickJumpSuffixTextProperty, SH.PaginationQuickJumpSuffix);
230+
SetCurrentValue(QuickJumpSuffixTextProperty, TranslationHelper.Get("Pagination_Page", domain: Domain));
229231
}
230232
}
231233

‎QuickLook.Plugin/QuickLook.Plugin.DbViewer/PasswordControl.xaml.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using QuickLook.Common.Helpers;
12
using System;
3+
using System.Reflection;
24
using System.Windows;
35
using System.Windows.Controls;
46

@@ -14,6 +16,13 @@ public PasswordControl()
1416
{
1517
InitializeComponent();
1618

19+
string domain = Assembly.GetExecutingAssembly().GetName().Name;
20+
titleTextBlock.Text = TranslationHelper.Get("PW_Title", domain: domain);
21+
hintTextBlock.Text = TranslationHelper.Get("Pw_Hint", domain: domain);
22+
passwordErrorTextBlock.Text = TranslationHelper.Get("PW_Error", domain: domain);
23+
openButton.Content = TranslationHelper.Get("BTN_Open", domain: domain);
24+
cancelButton.Content = TranslationHelper.Get("BTN_Cancel", domain: domain);
25+
1726
openButton.Click += OpenButton_Click;
1827
cancelButton.Click += CancelButton_Click;
1928
passwordBox.KeyDown += (s, e) =>

‎QuickLook.Plugin/QuickLook.Plugin.DbViewer/Plugin.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using Microsoft.Data.Sqlite;
22
using QuickLook.Common.Commands;
33
using QuickLook.Common.Controls;
4+
using QuickLook.Common.Helpers;
45
using QuickLook.Common.Plugin;
56
using QuickLook.Common.Plugin.MoreMenu;
67
using System;
78
using System.Collections.Generic;
89
using System.IO;
10+
using System.Reflection;
911
using System.Windows;
1012

1113
namespace QuickLook.Plugin.DbViewer;
@@ -155,7 +157,7 @@ private IEnumerable<IMenuItem> GetMenuItems()
155157
new MoreMenuItem
156158
{
157159
Icon = FontSymbols.SaveAs,
158-
Header = "导出为 Excel",
160+
Header = TranslationHelper.Get("MW_ExportToExcel", domain: Assembly.GetExecutingAssembly().GetName().Name),
159161
Command = new RelayCommand(ExportToExcel),
160162
IsVisible = true,
161163
IsEnabled = true,

‎QuickLook.Plugin/QuickLook.Plugin.DbViewer/QuickLook.Plugin.DbViewer.csproj‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
</ProjectReference>
107107
</ItemGroup>
108108

109+
<ItemGroup>
110+
<None Include="Translations.config">
111+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
112+
</None>
113+
</ItemGroup>
114+
109115
<ItemGroup>
110116
<Compile Include="..\..\GitVersion.cs">
111117
<Link>Properties\GitVersion.cs</Link>

‎QuickLook.Plugin/QuickLook.Plugin.DbViewer/SH.cs‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)