Skip to content

Commit

Permalink
[FancyZones] Localize strings in FancyZones editor (#6943)
Browse files Browse the repository at this point in the history
* Localize strings in FancyZones editor

* Move localized strings into resx file
  • Loading branch information
vldmr11080 committed Oct 5, 2020
1 parent 4feb0f2 commit 7176523
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 19 deletions.
60 changes: 43 additions & 17 deletions src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -76,18 +96,24 @@ private void OnStartup(object sender, StartupEventArgs e)

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("```");

Expand All @@ -101,17 +127,17 @@ private string FormatException(Exception ex)
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());
}

Expand All @@ -129,14 +155,14 @@ private string FormatException(Exception ex)
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))
{
Expand All @@ -146,11 +172,11 @@ private string FormatException(Exception ex)

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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public abstract class LayoutModel : INotifyPropertyChanged
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;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit 7176523

Please sign in to comment.