diff options
author | Jertzukka <Jertzukka@gmail.com> | 2023-11-19 01:31:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-19 00:31:40 +0100 |
commit | 6a1780864c57d598446eb0c1d4faf7ea238c04d4 (patch) | |
tree | 83a17d40280a4b82be556c2aabb27d15034027fc /src/Main/Resources.cpp | |
parent | 9247ce1bb90c44d19a0069fadb12c0c480ac9b4f (diff) | |
download | VeraCrypt-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/Resources.cpp')
-rw-r--r-- | src/Main/Resources.cpp | 84 |
1 files changed, 48 insertions, 36 deletions
diff --git a/src/Main/Resources.cpp b/src/Main/Resources.cpp index 58030c1e..d8bab977 100644 --- a/src/Main/Resources.cpp +++ b/src/Main/Resources.cpp @@ -23,6 +23,7 @@ #include "Platform/File.h" #include "Platform/StringConverter.h" #include <stdio.h> +#include "UserPreferences.h" #endif namespace VeraCrypt @@ -46,7 +47,6 @@ namespace VeraCrypt } #endif // TC_WINDOWS - string Resources::GetLanguageXml () { #ifdef TC_WINDOWS @@ -68,53 +68,65 @@ namespace VeraCrypt #endif string filenamePost(".xml"); string filename = filenamePrefix + defaultLang + filenamePost; - if(const char* env_p = getenv("LANG")){ - string lang(env_p); + + UserPreferences Preferences; + Preferences.Load(); + wstring preferredLang = Preferences.Language; #ifdef DEBUG - std::cout << lang << std::endl; + std::cout << "Config language: " << preferredLang << std::endl; #endif - if ( lang.size() > 1 ){ - int found = lang.find("."); - if ( found > 1 ){ - string langTag = lang.substr (0,found); - string lowerLangTag(StringConverter::ToLower (langTag) ); - int foundUnderscore = lowerLangTag.find("_"); - if ( foundUnderscore > 0 ) { - lowerLangTag.replace(foundUnderscore,1,1,'-'); - filename = filenamePrefix + lowerLangTag + filenamePost; - FilesystemPath xml(filename); - if (! xml.IsFile()){ - string shortLangTag = lowerLangTag.substr(0,foundUnderscore); - filename = filenamePrefix + shortLangTag + filenamePost; + + if (preferredLang == L"system") { + if (const char *env_p = getenv("LANG")) { + string lang(env_p); +#ifdef DEBUG + std::cout << "env $LANG: " << lang << std::endl; +#endif + if (lang.size() > 1) { + int found = lang.find("."); + if (found > 1) { + string langTag = lang.substr(0, found); + string lowerLangTag(StringConverter::ToLower(langTag)); + int foundUnderscore = lowerLangTag.find("_"); + if (foundUnderscore > 0) { + lowerLangTag.replace(foundUnderscore, 1, 1, '-'); + filename = filenamePrefix + lowerLangTag + filenamePost; FilesystemPath xml(filename); - if (! xml.IsFile()){ + if (!xml.IsFile()) { + string shortLangTag = lowerLangTag.substr(0, foundUnderscore); + filename = filenamePrefix + shortLangTag + filenamePost; + FilesystemPath xml(filename); + if (!xml.IsFile()) { + filename = filenamePrefix + defaultLang + filenamePost; + } + } + } else { + filename = filenamePrefix + langTag + filenamePost; + FilesystemPath xml(filename); + if (!xml.IsFile()) { filename = filenamePrefix + defaultLang + filenamePost; } } - }else{ - filename = filenamePrefix + langTag + filenamePost; + } else { + string lowerLang(StringConverter::ToLower(lang)); + filename = filenamePrefix + lowerLang + filenamePost; FilesystemPath xml(filename); - if (! xml.IsFile()){ - filename = filenamePrefix + defaultLang + filenamePost; - } - } - }else{ - string lowerLang(StringConverter::ToLower (lang) ); - filename = filenamePrefix + lowerLang + filenamePost; - FilesystemPath xml(filename); - if (! xml.IsFile()){ - int foundUnderscore = lowerLang.find("_"); - if ( foundUnderscore > 0 ) { - lowerLang.replace(foundUnderscore,1,1,'-'); - filename = filenamePrefix + lowerLang + filenamePost; - FilesystemPath xml(filename); - if (! xml.IsFile()){ - filename = filenamePrefix + defaultLang + filenamePost; + if (!xml.IsFile()) { + int foundUnderscore = lowerLang.find("_"); + if (foundUnderscore > 0) { + lowerLang.replace(foundUnderscore, 1, 1, '-'); + filename = filenamePrefix + lowerLang + filenamePost; + FilesystemPath xml(filename); + if (!xml.IsFile()) { + filename = filenamePrefix + defaultLang + filenamePost; + } } } } } } + } else { + filename = filenamePrefix + preferredLang + filenamePost; } FilesystemPath xml(filename); if ( xml.IsFile() ){ |