Skip to content

Commit

Permalink
Add ALL languages
Browse files Browse the repository at this point in the history
  • Loading branch information
PGgamer2 committed Apr 29, 2024
1 parent f3fdfaf commit 1b8d32f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 119 deletions.
75 changes: 35 additions & 40 deletions Localization.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
using System.Threading;
using System;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace sethc
{
public class Localization
{
public static void SetLanguage(Main mainForm)
{
// English (Default language)
string sktitle = "Sticky Keys";
string turnsktext = "Do you want to turn on Sticky Keys?";
string skcontenttext = "Sticky Keys lets you use the SHIFT, CTRL, ALT, or Windows Logo keys by pressing one key at a time. The keyboard shortcut to turn on Sticky Keys is to press the SHIFT key 5 times.";
string deactivatesktext = "Go to the Ease of Access Center to disable the keyboard shortcut";
string skyes = "&Yes";
string skno = "&No";
public class Localization
{
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibraryA(string lpLibFileName);
[DllImport("user32.dll")]
private static extern int LoadStringA(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);

switch (Thread.CurrentThread.CurrentCulture.Name)
{
case "it-IT": // Italian
sktitle = "Tasti permanenti";
turnsktext = "Attivare Tasti permanenti?";
skcontenttext = "Tasti permanenti consente di utilizzare combinazioni di tasti con MAIUSC, CTRL, ALT o il tasto logo Windows premendo un tasto alla volta. Per attivare Tasti permanenti, premere MAIUSC cinque volte.";
deactivatesktext = "Disabilita questa scelta rapida da tastiera nelle impostazioni della tastiera di Accesso Rapido";
skyes = "&Sì";
// Italian "No" and English "No" are the same.
break;
case "zh-CN": // Chinese PRC
sktitle = "粘滞键";
turnsktext = "你想启用粘滞键吗?";
skcontenttext = "通过一次按一个键,粘滞键允许使用 Shift、Ctrl、Alt 或 Windows徽标键。启用粘滞键的键盘快捷方式是按 5 次 Shift 键。";
deactivatesktext = "在“轻松使用”键盘设置中禁用此键盘快捷方式";
skyes = "&是(Y)";
skno = "&否(N)";
break;
}
public static string getMUIstring(IntPtr resContainer, uint msgId)
{
StringBuilder pBuffer = new StringBuilder(512);
if (LoadStringA(resContainer, msgId, pBuffer, 512) == 0) {
MessageBox.Show($"Cannot find resource {msgId}.", AppDomain.CurrentDomain.FriendlyName + " - Error interpreting mui file", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return pBuffer.ToString();
}

mainForm.Text = sktitle;
mainForm.labelturnsk.Text = turnsktext;
mainForm.labelskcontent.Text = skcontenttext;
mainForm.labeldeactivatedialog.Text = deactivatesktext;
mainForm.buttonYes.Text = skyes;
mainForm.buttonNo.Text = skno;
mainForm.Refresh();
}
}
public static void SetLanguage(Main mainForm, int windowMode)
{
IntPtr resContainer = LoadLibraryA($"{Environment.GetFolderPath(Environment.SpecialFolder.Windows)}\\System32\\{CultureInfo.InstalledUICulture.Name}\\EaseOfAccessDialog.exe.mui");
if (resContainer == null) {
MessageBox.Show("Cannot read mui file.", AppDomain.CurrentDomain.FriendlyName + " - Error loading mui file", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

mainForm.Text = getMUIstring(resContainer, 512);
mainForm.labelturnsk.Text = getMUIstring(resContainer, 1138);
mainForm.labelskcontent.Text = getMUIstring(resContainer, 1117);
mainForm.labeldeactivatedialog.Text = getMUIstring(resContainer, 1143);
mainForm.buttonYes.Text = getMUIstring(resContainer, 1135);
mainForm.buttonNo.Text = getMUIstring(resContainer, 1134);
mainForm.Refresh();
}
}
}
101 changes: 32 additions & 69 deletions Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
Expand All @@ -8,20 +7,20 @@ namespace sethc
{
public partial class Main : Form
{
public const Int32 SPI_SETSTICKYKEYS = 0x003B;
public const Int32 SPIF_UPDATEINIFILE = 0x01;
public const Int32 SPIF_SENDWININICHANGE = 0x02;
public const UInt32 SKF_STICKYKEYSON = 0x00000001;
public const UInt32 SKF_HOTKEYACTIVE = 0x00000004;
private const Int32 SPI_SETSTICKYKEYS = 0x003B;
private const Int32 SPIF_UPDATEINIFILE = 0x01;
private const Int32 SPIF_SENDWININICHANGE = 0x02;
private const UInt32 SKF_STICKYKEYSON = 0x00000001;
private const UInt32 SKF_HOTKEYACTIVE = 0x00000004;

public const Int32 WM_SYSCOMMAND = 0x112;
public const Int32 MF_BYPOSITION = 0x400;
public const Int32 MF_SEPARATOR = 0x800;
public const Int32 CTXMENU1 = 1000;
public const Int32 CTXMENU2 = 1001;
public const Int32 CTXMENU3 = 1002;
public const Int32 CTXMENU4 = 1003;
public const Int32 CTXMENU5 = 1004;
private const Int32 WM_SYSCOMMAND = 0x112;
private const Int32 MF_BYPOSITION = 0x400;
private const Int32 MF_SEPARATOR = 0x800;
private const Int32 CTXMENU1 = 1000;
private const Int32 CTXMENU2 = 1001;
private const Int32 CTXMENU3 = 1002;
private const Int32 CTXMENU4 = 1003;
private const Int32 CTXMENU5 = 1004;

[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
Expand All @@ -36,31 +35,26 @@ private struct tagSTICKYKEYS
public UInt32 dwFlags;
}

public Main()
public Main(string[] args)
{
InitializeComponent();
Localization.SetLanguage(this, (int.Parse(args[0]) - 211) / 10);
}

protected override void WndProc(ref Message msg)
{
if (msg.Msg == WM_SYSCOMMAND)
{
try
{
switch (msg.WParam.ToInt32())
{
if (msg.Msg == WM_SYSCOMMAND) {
try {
switch (msg.WParam.ToInt32()) {
// Actions for context menu
case CTXMENU1:
Process.Start("cmd.exe");
return;
case CTXMENU2:
try
{
try {
Process.Start("powershell.exe");
}
catch (Exception)
{
MessageBox.Show("PowerShell isn't installed.", AppDomain.CurrentDomain.FriendlyName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
} catch (Exception) {
MessageBox.Show("Cannot start PowerShell.", AppDomain.CurrentDomain.FriendlyName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
return;
case CTXMENU3:
Expand All @@ -75,9 +69,7 @@ protected override void WndProc(ref Message msg)
default:
break;
}
}
catch (Exception error)
{
} catch (Exception error) {
Console.WriteLine($"Cannot open process: {error}");
}
}
Expand All @@ -86,8 +78,6 @@ protected override void WndProc(ref Message msg)

private void Main_Load(object sender, EventArgs e)
{
Localization.SetLanguage(this);

// Insert new items into context menu
IntPtr MenuHandle = GetSystemMenu(this.Handle, false);
InsertMenu(MenuHandle, 5, MF_BYPOSITION | MF_SEPARATOR, 0, string.Empty);
Expand All @@ -101,33 +91,22 @@ private void Main_Load(object sender, EventArgs e)
private void labeldeactivatedialog_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
// Open settings
try
{
try {
Process.Start("ms-settings:easeofaccess-keyboard");
}
catch (Exception)
{
try
{
} catch (Exception) {
try {
ProcessStartInfo skwinxp = new ProcessStartInfo("rundll32.exe");
skwinxp.Arguments = "Shell32.dll,Control_RunDLL access.cpl,,1";
Process.Start(skwinxp);
}
catch (Exception)
{
try
{
} catch (Exception) {
try {
Process.Start("control.exe");
}
catch (Exception error)
{
int code = GetErrorCode(error);
} catch (Exception error) {
MessageBox.Show($"Cannot open settings from {AppDomain.CurrentDomain.FriendlyName}:\n{error}", AppDomain.CurrentDomain.FriendlyName + " - Cannot open settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(code);
Environment.Exit(126);
}
}
}

Application.Exit();
}

Expand All @@ -139,8 +118,7 @@ private void buttonNo_Click(object sender, EventArgs e)
private void buttonYes_Click(object sender, EventArgs e)
{
// Try to enable sticky keys
try
{
try {
tagSTICKYKEYS stk;
stk.dwFlags = SKF_STICKYKEYSON | SKF_HOTKEYACTIVE;
stk.cbSize = Marshal.SizeOf(typeof(tagSTICKYKEYS));
Expand All @@ -150,26 +128,11 @@ private void buttonYes_Click(object sender, EventArgs e)
// Set Sticky Keys settings
SystemParametersInfoA(SPI_SETSTICKYKEYS, 0, pObj, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
Marshal.FreeHGlobal(pObj);
}
catch (Exception error)
{
int code = GetErrorCode(error);
} catch (Exception error) {
MessageBox.Show($"Cannot change settings from {AppDomain.CurrentDomain.FriendlyName}: {error}\nThe current user will have to manually change the settings.", AppDomain.CurrentDomain.FriendlyName + " - Cannot change settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(code);
Environment.Exit(126);
}

Application.Exit();
}

private int GetErrorCode(Exception error)
{
int code = 1;
var w32ex = error as Win32Exception;
if (w32ex == null)
w32ex = error.InnerException as Win32Exception;
if (w32ex != null)
code = w32ex.ErrorCode;
return code;
}
}
}
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,4 @@ In fact, if you **right click with your mouse on the title bar** you'll see a sl
* PowerShell
* Explorer
* The Control Panel
* The Registry.

# Localization

At the moment there are only these languages:
* English
* Italian
* Chinese

But YOU can help me translating this program! Just modify the `SetLanguage()` function in the `Localization.cs` file and send me a pull request.
* The Registry

0 comments on commit 1b8d32f

Please sign in to comment.