Skip to content

Commit f93597c

Browse files
committed
lang(RightToLeft): Add support for Right to left languages
Fixes #601
1 parent 0173692 commit f93597c

File tree

7 files changed

+31
-6
lines changed

7 files changed

+31
-6
lines changed

SoundSwitch/Localization/Factory/Lang/ILang.cs

+5
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ public interface ILang : IEnumImpl<Language>
99
/// Culture info of this language
1010
/// </summary>
1111
CultureInfo CultureInfo { get; }
12+
13+
/// <summary>
14+
/// Is this language read from Right to left
15+
/// </summary>
16+
bool IsRightToLeft { get; }
1217
}
1318
}

SoundSwitch/Localization/Factory/Lang/Langs.cs

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public abstract class BaseLang : ILang
77
public abstract Language TypeEnum { get; }
88
public string Label => CultureInfo.NativeName;
99
public abstract CultureInfo CultureInfo { get; }
10+
public virtual bool IsRightToLeft { get; }
1011
}
1112

1213
public class EnglishLang : BaseLang
@@ -179,6 +180,8 @@ public class HebrewLang : BaseLang
179180
public override CultureInfo CultureInfo => CultureInfo.GetCultureInfo("he");
180181

181182
public override Language TypeEnum => Language.Hebrew;
183+
184+
public override bool IsRightToLeft => true;
182185
}
183186

184187
public class Czech : BaseLang
@@ -208,6 +211,7 @@ public class Arabic : BaseLang
208211
public override CultureInfo CultureInfo => CultureInfo.GetCultureInfo("ar");
209212

210213
public override Language TypeEnum => Language.Arabic;
214+
public override bool IsRightToLeft => true;
211215
}
212216

213217
}

SoundSwitch/UI/Component/TrayIcon.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
using SoundSwitch.Framework.Updater;
3535
using SoundSwitch.Framework.Updater.Remind;
3636
using SoundSwitch.Localization;
37+
using SoundSwitch.Localization.Factory;
3738
using SoundSwitch.Model;
3839
using SoundSwitch.Properties;
3940
using SoundSwitch.UI.Forms;
@@ -80,6 +81,11 @@ public sealed class TrayIcon : IDisposable
8081

