VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Main/Forms/PreferencesDialog.cpp
diff options
context:
space:
mode:
authorJertzukka <Jertzukka@gmail.com>2023-11-19 01:31:40 +0200
committerGitHub <noreply@github.com>2023-11-19 00:31:40 +0100
commit6a1780864c57d598446eb0c1d4faf7ea238c04d4 (patch)
tree83a17d40280a4b82be556c2aabb27d15034027fc /src/Main/Forms/PreferencesDialog.cpp
parent9247ce1bb90c44d19a0069fadb12c0c480ac9b4f (diff)
downloadVeraCrypt-6a1780864c57d598446eb0c1d4faf7ea238c04d4.tar.gz
VeraCrypt-6a1780864c57d598446eb0c1d4faf7ea238c04d4.zip
Linux/FreeBSD/macOS: Implement language selection settings (#1253)
* Implement Language selection into settings Initial commit to create a new tab in PreferencesNotebook for Language selection. By default, if nothing is chosen, it uses the current behaviour of using the language from system environment variables. If another language is chosen from the settings, it is saved into the Configuration.xml and this is used instead. * Fix SetStringSelection() assert issue on macOS * Add header include to fix build * Add current language pack, authors and way to use literal strings * Translations also for FreeBSD * Minimal GTK3 WX build on FreeBSD requires wxGraphicsContext * Get Preferences properly instead of workaround function * Use WrapSizer instead of BoxSizer for author line This forces long author lists to be put on a new line, reducing the need to increase window width. * Update Finnish translation * Borrow translation from IDM_LANGUAGE where it makes sense * Remove colon and thus unneeded function * Simplify Language tab layout * Reintroduce macOS specific fixes to Forms.cpp * cleanup
Diffstat (limited to 'src/Main/Forms/PreferencesDialog.cpp')
-rw-r--r--src/Main/Forms/PreferencesDialog.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/Main/Forms/PreferencesDialog.cpp b/src/Main/Forms/PreferencesDialog.cpp
index 91204389..90a668e6 100644
--- a/src/Main/Forms/PreferencesDialog.cpp
+++ b/src/Main/Forms/PreferencesDialog.cpp
@@ -14,6 +14,9 @@
#include <wx/dynlib.h>
#ifdef TC_WINDOWS
#include <wx/msw/registry.h>
+#else
+#include <wx/dir.h>
+#include <wx/arrstr.h>
#endif
#include "Common/SecurityToken.h"
#include "Main/Main.h"
@@ -68,6 +71,30 @@ namespace VeraCrypt
}
Pkcs5PrfChoice->Select (prfInitialIndex);
+ // Language for non-Windows
+#ifndef TC_WINDOWS
+#if defined (TC_MACOSX)
+ wxDir languagesFolder(StringConverter::ToSingle (Application::GetExecutableDirectory()) + "/../Resources/languages/");
+#else
+ wxDir languagesFolder("/usr/share/veracrypt/languages/");
+#endif
+ wxArrayString langArray;
+ LanguageListBox->Append("System default");
+ LanguageListBox->Append("English");
+
+ size_t langCount;
+ langCount = wxDir::GetAllFiles(languagesFolder.GetName(), &langArray, wxEmptyString, wxDIR_FILES);
+ for (size_t i = 0; i < langCount; ++i) {
+ wxFileName filename(langArray[i]);
+ wxString langId = filename.GetName().AfterLast('.');
+ wxString langNative = langEntries[langId];
+ if (!langNative.empty()) {
+ LanguageListBox->Append(langNative);
+ }
+ }
+#endif
+
+
// Keyfiles
TC_CHECK_BOX_VALIDATOR (UseKeyfiles);
@@ -238,6 +265,15 @@ namespace VeraCrypt
}
}
+ void PreferencesDialog::OnSysDefaultLangButtonClick (wxCommandEvent& event)
+ {
+ // SetStringSelection()'s Assert currently broken in sorted ListBoxes on macOS, workaround:
+ int itemIndex = LanguageListBox->FindString("System default", true);
+ if (itemIndex != wxNOT_FOUND) {
+ LanguageListBox->SetSelection(itemIndex);
+ }
+ }
+
void PreferencesDialog::OnAssignHotkeyButtonClick (wxCommandEvent& event)
{
#ifdef TC_WINDOWS
@@ -355,6 +391,13 @@ namespace VeraCrypt
AssignHotkeyButton->Enable (false);
}
+ // Fixes an issue where going through PreferencesNotebook tabs would unintentionally select the first entry
+ // in the LanguageListBox and thus cause a language change on OKButton press.
+ void PreferencesDialog::OnPageChanged(wxBookCtrlEvent &event)
+ {
+ LanguageListBox->DeselectAll();
+ }
+
void PreferencesDialog::OnOKButtonClick (wxCommandEvent& event)
{
#ifdef TC_WINDOWS
@@ -388,6 +431,19 @@ namespace VeraCrypt
bool securityTokenModuleChanged = (Preferences.SecurityTokenModule != wstring (Pkcs11ModulePathTextCtrl->GetValue()));
Preferences.SecurityTokenModule = wstring (Pkcs11ModulePathTextCtrl->GetValue());
+ if (LanguageListBox->GetSelection() != wxNOT_FOUND) {
+ wxString langToFind = LanguageListBox->GetString(LanguageListBox->GetSelection());
+ for (const auto &each: langEntries) {
+ if (each.second == langToFind) {
+ Preferences.Language = each.first;
+#ifdef DEBUG
+ cout << "Lang set to: " << each.first << endl;
+#endif
+ }
+ }
+ Gui->ShowInfo (LangString["LINUX_RESTART_FOR_LANGUAGE_CHANGE"]);
+ }
+
Gui->SetPreferences (Preferences);
try