Skip to content

Commit

Permalink
lang(RightToLeft): Add support for Right to left languages
Browse files Browse the repository at this point in the history
Fixes #601
  • Loading branch information
Belphemur committed Aug 25, 2021
1 parent 0173692 commit f93597c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions SoundSwitch/Localization/Factory/Lang/ILang.cs
Expand Up @@ -9,5 +9,10 @@ public interface ILang : IEnumImpl<Language>
/// Culture info of this language
/// </summary>
CultureInfo CultureInfo { get; }

/// <summary>
/// Is this language read from Right to left
/// </summary>
bool IsRightToLeft { get; }
}
}
4 changes: 4 additions & 0 deletions SoundSwitch/Localization/Factory/Lang/Langs.cs
Expand Up @@ -7,6 +7,7 @@ public abstract class BaseLang : ILang
public abstract Language TypeEnum { get; }
public string Label => CultureInfo.NativeName;
public abstract CultureInfo CultureInfo { get; }
public virtual bool IsRightToLeft { get; }
}

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

public override Language TypeEnum => Language.Hebrew;

public override bool IsRightToLeft => true;
}

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

public override Language TypeEnum => Language.Arabic;
public override bool IsRightToLeft => true;
}

}
16 changes: 11 additions & 5 deletions SoundSwitch/UI/Component/TrayIcon.cs
Expand Up @@ -34,6 +34,7 @@
using SoundSwitch.Framework.Updater;
using SoundSwitch.Framework.Updater.Remind;
using SoundSwitch.Localization;
using SoundSwitch.Localization.Factory;
using SoundSwitch.Model;
using SoundSwitch.Properties;
using SoundSwitch.UI.Forms;
Expand Down Expand Up @@ -80,6 +81,11 @@ public sealed class TrayIcon : IDisposable

public TrayIcon()
{
//Localization
var rightToLeft = new LanguageFactory().Get(AppModel.Instance.Language).IsRightToLeft ? RightToLeft.Yes : RightToLeft.No;
_selectionMenu.RightToLeft = rightToLeft;
_settingsMenu.RightToLeft = rightToLeft;

UpdateIcon();
_showContextMenu = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
_tooltipInfoManager = new TooltipInfoManager(NotifyIcon);
Expand All @@ -102,7 +108,7 @@ public TrayIcon()
if (e.Button != MouseButtons.Left) return;
if (_updateMenuItem.Tag != null && !_postponeService.ShouldPostpone((Release) _updateMenuItem.Tag))
if (_updateMenuItem.Tag != null && !_postponeService.ShouldPostpone((Release)_updateMenuItem.Tag))
{
OnUpdateClick(sender, e);
return;
Expand Down Expand Up @@ -144,7 +150,7 @@ public void ReplaceIcon(Icon newIcon)
return;

var oldIcon = NotifyIcon.Icon;
NotifyIcon.Icon = (Icon) newIcon.Clone();
NotifyIcon.Icon = (Icon)newIcon.Clone();
try
{
oldIcon?.Dispose();
Expand Down Expand Up @@ -199,7 +205,7 @@ private void OnUpdateClick(object sender, EventArgs eventArgs)

StopAnimationIconUpdate();
NotifyIcon.BalloonTipClicked -= OnUpdateClick;
_updateDownloadForm.DownloadRelease((Release) _updateMenuItem.Tag);
_updateDownloadForm.DownloadRelease((Release)_updateMenuItem.Tag);
}

private void SetEventHandlers()
Expand Down Expand Up @@ -264,7 +270,7 @@ private void StartAnimationIconUpdate()
{
if (_animationTimer == null)
{
_animationTimer = new TimerForm() {Interval = 1000};
_animationTimer = new TimerForm() { Interval = 1000 };
var tick = 0;
_animationTimer.Tick += (sender, args) =>
{
Expand Down Expand Up @@ -335,7 +341,7 @@ private void DeviceClicked(object sender, EventArgs e)
{
try
{
var item = (ToolStripDeviceItem) sender;
var item = (ToolStripDeviceItem)sender;
AppModel.Instance.SetActiveDevice(item.AudioDevice);
}
catch (Exception)
Expand Down
4 changes: 3 additions & 1 deletion SoundSwitch/UI/Forms/About.cs
Expand Up @@ -13,9 +13,10 @@
* GNU General Public License for more details.
********************************************************************/

using System.Diagnostics;
using System.Windows.Forms;
using SoundSwitch.Localization;
using SoundSwitch.Localization.Factory;
using SoundSwitch.Model;
using SoundSwitch.Properties;
using SoundSwitch.Util.Url;

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

public About()
{
RightToLeft = new LanguageFactory().Get(AppModel.Instance.Language).IsRightToLeft ? RightToLeft.Yes : RightToLeft.No;
InitializeComponent();
Icon = helpIcon;
}
Expand Down
1 change: 1 addition & 0 deletions SoundSwitch/UI/Forms/Settings.cs
Expand Up @@ -294,6 +294,7 @@ private void PopulateAudioDevices()

private void LocalizeForm()
{
RightToLeft = new LanguageFactory().Get(AppModel.Instance.Language).IsRightToLeft ? RightToLeft.Yes : RightToLeft.No;
// TabPages
playbackTabPage.Text = SettingsStrings.playback;
playbackListView.Groups[0].Header = SettingsStrings.selected;
Expand Down
4 changes: 4 additions & 0 deletions SoundSwitch/UI/Forms/UpdateDownloadForm.cs
Expand Up @@ -19,6 +19,8 @@
using SoundSwitch.Framework.Updater.Installer;
using SoundSwitch.Framework.Updater.Remind;
using SoundSwitch.Localization;
using SoundSwitch.Localization.Factory;
using SoundSwitch.Model;
using SoundSwitch.Properties;
using SoundSwitch.UI.Component;

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

public UpdateDownloadForm()
{
RightToLeft = new LanguageFactory().Get(AppModel.Instance.Language).IsRightToLeft ? RightToLeft.Yes : RightToLeft.No;

InitializeComponent();
Icon = Resources.UpdateIcon;

Expand Down
3 changes: 3 additions & 0 deletions SoundSwitch/UI/Forms/UpsertProfileExtended.cs
Expand Up @@ -8,6 +8,7 @@
using SoundSwitch.Framework.Profile;
using SoundSwitch.Framework.Profile.Trigger;
using SoundSwitch.Localization;
using SoundSwitch.Localization.Factory;
using SoundSwitch.Model;
using SoundSwitch.Properties;
using SoundSwitch.UI.Component;
Expand All @@ -25,6 +26,8 @@ public partial class UpsertProfileExtended : Form

public UpsertProfileExtended(Profile profile, IEnumerable<DeviceFullInfo> playbacks, IEnumerable<DeviceFullInfo> recordings, SettingsForm settingsForm, bool editing = false)
{
RightToLeft = new LanguageFactory().Get(AppModel.Instance.Language).IsRightToLeft ? RightToLeft.Yes : RightToLeft.No;

_oldProfile = editing ? profile : null;
_profile = editing ? profile.Copy() : profile;
_settingsForm = settingsForm;
Expand Down

0 comments on commit f93597c

Please sign in to comment.