8182
public TrayIcon()
8283
{
84+
//Localization
85+
var rightToLeft = new LanguageFactory().Get(AppModel.Instance.Language).IsRightToLeft ? RightToLeft.Yes : RightToLeft.No;
86+
_selectionMenu.RightToLeft = rightToLeft;
87+
_settingsMenu.RightToLeft = rightToLeft;
88+
8389
UpdateIcon();
8490
_showContextMenu = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
8591
_tooltipInfoManager = new TooltipInfoManager(NotifyIcon);
@@ -102,7 +108,7 @@ public TrayIcon()
102108

103109
if (e.Button != MouseButtons.Left) return;
104110

105-
if (_updateMenuItem.Tag != null && !_postponeService.ShouldPostpone((Release) _updateMenuItem.Tag))
111+
if (_updateMenuItem.Tag != null && !_postponeService.ShouldPostpone((Release)_updateMenuItem.Tag))
106112
{
107113
OnUpdateClick(sender, e);
108114
return;
@@ -144,7 +150,7 @@ public void ReplaceIcon(Icon newIcon)
144150
return;
145151

146152
var oldIcon = NotifyIcon.Icon;
147-
NotifyIcon.Icon = (Icon) newIcon.Clone();
153+
NotifyIcon.Icon = (Icon)newIcon.Clone();
148154
try
149155
{
150156
oldIcon?.Dispose();
@@ -199,7 +205,7 @@ private void OnUpdateClick(object sender, EventArgs eventArgs)
199205

200206
StopAnimationIconUpdate();
201207
NotifyIcon.BalloonTipClicked -= OnUpdateClick;
202-
_updateDownloadForm.DownloadRelease((Release) _updateMenuItem.Tag);
208+
_updateDownloadForm.DownloadRelease((Release)_updateMenuItem.Tag);
203209
}
204210

205211
private void SetEventHandlers()
@@ -264,7 +270,7 @@ private void StartAnimationIconUpdate()
264270
{
265271
if (_animationTimer == null)
266272
{
267-
_animationTimer = new TimerForm() {Interval = 1000};
273+
_animationTimer = new TimerForm() { Interval = 1000 };
268274
var tick = 0;
269275
_animationTimer.Tick += (sender, args) =>
270276
{
@@ -335,7 +341,7 @@ private void DeviceClicked(object sender, EventArgs e)
335341
{
336342
try
337343
{
338-
var item = (ToolStripDeviceItem) sender;
344+
var item = (ToolStripDeviceItem)sender;
339345
AppModel.Instance.SetActiveDevice(item.AudioDevice);
340346
}
341347
catch (Exception)

SoundSwitch/UI/Forms/About.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
* GNU General Public License for more details.
1414
********************************************************************/
1515

16-
using System.Diagnostics;
1716
using System.Windows.Forms;
1817
using SoundSwitch.Localization;
18+
using SoundSwitch.Localization.Factory;
19+
using SoundSwitch.Model;
1920
using SoundSwitch.Properties;
2021
using SoundSwitch.Util.Url;
2122

@@ -27,6 +28,7 @@ public partial class About : Form
2728

2829
public About()
2930
{
31+
RightToLeft = new LanguageFactory().Get(AppModel.Instance.Language).IsRightToLeft ? RightToLeft.Yes : RightToLeft.No;
3032
InitializeComponent();
3133
Icon = helpIcon;
3234
}

SoundSwitch/UI/Forms/Settings.cs

+1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ private void PopulateAudioDevices()
294294

295295
private void LocalizeForm()
296296
{
297+
RightToLeft = new LanguageFactory().Get(AppModel.Instance.Language).IsRightToLeft ? RightToLeft.Yes : RightToLeft.No;
297298
// TabPages
298299
playbackTabPage.Text = SettingsStrings.playback;
299300
playbackListView.Groups[0].Header = SettingsStrings.selected;

SoundSwitch/UI/Forms/UpdateDownloadForm.cs

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
using SoundSwitch.Framework.Updater.Installer;
2020
using SoundSwitch.Framework.Updater.Remind;
2121
using SoundSwitch.Localization;
22+
using SoundSwitch.Localization.Factory;
23+
using SoundSwitch.Model;
2224
using SoundSwitch.Properties;
2325
using SoundSwitch.UI.Component;
2426

@@ -32,6 +34,8 @@ public sealed partial class UpdateDownloadForm : Form
3234

3335
public UpdateDownloadForm()
3436
{
37+
RightToLeft = new LanguageFactory().Get(AppModel.Instance.Language).IsRightToLeft ? RightToLeft.Yes : RightToLeft.No;
38+
3539
InitializeComponent();
3640
Icon = Resources.UpdateIcon;
3741

SoundSwitch/UI/Forms/UpsertProfileExtended.cs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using SoundSwitch.Framework.Profile;
99
using SoundSwitch.Framework.Profile.Trigger;
1010
using SoundSwitch.Localization;
11+
using SoundSwitch.Localization.Factory;
1112
using SoundSwitch.Model;
1213
using SoundSwitch.Properties;
1314
using SoundSwitch.UI.Component;
@@ -25,6 +26,8 @@ public partial class UpsertProfileExtended : Form
2526

2627
public UpsertProfileExtended(Profile profile, IEnumerable<DeviceFullInfo> playbacks, IEnumerable<DeviceFullInfo> recordings, SettingsForm settingsForm, bool editing = false)
2728
{
29+
RightToLeft = new LanguageFactory().Get(AppModel.Instance.Language).IsRightToLeft ? RightToLeft.Yes : RightToLeft.No;
30+
2831
_oldProfile = editing ? profile : null;
2932
_profile = editing ? profile.Copy() : profile;
3033
_settingsForm = settingsForm;

0 commit comments

Comments
 (0)