mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 17:59:17 +00:00
eliminate translation doc names when calling GetString()
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
@@ -35,9 +34,7 @@ namespace QuickLook.Plugin.TextViewer
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
viewer.FontFamily =
|
viewer.FontFamily =
|
||||||
new FontFamily(context.GetString(
|
new FontFamily(context.GetString("Editor_FontFamily", failsafe: "Consolas"));
|
||||||
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Translations.config"),
|
|
||||||
"Editor_FontFamily", failsafe: "Consolas"));
|
|
||||||
|
|
||||||
LoadFile(path);
|
LoadFile(path);
|
||||||
}
|
}
|
||||||
|
@@ -36,8 +36,6 @@ namespace QuickLook
|
|||||||
public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location;
|
public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location;
|
||||||
public static readonly string AppPath = Path.GetDirectoryName(AppFullPath);
|
public static readonly string AppPath = Path.GetDirectoryName(AppFullPath);
|
||||||
|
|
||||||
internal static readonly string Translations = Path.Combine(AppPath, @"Translations.config");
|
|
||||||
|
|
||||||
private bool _isFirstInstance;
|
private bool _isFirstInstance;
|
||||||
private Mutex _isRunning;
|
private Mutex _isRunning;
|
||||||
|
|
||||||
@@ -64,7 +62,7 @@ namespace QuickLook
|
|||||||
RemoteCallShowPreview(e);
|
RemoteCallShowPreview(e);
|
||||||
// second instance: duplicate
|
// second instance: duplicate
|
||||||
else
|
else
|
||||||
MessageBox.Show(TranslationHelper.GetString(Translations, "APP_SECOND"));
|
MessageBox.Show(TranslationHelper.GetString("APP_SECOND"));
|
||||||
|
|
||||||
Shutdown();
|
Shutdown();
|
||||||
return;
|
return;
|
||||||
@@ -87,7 +85,7 @@ namespace QuickLook
|
|||||||
TrayIconManager.GetInstance();
|
TrayIconManager.GetInstance();
|
||||||
if (!e.Args.Contains("/autorun") && !IsUWP)
|
if (!e.Args.Contains("/autorun") && !IsUWP)
|
||||||
TrayIconManager.GetInstance()
|
TrayIconManager.GetInstance()
|
||||||
.ShowNotification("", TranslationHelper.GetString(Translations, "APP_START"));
|
.ShowNotification("", TranslationHelper.GetString("APP_START"));
|
||||||
if (e.Args.Contains("/first"))
|
if (e.Args.Contains("/first"))
|
||||||
AutoStartupHelper.CreateAutorunShortcut();
|
AutoStartupHelper.CreateAutorunShortcut();
|
||||||
|
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Xml.XPath;
|
using System.Xml.XPath;
|
||||||
|
|
||||||
namespace QuickLook.Helpers
|
namespace QuickLook.Helpers
|
||||||
@@ -13,8 +15,14 @@ namespace QuickLook.Helpers
|
|||||||
private static readonly Dictionary<string, XPathNavigator> FileCache = new Dictionary<string, XPathNavigator>();
|
private static readonly Dictionary<string, XPathNavigator> FileCache = new Dictionary<string, XPathNavigator>();
|
||||||
private static readonly Dictionary<string, string> StringCache = new Dictionary<string, string>();
|
private static readonly Dictionary<string, string> StringCache = new Dictionary<string, string>();
|
||||||
|
|
||||||
public static string GetString(string file, string id, CultureInfo locale = null, string failsafe = null)
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
public static string GetString(string id, string file = null, CultureInfo locale = null, string failsafe = null,
|
||||||
|
Assembly calling = null)
|
||||||
{
|
{
|
||||||
|
if (file == null)
|
||||||
|
file = Path.Combine(Path.GetDirectoryName((calling ?? Assembly.GetCallingAssembly()).Location),
|
||||||
|
"Translations.config");
|
||||||
|
|
||||||
if (!File.Exists(file))
|
if (!File.Exists(file))
|
||||||
return failsafe ?? id;
|
return failsafe ?? id;
|
||||||
|
|
||||||
@@ -44,7 +52,7 @@ namespace QuickLook.Helpers
|
|||||||
|
|
||||||
private static string GetStringFromXml(XPathNavigator nav, string id, CultureInfo locale)
|
private static string GetStringFromXml(XPathNavigator nav, string id, CultureInfo locale)
|
||||||
{
|
{
|
||||||
var cacheKey = $"{locale.Name}::{id}";
|
var cacheKey = $"{nav.BaseURI.GetHashCode()}::{locale.Name}::{id}";
|
||||||
if (StringCache.ContainsKey(cacheKey))
|
if (StringCache.ContainsKey(cacheKey))
|
||||||
return StringCache[cacheKey];
|
return StringCache[cacheKey];
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ namespace QuickLook.Helpers
|
|||||||
if (!silent)
|
if (!silent)
|
||||||
Application.Current.Dispatcher.Invoke(
|
Application.Current.Dispatcher.Invoke(
|
||||||
() => TrayIconManager.GetInstance().ShowNotification("",
|
() => TrayIconManager.GetInstance().ShowNotification("",
|
||||||
TranslationHelper.GetString(App.Translations, "Update_NoUpdate")));
|
TranslationHelper.GetString("Update_NoUpdate")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ namespace QuickLook.Helpers
|
|||||||
{
|
{
|
||||||
ViewWindowManager.GetInstance().InvokeViewer(changeLogPath);
|
ViewWindowManager.GetInstance().InvokeViewer(changeLogPath);
|
||||||
TrayIconManager.GetInstance().ShowNotification("",
|
TrayIconManager.GetInstance().ShowNotification("",
|
||||||
string.Format(TranslationHelper.GetString(App.Translations, "Update_Found"), nVersion),
|
string.Format(TranslationHelper.GetString("Update_Found"), nVersion),
|
||||||
clickEvent: () => Process.Start(
|
clickEvent: () => Process.Start(
|
||||||
@"https://github.com/xupefei/QuickLook/releases/latest"));
|
@"https://github.com/xupefei/QuickLook/releases/latest"));
|
||||||
});
|
});
|
||||||
@@ -77,7 +77,7 @@ namespace QuickLook.Helpers
|
|||||||
Debug.WriteLine(e.Message);
|
Debug.WriteLine(e.Message);
|
||||||
Application.Current.Dispatcher.Invoke(
|
Application.Current.Dispatcher.Invoke(
|
||||||
() => TrayIconManager.GetInstance().ShowNotification("",
|
() => TrayIconManager.GetInstance().ShowNotification("",
|
||||||
string.Format(TranslationHelper.GetString(App.Translations, "Update_Error"), e.Message)));
|
string.Format(TranslationHelper.GetString("Update_Error"), e.Message)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,7 @@ namespace QuickLook
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
FontFamily =
|
FontFamily =
|
||||||
new FontFamily(TranslationHelper.GetString(App.Translations, "UI_FontFamily", failsafe: "Segoe UI"));
|
new FontFamily(TranslationHelper.GetString("UI_FontFamily", failsafe: "Segoe UI"));
|
||||||
|
|
||||||
SourceInitialized += (sender, e) =>
|
SourceInitialized += (sender, e) =>
|
||||||
{
|
{
|
||||||
@@ -181,13 +181,13 @@ namespace QuickLook
|
|||||||
|
|
||||||
buttonOpenWith.Content = isExe == null
|
buttonOpenWith.Content = isExe == null
|
||||||
? Directory.Exists(PreviewPath)
|
? Directory.Exists(PreviewPath)
|
||||||
? string.Format(TranslationHelper.GetString(App.Translations, "MW_BrowseFolder"),
|
? string.Format(TranslationHelper.GetString("MW_BrowseFolder"),
|
||||||
Path.GetFileName(PreviewPath))
|
Path.GetFileName(PreviewPath))
|
||||||
: string.Format(TranslationHelper.GetString(App.Translations, "MW_Open"),
|
: string.Format(TranslationHelper.GetString("MW_Open"),
|
||||||
Path.GetFileName(PreviewPath))
|
Path.GetFileName(PreviewPath))
|
||||||
: isExe == true
|
: isExe == true
|
||||||
? string.Format(TranslationHelper.GetString(App.Translations, "MW_Run"), appFriendlyName)
|
? string.Format(TranslationHelper.GetString("MW_Run"), appFriendlyName)
|
||||||
: string.Format(TranslationHelper.GetString(App.Translations, "MW_OpenWith"), appFriendlyName);
|
: string.Format(TranslationHelper.GetString("MW_OpenWith"), appFriendlyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void BeginHide()
|
internal void BeginHide()
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using QuickLook.Annotations;
|
using QuickLook.Annotations;
|
||||||
@@ -130,9 +131,10 @@ namespace QuickLook.Plugin
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a string from translation Xml document.
|
/// Get a string from translation Xml document.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetString(string file, string id, CultureInfo locale = null, string failsafe = null)
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
public string GetString(string id, string file = null, CultureInfo locale = null, string failsafe = null)
|
||||||
{
|
{
|
||||||
return TranslationHelper.GetString(file, id, locale, failsafe);
|
return TranslationHelper.GetString(id, file, locale, failsafe, Assembly.GetCallingAssembly());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -62,7 +62,7 @@ namespace QuickLook.Plugin.InfoPanel
|
|||||||
filename.Text = string.IsNullOrEmpty(name) ? path : name;
|
filename.Text = string.IsNullOrEmpty(name) ? path : name;
|
||||||
|
|
||||||
var last = File.GetLastWriteTime(path);
|
var last = File.GetLastWriteTime(path);
|
||||||
modDate.Text = string.Format(TranslationHelper.GetString(App.Translations, "InfoPanel_LastModified"),
|
modDate.Text = string.Format(TranslationHelper.GetString("InfoPanel_LastModified"),
|
||||||
last.ToString(CultureInfo.CurrentCulture));
|
last.ToString(CultureInfo.CurrentCulture));
|
||||||
|
|
||||||
Stop = false;
|
Stop = false;
|
||||||
@@ -85,7 +85,7 @@ namespace QuickLook.Plugin.InfoPanel
|
|||||||
Dispatcher.Invoke(() =>
|
Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
totalSize.Text =
|
totalSize.Text =
|
||||||
string.Format(TranslationHelper.GetString(App.Translations, "InfoPanel_DriveSize"),
|
string.Format(TranslationHelper.GetString("InfoPanel_DriveSize"),
|
||||||
totalSpace.ToPrettySize(2),
|
totalSpace.ToPrettySize(2),
|
||||||
totalFreeSpace.ToPrettySize(2));
|
totalFreeSpace.ToPrettySize(2));
|
||||||
});
|
});
|
||||||
@@ -101,15 +101,15 @@ namespace QuickLook.Plugin.InfoPanel
|
|||||||
string t;
|
string t;
|
||||||
var d = totalDirsL != 0
|
var d = totalDirsL != 0
|
||||||
? string.Format(
|
? string.Format(
|
||||||
TranslationHelper.GetString(App.Translations, "InfoPanel_Folders"), totalDirsL)
|
TranslationHelper.GetString("InfoPanel_Folders"), totalDirsL)
|
||||||
: string.Empty;
|
: string.Empty;
|
||||||
var f = totalFilesL != 0
|
var f = totalFilesL != 0
|
||||||
? string.Format(
|
? string.Format(
|
||||||
TranslationHelper.GetString(App.Translations, "InfoPanel_Files"), totalFilesL)
|
TranslationHelper.GetString("InfoPanel_Files"), totalFilesL)
|
||||||
: string.Empty;
|
: string.Empty;
|
||||||
if (!string.IsNullOrEmpty(d) && !string.IsNullOrEmpty(f))
|
if (!string.IsNullOrEmpty(d) && !string.IsNullOrEmpty(f))
|
||||||
t = string.Format(
|
t = string.Format(
|
||||||
TranslationHelper.GetString(App.Translations, "InfoPanel_FolderAndFile"), d, f);
|
TranslationHelper.GetString("InfoPanel_FolderAndFile"), d, f);
|
||||||
else if (string.IsNullOrEmpty(d) && string.IsNullOrEmpty(f))
|
else if (string.IsNullOrEmpty(d) && string.IsNullOrEmpty(f))
|
||||||
t = string.Empty;
|
t = string.Empty;
|
||||||
else
|
else
|
||||||
|
@@ -29,7 +29,7 @@ namespace QuickLook
|
|||||||
private readonly NotifyIcon _icon;
|
private readonly NotifyIcon _icon;
|
||||||
|
|
||||||
private readonly MenuItem _itemAutorun =
|
private readonly MenuItem _itemAutorun =
|
||||||
new MenuItem(TranslationHelper.GetString(App.Translations, "Icon_RunAtStartup"),
|
new MenuItem(TranslationHelper.GetString("Icon_RunAtStartup"),
|
||||||
(sender, e) =>
|
(sender, e) =>
|
||||||
{
|
{
|
||||||
if (AutoStartupHelper.IsAutorun())
|
if (AutoStartupHelper.IsAutorun())
|
||||||
@@ -42,7 +42,7 @@ namespace QuickLook
|
|||||||
{
|
{
|
||||||
_icon = new NotifyIcon
|
_icon = new NotifyIcon
|
||||||
{
|
{
|
||||||
Text = string.Format(TranslationHelper.GetString(App.Translations, "Icon_ToolTip"),
|
Text = string.Format(TranslationHelper.GetString("Icon_ToolTip"),
|
||||||
Application.ProductVersion),
|
Application.ProductVersion),
|
||||||
Icon = Resources.app,
|
Icon = Resources.app,
|
||||||
Visible = true,
|
Visible = true,
|
||||||
@@ -50,10 +50,10 @@ namespace QuickLook
|
|||||||
{
|
{
|
||||||
new MenuItem($"v{Application.ProductVersion}") {Enabled = false},
|
new MenuItem($"v{Application.ProductVersion}") {Enabled = false},
|
||||||
new MenuItem("-"),
|
new MenuItem("-"),
|
||||||
new MenuItem(TranslationHelper.GetString(App.Translations, "Icon_CheckUpdate"),
|
new MenuItem(TranslationHelper.GetString("Icon_CheckUpdate"),
|
||||||
(sender, e) => Updater.CheckForUpdates()) {Enabled = !App.IsUWP},
|
(sender, e) => Updater.CheckForUpdates()) {Enabled = !App.IsUWP},
|
||||||
_itemAutorun,
|
_itemAutorun,
|
||||||
new MenuItem(TranslationHelper.GetString(App.Translations, "Icon_Quit"),
|
new MenuItem(TranslationHelper.GetString("Icon_Quit"),
|
||||||
(sender, e) => System.Windows.Application.Current.Shutdown())
|
(sender, e) => System.Windows.Application.Current.Shutdown())
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user