Skip to content

Commit

Permalink
config: add ui language toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhngtu committed Jan 17, 2024
1 parent 15adb71 commit 954dc38
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 32 deletions.
9 changes: 9 additions & 0 deletions VietTypeConfig/Form1.Designer.cs

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

17 changes: 16 additions & 1 deletion VietTypeConfig/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// SPDX-FileCopyrightText: Copyright (c) 2022 Dinh Ngoc Tu
// SPDX-License-Identifier: GPL-3.0-only

using Microsoft.Win32;
using System;
using System.Resources;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using static VietTypeConfig.VietTypeRegistrar;

namespace VietTypeConfig {
public partial class Form1 : Form {
private readonly ResourceManager rm = new ResourceManager(typeof(Form1));
private bool oobe = false;
private readonly bool oobe = false;

public Form1(string[] args) {
if (args.Length > 0) {
Expand All @@ -30,6 +32,8 @@ private void Form1_Load(object sender, EventArgs e) {
MessageBox.Show(string.Format(rm.GetString("cannotFindLibraryMessage"), ex.Message), "VietType", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
}
cbVietnameseUI.Checked = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName == "vi";
cbVietnameseUI.CheckedChanged += cbVietnameseUI_CheckedChanged;
}

private void CloseForm(object sender, EventArgs e) {
Expand Down Expand Up @@ -62,6 +66,17 @@ private void btnEnable_Click(object sender, EventArgs e) {
Activate(IsProfileActivated() != S_OK);
}

private void cbVietnameseUI_CheckedChanged(object sender, EventArgs e) {
try {
using (var regKey = Registry.CurrentUser.CreateSubKey(Settings.Subkey)) {
regKey.SetValue("ui_language", cbVietnameseUI.Checked ? "vi" : "en");
Application.Restart();
}
} catch (Exception ex) {
MessageBox.Show(string.Format(rm.GetString("cannotSaveSettingsMessage"), ex.Message), "VietType", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void Activate(bool newState) {
var result = newState ? ActivateProfiles() : DeactivateProfiles();
if (result == S_OK) {
Expand Down
3 changes: 3 additions & 0 deletions VietTypeConfig/Form1.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ VietType is free software, licensed under the GNU General Public License. VietTy
<data name="cbOaUy.Text" xml:space="preserve">
<value>&amp;Use "oà", "uý" instead of "òa", "úy"</value>
</data>
<data name="cbVietnameseUI.Text" xml:space="preserve">
<value>Giao diện tiếng &amp;Việt</value>
</data>
<data name="disableSuccessMessage" xml:space="preserve">
<value>Successfully disabled VietType.</value>
</data>
Expand Down
90 changes: 60 additions & 30 deletions VietTypeConfig/Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="cbDefaultEnabled.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 51</value>
<value>12, 74</value>
</data>
<data name="cbDefaultEnabled.Size" type="System.Drawing.Size, System.Drawing">
<value>320, 17</value>
</data>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="cbDefaultEnabled.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
<value>2</value>
</data>
<data name="cbDefaultEnabled.Text" xml:space="preserve">
<value>Vietnamese mode by de&amp;fault</value>
Expand All @@ -151,7 +151,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;cbDefaultEnabled.ZOrder" xml:space="preserve">
<value>11</value>
<value>12</value>
</data>
<data name="cbOaUy.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
Expand All @@ -160,13 +160,13 @@
<value>NoControl</value>
</data>
<data name="cbOaUy.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 74</value>
<value>12, 97</value>
</data>
<data name="cbOaUy.Size" type="System.Drawing.Size, System.Drawing">
<value>320, 17</value>
</data>
<data name="cbOaUy.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
<value>3</value>
</data>
<data name="cbOaUy.Text" xml:space="preserve">
<value>&amp;Use "oà", "uý" instead of "òa", "úy"</value>
Expand All @@ -181,7 +181,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;cbOaUy.ZOrder" xml:space="preserve">
<value>10</value>
<value>11</value>
</data>
<data name="cbAcceptDd.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
Expand All @@ -190,13 +190,13 @@
<value>NoControl</value>
</data>
<data name="cbAcceptDd.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 97</value>
<value>12, 120</value>
</data>
<data name="cbAcceptDd.Size" type="System.Drawing.Size, System.Drawing">
<value>320, 17</value>
</data>
<data name="cbAcceptDd.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
<value>4</value>
</data>
<data name="cbAcceptDd.Text" xml:space="preserve">
<value>Accept 'd' any&amp;where</value>
Expand All @@ -211,7 +211,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;cbAcceptDd.ZOrder" xml:space="preserve">
<value>9</value>
<value>10</value>
</data>
<data name="cbBackspaceInvalid.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
Expand All @@ -220,13 +220,13 @@
<value>NoControl</value>
</data>
<data name="cbBackspaceInvalid.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 120</value>
<value>12, 143</value>
</data>
<data name="cbBackspaceInvalid.Size" type="System.Drawing.Size, System.Drawing">
<value>320, 17</value>
</data>
<data name="cbBackspaceInvalid.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
<value>5</value>
</data>
<data name="cbBackspaceInvalid.Text" xml:space="preserve">
<value>Backspaced &amp;invalid word stays invalid</value>
Expand All @@ -241,7 +241,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;cbBackspaceInvalid.ZOrder" xml:space="preserve">
<value>8</value>
<value>9</value>
</data>
<data name="cbBackconvertOnBackspace.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
Expand All @@ -250,13 +250,13 @@
<value>NoControl</value>
</data>
<data name="cbBackconvertOnBackspace.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 143</value>
<value>12, 166</value>
</data>
<data name="cbBackconvertOnBackspace.Size" type="System.Drawing.Size, System.Drawing">
<value>320, 17</value>
</data>
<data name="cbBackconvertOnBackspace.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
<value>6</value>
</data>
<data name="cbBackconvertOnBackspace.Text" xml:space="preserve">
<value>&amp;Reconvert word on Backspace (Experimental)</value>
Expand All @@ -271,7 +271,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;cbBackconvertOnBackspace.ZOrder" xml:space="preserve">
<value>7</value>
<value>8</value>
</data>
<data name="btnEnable.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
Expand All @@ -298,7 +298,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;btnEnable.ZOrder" xml:space="preserve">
<value>3</value>
<value>4</value>
</data>
<data name="label1.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
Expand All @@ -307,13 +307,13 @@
<value>NoControl</value>
</data>
<data name="label1.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 42</value>
<value>0, 64</value>
</data>
<data name="label1.Size" type="System.Drawing.Size, System.Drawing">
<value>344, 2</value>
</data>
<data name="label1.TabIndex" type="System.Int32, mscorlib">
<value>11</value>
<value>12</value>
</data>
<data name="label1.Text" xml:space="preserve">
<value>label1</value>
Expand All @@ -328,7 +328,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;label1.ZOrder" xml:space="preserve">
<value>2</value>
<value>3</value>
</data>
<data name="btnOK.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Right</value>
Expand All @@ -343,7 +343,7 @@
<value>75, 23</value>
</data>
<data name="btnOK.TabIndex" type="System.Int32, mscorlib">
<value>8</value>
<value>9</value>
</data>
<data name="btnOK.Text" xml:space="preserve">
<value>OK</value>
Expand All @@ -358,7 +358,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;btnOK.ZOrder" xml:space="preserve">
<value>6</value>
<value>7</value>
</data>
<data name="btnCancel.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Right</value>
Expand All @@ -373,7 +373,7 @@
<value>75, 23</value>
</data>
<data name="btnCancel.TabIndex" type="System.Int32, mscorlib">
<value>9</value>
<value>10</value>
</data>
<data name="btnCancel.Text" xml:space="preserve">
<value>Cancel</value>
Expand All @@ -388,7 +388,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;btnCancel.ZOrder" xml:space="preserve">
<value>5</value>
<value>6</value>
</data>
<data name="btnAbout.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left</value>
Expand All @@ -403,7 +403,7 @@
<value>75, 23</value>
</data>
<data name="btnAbout.TabIndex" type="System.Int32, mscorlib">
<value>10</value>
<value>11</value>
</data>
<data name="btnAbout.Text" xml:space="preserve">
<value>A&amp;bout</value>
Expand All @@ -418,7 +418,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;btnAbout.ZOrder" xml:space="preserve">
<value>4</value>
<value>5</value>
</data>
<data name="lblOptimizeMultilang.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
Expand All @@ -427,13 +427,13 @@
<value>NoControl</value>
</data>
<data name="lblOptimizeMultilang.Location" type="System.Drawing.Point, System.Drawing">
<value>9, 168</value>
<value>9, 191</value>
</data>
<data name="lblOptimizeMultilang.Size" type="System.Drawing.Size, System.Drawing">
<value>176, 13</value>
</data>
<data name="lblOptimizeMultilang.TabIndex" type="System.Int32, mscorlib">
<value>6</value>
<value>7</value>
</data>
<data name="lblOptimizeMultilang.Text" xml:space="preserve">
<value>Multilingual typing &amp;optimization level:</value>
Expand All @@ -448,19 +448,19 @@
<value>$this</value>
</data>
<data name="&gt;&gt;lblOptimizeMultilang.ZOrder" xml:space="preserve">
<value>1</value>
<value>2</value>
</data>
<data name="udOptimizeMultilang.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
</data>
<data name="udOptimizeMultilang.Location" type="System.Drawing.Point, System.Drawing">
<value>212, 166</value>
<value>212, 189</value>
</data>
<data name="udOptimizeMultilang.Size" type="System.Drawing.Size, System.Drawing">
<value>120, 20</value>
</data>
<data name="udOptimizeMultilang.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
<value>8</value>
</data>
<data name="&gt;&gt;udOptimizeMultilang.Name" xml:space="preserve">
<value>udOptimizeMultilang</value>
Expand All @@ -472,6 +472,36 @@
<value>$this</value>
</data>
<data name="&gt;&gt;udOptimizeMultilang.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="cbVietnameseUI.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
</data>
<data name="cbVietnameseUI.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="cbVietnameseUI.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 41</value>
</data>
<data name="cbVietnameseUI.Size" type="System.Drawing.Size, System.Drawing">
<value>118, 17</value>
</data>
<data name="cbVietnameseUI.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="cbVietnameseUI.Text" xml:space="preserve">
<value>Giao diện tiếng &amp;Việt</value>
</data>
<data name="&gt;&gt;cbVietnameseUI.Name" xml:space="preserve">
<value>cbVietnameseUI</value>
</data>
<data name="&gt;&gt;cbVietnameseUI.Type" xml:space="preserve">
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;cbVietnameseUI.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;cbVietnameseUI.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
Expand Down
3 changes: 3 additions & 0 deletions VietTypeConfig/Form1.vi.resx
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,7 @@ VietType là phần mềm tự do, bạn có thể cung cấp lại và/hoặc c
<data name="setDefaultQuestion" xml:space="preserve">
<value>Đặt VietType làm bộ gõ mặc định?</value>
</data>
<data name="cbVietnameseUI.Text" xml:space="preserve">
<value>&amp;Vietnamese interface</value>
</data>
</root>
Loading

0 comments on commit 954dc38

Please sign in to comment.