[FancyZones] Localize strings in FancyZones editor (#6943)

* Localize strings in FancyZones editor

* Move localized strings into resx file
This commit is contained in:
vldmr11080
2020-10-05 12:06:35 +02:00
committed by GitHub
parent 4feb0f209f
commit 71765238b1
4 changed files with 81 additions and 19 deletions

View File

@@ -21,6 +21,26 @@ namespace FancyZonesEditor
/// </summary>
public partial class App : Application
{
// Non-localizable strings
private const string CrashReportLogFile = "FZEditorCrashLog.txt";
private const string PowerToysIssuesURL = "https://aka.ms/powerToysReportBug";
private const string CrashReportExceptionTag = "Exception";
private const string CrashReportSourceTag = "Source: ";
private const string CrashReportTargetAssemblyTag = "TargetAssembly: ";
private const string CrashReportTargetModuleTag = "TargetModule: ";
private const string CrashReportTargetSiteTag = "TargetSite: ";
private const string CrashReportEnvironmentTag = "Environment";
private const string CrashReportCommandLineTag = "* Command Line: ";
private const string CrashReportTimestampTag = "* Timestamp: ";
private const string CrashReportOSVersionTag = "* OS Version: ";
private const string CrashReportIntPtrLengthTag = "* IntPtr Length: ";
private const string CrashReportx64Tag = "* x64: ";
private const string CrashReportCLRVersionTag = "* CLR Version: ";
private const string CrashReportAssembliesTag = "Assemblies - ";
private const string CrashReportDynamicAssemblyTag = "dynamic assembly doesn't have location";
private const string CrashReportLocationNullTag = "location is null or empty";
public Settings ZoneSettings { get; }
public App()
@@ -76,18 +96,24 @@ namespace FancyZonesEditor
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs args)
{
var fileStream = File.OpenWrite("FZEditorCrashLog.txt");
var fileStream = File.OpenWrite(CrashReportLogFile);
var sw = new StreamWriter(fileStream);
sw.Write(FormatException((Exception)args.ExceptionObject));
fileStream.Close();
MessageBox.Show("Error logged to " + Path.GetFullPath(fileStream.Name) + "\nPlease report the bug to https://aka.ms/powerToysReportBug", "FancyZones Editor Error");
MessageBox.Show(
FancyZonesEditor.Properties.Resources.Crash_Report_Message_Box_Text_Part1 +
Path.GetFullPath(fileStream.Name) +
"\n" +
FancyZonesEditor.Properties.Resources.Crash_Report_Message_Box_Text_Part2 +
PowerToysIssuesURL,
FancyZonesEditor.Properties.Resources.Fancy_Zones_Editor_App_Title);
}
private string FormatException(Exception ex)
{
var sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("## Exception");
sb.AppendLine("## " + CrashReportExceptionTag);
sb.AppendLine();
sb.AppendLine("```");
@@ -101,17 +127,17 @@ namespace FancyZonesEditor
exsb.AppendLine(ex.Message);
if (ex.Source != null)
{
exsb.Append(" Source: ");
exsb.Append(" " + CrashReportSourceTag);
exsb.AppendLine(ex.Source);
}
if (ex.TargetSite != null)
{
exsb.Append(" TargetAssembly: ");
exsb.Append(" " + CrashReportTargetAssemblyTag);
exsb.AppendLine(ex.TargetSite.Module.Assembly.ToString());
exsb.Append(" TargetModule: ");
exsb.Append(" " + CrashReportTargetModuleTag);
exsb.AppendLine(ex.TargetSite.Module.ToString());
exsb.Append(" TargetSite: ");
exsb.Append(" " + CrashReportTargetSiteTag);
exsb.AppendLine(ex.TargetSite.ToString());
}
@@ -129,14 +155,14 @@ namespace FancyZonesEditor
sb.AppendLine("```");
sb.AppendLine();
sb.AppendLine("## Environment");
sb.AppendLine($"* Command Line: {Environment.CommandLine}");
sb.AppendLine($"* Timestamp: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}");
sb.AppendLine($"* OS Version: {Environment.OSVersion.VersionString}");
sb.AppendLine($"* IntPtr Length: {IntPtr.Size}");
sb.AppendLine($"* x64: {Environment.Is64BitOperatingSystem}");
sb.AppendLine($"* CLR Version: {Environment.Version}");
sb.AppendLine("## Assemblies - " + AppDomain.CurrentDomain.FriendlyName);
sb.AppendLine("## " + CrashReportEnvironmentTag);
sb.AppendLine(CrashReportCommandLineTag + Environment.CommandLine);
sb.AppendLine(CrashReportTimestampTag + DateTime.Now.ToString(CultureInfo.InvariantCulture));
sb.AppendLine(CrashReportOSVersionTag + Environment.OSVersion.VersionString);
sb.AppendLine(CrashReportIntPtrLengthTag + IntPtr.Size);
sb.AppendLine(CrashReportx64Tag + Environment.Is64BitOperatingSystem);
sb.AppendLine(CrashReportCLRVersionTag + Environment.Version);
sb.AppendLine("## " + CrashReportAssembliesTag + AppDomain.CurrentDomain.FriendlyName);
sb.AppendLine();
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies().OrderBy(o => o.GlobalAssemblyCache ? 50 : 0))
{
@@ -146,11 +172,11 @@ namespace FancyZonesEditor
if (ass.IsDynamic)
{
sb.Append("dynamic assembly doesn't has location");
sb.Append(CrashReportDynamicAssemblyTag);
}
else if (string.IsNullOrEmpty(ass.Location))
{
sb.Append("location is null or empty");
sb.Append(CrashReportLocationNullTag);
}
else
{

View File

@@ -61,11 +61,11 @@ namespace FancyZonesEditor.Models
private const string PriorityGridJsonTag = "priority-grid";
private const string CustomJsonTag = "custom";
private const string PowerToysIssuesLink = "https://aka.ms/powerToysReportBug";
private const string PowerToysIssuesURL = "https://aka.ms/powerToysReportBug";
public static void ShowExceptionMessageBox(string message, Exception exception = null)
{
string fullMessage = ErrorMessageBoxMessage + PowerToysIssuesLink + " \n" + message;
string fullMessage = ErrorMessageBoxMessage + PowerToysIssuesURL + " \n" + message;
if (exception != null)
{
fullMessage += ": " + exception.Message;

View File

@@ -96,6 +96,24 @@ namespace FancyZonesEditor.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Error logged to .
/// </summary>
public static string Crash_Report_Message_Box_Text_Part1 {
get {
return ResourceManager.GetString("Crash_Report_Message_Box_Text_Part1", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Please report the bug to .
/// </summary>
public static string Crash_Report_Message_Box_Text_Part2 {
get {
return ResourceManager.GetString("Crash_Report_Message_Box_Text_Part2", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Custom.
/// </summary>
@@ -141,6 +159,15 @@ namespace FancyZonesEditor.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to FancyZones Editor.
/// </summary>
public static string Fancy_Zones_Editor_App_Title {
get {
return ResourceManager.GetString("Fancy_Zones_Editor_App_Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Name.
/// </summary>

View File

@@ -129,6 +129,12 @@
<data name="Choose_Layout" xml:space="preserve">
<value>Choose your layout for this desktop</value>
</data>
<data name="Crash_Report_Message_Box_Text_Part1" xml:space="preserve">
<value>Error logged to </value>
</data>
<data name="Crash_Report_Message_Box_Text_Part2" xml:space="preserve">
<value>Please report the bug to </value>
</data>
<data name="Custom" xml:space="preserve">
<value>Custom</value>
</data>
@@ -144,6 +150,9 @@
<data name="Edit_Selected_Layout" xml:space="preserve">
<value>Edit selected layout</value>
</data>
<data name="Fancy_Zones_Editor_App_Title" xml:space="preserve">
<value>FancyZones Editor</value>
</data>
<data name="Name" xml:space="preserve">
<value>Name</value>
</data>