瀏覽代碼

Implement language autoselection using platform priority lists

Palana 11 年之前
父節點
當前提交
0a80960b5b
共有 1 個文件被更改,包括 32 次插入4 次删除
  1. 32 4
      obs/obs-app.cpp

+ 32 - 4
obs/obs-app.cpp

@@ -162,9 +162,6 @@ bool OBSApp::InitLocale()
 
 
 	locale = lang;
 	locale = lang;
 
 
-	stringstream file;
-	file << "locale/" << lang << ".ini";
-
 	string englishPath;
 	string englishPath;
 	if (!GetDataFilePath("locale/" DEFAULT_LANG ".ini", englishPath)) {
 	if (!GetDataFilePath("locale/" DEFAULT_LANG ".ini", englishPath)) {
 		OBSErrorBox(NULL, "Failed to find locale/" DEFAULT_LANG ".ini");
 		OBSErrorBox(NULL, "Failed to find locale/" DEFAULT_LANG ".ini");
@@ -178,9 +175,40 @@ bool OBSApp::InitLocale()
 		return false;
 		return false;
 	}
 	}
 
 
-	if (astrcmpi(lang, DEFAULT_LANG) == 0)
+	bool userLocale = config_has_user_value(globalConfig, "General",
+			"Language");
+	bool defaultLang = astrcmpi(lang, DEFAULT_LANG) == 0;
+
+	if (userLocale && defaultLang)
 		return true;
 		return true;
 
 
+	if (!userLocale && defaultLang) {
+		for (auto &locale_ : GetPreferredLocales()) {
+			if (locale_ == lang)
+				return true;
+
+			stringstream file;
+			file << "locale/" << locale_ << ".ini";
+
+			string path;
+			if (!GetDataFilePath(file.str().c_str(), path))
+				continue;
+
+			if (!text_lookup_add(textLookup, path.c_str()))
+				continue;
+
+			blog(LOG_INFO, "Using preferred locale '%s'",
+					locale_.c_str());
+			locale = locale_;
+			return true;
+		}
+
+		return true;
+	}
+
+	stringstream file;
+	file << "locale/" << lang << ".ini";
+
 	string path;
 	string path;
 	if (GetDataFilePath(file.str().c_str(), path)) {
 	if (GetDataFilePath(file.str().c_str(), path)) {
 		if (!text_lookup_add(textLookup, path.c_str()))
 		if (!text_lookup_add(textLookup, path.c_str()))