Skip to content

Commit

Permalink
Add msgbox translation support
Browse files Browse the repository at this point in the history
  • Loading branch information
nomi-san committed May 9, 2024
1 parent 38a6b07 commit a7a8bcd
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 29 deletions.
27 changes: 15 additions & 12 deletions app/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,30 @@ protected override void OnStartup(StartupEventArgs e)
return;
}

base.OnStartup(e);
LoadLanguages();

var status = ParsecVDD.QueryStatus();
if (status != Device.Status.OK)
{
if (status == Device.Status.RESTART_REQUIRED)
{
MessageBox.Show("You must restart your PC to complete the driver setup.",
MessageBox.Show(GetTranslation("t_msg_must_restart_pc"),
NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
}
else if (status == Device.Status.DISABLED)
{
MessageBox.Show($"{ParsecVDD.ADAPTER} is disabled, please enable it.",
MessageBox.Show(GetTranslation("t_msg_driver_is_disabled", ParsecVDD.ADAPTER),
NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
}
else if (status == Device.Status.NOT_INSTALLED)
{
MessageBox.Show("Please install the driver first.",
MessageBox.Show(GetTranslation("t_msg_please_install_driver"),
NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
{
MessageBox.Show($"The driver is not OK, please check again. Current status: {status}.",
MessageBox.Show(GetTranslation("t_msg_driver_status_not_ok", status),
NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
}

Expand All @@ -85,7 +88,7 @@ protected override void OnStartup(StartupEventArgs e)

if (ParsecVDD.Init() == false)
{
MessageBox.Show("Failed to obtain the device handle, please check the driver installation again.",
MessageBox.Show(GetTranslation("t_msg_failed_to_obtain_handle"),
NAME, MessageBoxButton.OK, MessageBoxImage.Warning);

Shutdown();
Expand All @@ -100,9 +103,6 @@ protected override void OnStartup(StartupEventArgs e)
}
});

base.OnStartup(e);
LoadLanguages();

// Disable GPU to prevent flickering when adding display
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
}
Expand Down Expand Up @@ -166,13 +166,16 @@ public static void SetLanguage(string name, bool saveConfig = true)
}
}

public static string GetTranslation(string key)
public static string GetTranslation(string key, params object[] args)
{
try
{
var trans = Current.FindResource(key);
if (trans != null && trans is string)
return trans as string;
var translation = Current.FindResource(key);
if (translation != null && translation is string t)
{
t = t.Replace("\\n", "\n");
return string.Format(t, args);
}
}
catch
{
Expand Down
4 changes: 2 additions & 2 deletions app/Components/CustomPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void ApplyChanges(object sender, EventArgs e)
// Check negative values & limit 8K resolution
if (width < 0 || width > 7680 || height < 0 || height > 4320 || hz < 0)
{
MessageBox.Show($"Found invalid value in slot {i / 3 + 1}.",
MessageBox.Show(App.GetTranslation("t_msg_custom_invalid_slot", i / 3 + 1),
App.NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
Expand All @@ -65,7 +65,7 @@ private void ApplyChanges(object sender, EventArgs e)
var args = $"-custom \"{Display.DumpModes(modes)}\" \"{parentGPU}\"";
if (Helper.RunAdminTask(args) == false)
{
MessageBox.Show("Could not set custom resolutions, access denied!",
MessageBox.Show(App.GetTranslation("t_msg_custom_access_denied"),
App.NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
Expand Down
19 changes: 18 additions & 1 deletion app/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<system:String x:Key="t_custom">Custom...</system:String>
<system:String x:Key="t_apply">Apply</system:String>
<system:String x:Key="t_parent_gpu">Parent GPU</system:String>
<system:String x:Key="t_driver_status">Driver status</system:String>
<system:String x:Key="t_language">Language</system:String>

<!--Context menu-->
Expand All @@ -32,4 +31,22 @@
<system:String x:Key="t_keep_screen_on">Keep screen on</system:String>
<system:String x:Key="t_check_for_update">Check for update</system:String>
<system:String x:Key="t_exit">Exit</system:String>

<!--Dialog messages-->
<system:String x:Key="t_msg_up_to_date">Your app version is up-to-date.</system:String>
<system:String x:Key="t_msg_update_available">A new version — v{0} is available.\nTo keep your experience optimal, please update it now."</system:String>

<system:String x:Key="t_msg_custom_access_denied">Could not apply custom resolutions, access denied!</system:String>
<system:String x:Key="t_msg_custom_invalid_slot">Found invalid value in slot #{0}.</system:String>

<system:String x:Key="t_msg_exceeded_display_limit">Could not add more virtual displays, you have exceeded the maximum number ({0}).</system:String>
<system:String x:Key="t_msg_prompt_leave_all">All added virtual displays will be unplugged.\nDo you still want to exit?.</system:String>

<system:String x:Key="t_msg_driver_status">Driver status</system:String>
<system:String x:Key="t_msg_must_restart_pc">You must restart your PC to complete the driver setup.</system:String>
<system:String x:Key="t_msg_driver_is_disabled">{0} is disabled, please enable it in Device Manager.</system:String>
<system:String x:Key="t_msg_please_install_driver">Please install the driver first.</system:String>
<system:String x:Key="t_msg_driver_status_not_ok">The driver is not OK, please check again. Current status: {0}.</system:String>
<system:String x:Key="t_msg_failed_to_obtain_handle">Failed to obtain the device handle, please check the driver installation again.</system:String>

</ResourceDictionary>
16 changes: 15 additions & 1 deletion app/Languages/vi.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@
<system:String x:Key="t_exit">Thoát</system:String>

<!--Dialog messages-->
<system:String x:Key="t_msg_">Thoát</system:String>
<system:String x:Key="t_msg_up_to_date">Bạn đang sử dụng phiên bản mới nhất.</system:String>
<system:String x:Key="t_msg_update_available">Có bản cập nhật mới — v{0}.\nHãy cập nhật ngay để trải nghiệm các tính năng mới."</system:String>

<system:String x:Key="t_msg_custom_access_denied">Không thể áp dụng độ phân giải tùy chỉnh, quyền truy cập bị từ chối!</system:String>
<system:String x:Key="t_msg_custom_invalid_slot">Giá trị không hợp lệ ở slot #{0}.</system:String>

<system:String x:Key="t_msg_exceeded_display_limit">Không thể cắm thêm màn hình ảo, bạn đã đạt đến con số giới hạn ({0}).</system:String>
<system:String x:Key="t_msg_prompt_leave_all">Tất cả màn hình ảo sẽ bị tháo bỏ.\nBạn có muốn thoát không?.</system:String>

<system:String x:Key="t_msg_driver_status">Trạng thái driver</system:String>
<system:String x:Key="t_msg_must_restart_pc">Bạn phải khởi động lại PC để driver hoạt động.</system:String>
<system:String x:Key="t_msg_driver_is_disabled">{0} đã bị vô hiệu, vui lòng bật nó trong Device Manager.</system:String>
<system:String x:Key="t_msg_please_install_driver">Vui lòng cài đặt driver trước.</system:String>
<system:String x:Key="t_msg_driver_status_not_ok">Driver không được OK, vui lòng kiểm tra lại. Trạng thái hiện tại: {0}.</system:String>
<system:String x:Key="t_msg_failed_to_obtain_handle">Không thể lấy 'device handle', vui lòng kiểm tra cài đặt driver và thử lại.</system:String>

</ResourceDictionary>
22 changes: 9 additions & 13 deletions app/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public MainWindow()
// setup tray context menu
ContextMenu.DataContext = this;
ContextMenu.Resources = App.Current.Resources;

Tray.Init(this, ContextMenu);
ContextMenu = null;
}

protected override void OnSourceInitialized(EventArgs e)
Expand Down Expand Up @@ -68,6 +65,9 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
{
Loaded -= Window_Loaded;

Tray.Init(this, ContextMenu);
ContextMenu = null;

if (App.Silent)
Hide();

Expand Down Expand Up @@ -128,8 +128,7 @@ private void AddDisplay(object sender, EventArgs e)
{
if (ParsecVDD.DisplayCount >= ParsecVDD.MAX_DISPLAYS)
{
MessageBox.Show(this,
$"Could not add more virtual displays, you have exceeded the maximum number ({ParsecVDD.MAX_DISPLAYS}).",
MessageBox.Show(this, App.GetTranslation("t_msg_exceeded_display_limit", ParsecVDD.MAX_DISPLAYS),
Title, MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
Expand Down Expand Up @@ -176,16 +175,15 @@ private void QueryStatus(object sender, EventArgs e)
var status = ParsecVDD.QueryStatus();
var version = ParsecVDD.QueryVersion();

MessageBox.Show(this,
$"Parsec Virtual Display v{version}\nDriver status: {status}",
MessageBox.Show(this, $"Parsec Virtual Display v{version}\n" +
$"{App.GetTranslation("t_msg_driver_status")}: {status}",
App.NAME, MessageBoxButton.OK, MessageBoxImage.Information);
}

private void ExitApp(object sender, EventArgs e)
{
if (ParsecVDD.DisplayCount > 0)
if (MessageBox.Show(this,
"All added virtual displays will be unplugged.\nDo you still want to exit?",
if (MessageBox.Show(this, App.GetTranslation("t_msg_prompt_leave_all"),
App.NAME, MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes)
return;

Expand All @@ -211,9 +209,7 @@ private async void CheckUpdate(object sender, RoutedEventArgs e)
var newVersion = await Updater.CheckUpdate();
if (!string.IsNullOrEmpty(newVersion))
{
var ret = MessageBox.Show(this,
$"A new version — v{newVersion} is available!\n" +
$"To keep your experience optimal, please update it now.",
var ret = MessageBox.Show(this, App.GetTranslation("t_msg_update_available", newVersion),
App.NAME, MessageBoxButton.YesNo, MessageBoxImage.Question);
if (ret == MessageBoxResult.Yes)
{
Expand All @@ -222,7 +218,7 @@ private async void CheckUpdate(object sender, RoutedEventArgs e)
}
else if (sender != null)
{
MessageBox.Show(this, "Your app version is up-to-date.",
MessageBox.Show(this, App.GetTranslation("t_msg_up_to_date"),
App.NAME, MessageBoxButton.OK, MessageBoxImage.Information);
}

Expand Down

0 comments on commit a7a8bcd

Please sign in to comment.