Save GUI language as string instead of wxLanguage enum

When 5.0-211 updated wxWidgets to 3.1.0, some entries in the
wxLanguage enum were moved and added, changing the wxLanguage
values. Because we save Dolphin's interface language to disk
as a wxLanguage, the language you have set will mean something
different depending on whether you have the updated wx version
or not. For instance, setting the language to English with the
updated version and then using an older version will make
Dolphin use Dutch. Because we can't rely on the enum anymore,
I'm replacing the "Language" setting with a "LanguageCode"
setting that uses standard ISO 639 codes.
This commit is contained in:
JosJuice 2016-08-12 14:01:09 +02:00
parent cef71afc27
commit ed9007cab7
4 changed files with 26 additions and 38 deletions

View File

@ -156,7 +156,7 @@ void SConfig::SaveInterfaceSettings(IniFile& ini)
interface->Set("MainWindowPosY", (iPosY == -32000) ? 0 : iPosY); // TODO - HAX interface->Set("MainWindowPosY", (iPosY == -32000) ? 0 : iPosY); // TODO - HAX
interface->Set("MainWindowWidth", iWidth); interface->Set("MainWindowWidth", iWidth);
interface->Set("MainWindowHeight", iHeight); interface->Set("MainWindowHeight", iHeight);
interface->Set("Language", m_InterfaceLanguage); interface->Set("LanguageCode", m_InterfaceLanguage);
interface->Set("ShowToolbar", m_InterfaceToolbar); interface->Set("ShowToolbar", m_InterfaceToolbar);
interface->Set("ShowStatusbar", m_InterfaceStatusbar); interface->Set("ShowStatusbar", m_InterfaceStatusbar);
interface->Set("ShowLogWindow", m_InterfaceLogWindow); interface->Set("ShowLogWindow", m_InterfaceLogWindow);
@ -423,7 +423,7 @@ void SConfig::LoadInterfaceSettings(IniFile& ini)
interface->Get("MainWindowPosY", &iPosY, 100); interface->Get("MainWindowPosY", &iPosY, 100);
interface->Get("MainWindowWidth", &iWidth, 800); interface->Get("MainWindowWidth", &iWidth, 800);
interface->Get("MainWindowHeight", &iHeight, 600); interface->Get("MainWindowHeight", &iHeight, 600);
interface->Get("Language", &m_InterfaceLanguage, 0); interface->Get("LanguageCode", &m_InterfaceLanguage, "");
interface->Get("ShowToolbar", &m_InterfaceToolbar, true); interface->Get("ShowToolbar", &m_InterfaceToolbar, true);
interface->Get("ShowStatusbar", &m_InterfaceStatusbar, true); interface->Get("ShowStatusbar", &m_InterfaceStatusbar, true);
interface->Get("ShowLogWindow", &m_InterfaceLogWindow, false); interface->Get("ShowLogWindow", &m_InterfaceLogWindow, false);

View File

@ -210,7 +210,7 @@ struct SConfig : NonCopyable
std::string m_bba_mac; std::string m_bba_mac;
// interface language // interface language
int m_InterfaceLanguage; std::string m_InterfaceLanguage;
float m_EmulationSpeed; float m_EmulationSpeed;
bool m_OCEnable; bool m_OCEnable;
float m_OCFactor; float m_OCFactor;

View File

@ -27,38 +27,14 @@
#include "DolphinWX/X11Utils.h" #include "DolphinWX/X11Utils.h"
#endif #endif
static const wxLanguage language_ids[] = { static const std::string language_ids[] = {
wxLANGUAGE_DEFAULT, "",
wxLANGUAGE_MALAY, "ms", "ca", "cs", "da", "de", "en", "es", "fr", "hr", "it", "hu", "nl",
wxLANGUAGE_CATALAN, "nb", // wxWidgets won't accept "no"
wxLANGUAGE_CZECH, "pl", "pt", "pt_BR", "ro", "sr", "sv", "tr",
wxLANGUAGE_DANISH,
wxLANGUAGE_GERMAN,
wxLANGUAGE_ENGLISH,
wxLANGUAGE_SPANISH,
wxLANGUAGE_FRENCH,
wxLANGUAGE_CROATIAN,
wxLANGUAGE_ITALIAN,
wxLANGUAGE_HUNGARIAN,
wxLANGUAGE_DUTCH,
wxLANGUAGE_NORWEGIAN_BOKMAL,
wxLANGUAGE_POLISH,
wxLANGUAGE_PORTUGUESE,
wxLANGUAGE_PORTUGUESE_BRAZILIAN,
wxLANGUAGE_ROMANIAN,
wxLANGUAGE_SERBIAN,
wxLANGUAGE_SWEDISH,
wxLANGUAGE_TURKISH,
wxLANGUAGE_GREEK, "el", "ru", "ar", "fa", "ko", "ja", "zh_CN", "zh_TW",
wxLANGUAGE_RUSSIAN,
wxLANGUAGE_ARABIC,
wxLANGUAGE_FARSI,
wxLANGUAGE_KOREAN,
wxLANGUAGE_JAPANESE,
wxLANGUAGE_CHINESE_SIMPLIFIED,
wxLANGUAGE_CHINESE_TRADITIONAL,
}; };
InterfaceConfigPane::InterfaceConfigPane(wxWindow* parent, wxWindowID id) : wxPanel(parent, id) InterfaceConfigPane::InterfaceConfigPane(wxWindow* parent, wxWindowID id) : wxPanel(parent, id)

View File

@ -295,11 +295,23 @@ void DolphinApp::AfterInit()
void DolphinApp::InitLanguageSupport() void DolphinApp::InitLanguageSupport()
{ {
unsigned int language = 0; std::string language_code;
{
IniFile ini; IniFile ini;
ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX));
ini.GetOrCreateSection("Interface")->Get("Language", &language, wxLANGUAGE_DEFAULT); ini.GetOrCreateSection("Interface")->Get("LanguageCode", &language_code, "");
}
int language = wxLANGUAGE_UNKNOWN;
if (language_code.empty())
{
language = wxLANGUAGE_DEFAULT;
}
else
{
const wxLanguageInfo* language_info = wxLocale::FindLanguageInfo(StrToWxStr(language_code));
if (language_info)
language = language_info->Language;
}
// Load language if possible, fall back to system default otherwise // Load language if possible, fall back to system default otherwise
if (wxLocale::IsAvailable(language)) if (wxLocale::IsAvailable(language))