|
|
@@ -15,7 +15,9 @@
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
******************************************************************************/
|
|
|
|
|
|
+#include <algorithm>
|
|
|
#include <sstream>
|
|
|
+#include "obs-app.hpp"
|
|
|
#include "platform.hpp"
|
|
|
using namespace std;
|
|
|
|
|
|
@@ -84,3 +86,75 @@ string GetDefaultVideoSavePath()
|
|
|
os_wcs_to_utf8(path_utf16, wcslen(path_utf16), path_utf8, MAX_PATH);
|
|
|
return string(path_utf8);
|
|
|
}
|
|
|
+
|
|
|
+static vector<string> GetUserPreferredLocales()
|
|
|
+{
|
|
|
+ vector<string> result;
|
|
|
+
|
|
|
+ ULONG num, length = 0;
|
|
|
+ if (!GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &num,
|
|
|
+ nullptr, &length))
|
|
|
+ return result;
|
|
|
+
|
|
|
+ vector<wchar_t> buffer(length);
|
|
|
+ if (!GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &num,
|
|
|
+ &buffer.front(), &length))
|
|
|
+ return result;
|
|
|
+
|
|
|
+ result.reserve(num);
|
|
|
+ auto start = begin(buffer);
|
|
|
+ auto end_ = end(buffer);
|
|
|
+ decltype(start) separator;
|
|
|
+ while ((separator = find(start, end_, 0)) != end_) {
|
|
|
+ if (result.size() == num)
|
|
|
+ break;
|
|
|
+
|
|
|
+ char conv[MAX_PATH] = {};
|
|
|
+ os_wcs_to_utf8(&*start, separator - start, conv, MAX_PATH);
|
|
|
+
|
|
|
+ result.emplace_back(conv);
|
|
|
+
|
|
|
+ start = separator + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+vector<string> GetPreferredLocales()
|
|
|
+{
|
|
|
+ vector<string> windows_locales = GetUserPreferredLocales();
|
|
|
+ auto obs_locales = GetLocaleNames();
|
|
|
+ auto windows_to_obs = [&obs_locales](string windows) {
|
|
|
+ string lang_match;
|
|
|
+
|
|
|
+ for (auto &locale_pair : obs_locales) {
|
|
|
+ auto &locale = locale_pair.first;
|
|
|
+ if (locale == windows.substr(0, locale.size()))
|
|
|
+ return locale;
|
|
|
+
|
|
|
+ if (lang_match.size())
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (locale.substr(0, 2) == windows.substr(0, 2))
|
|
|
+ lang_match = locale;
|
|
|
+ }
|
|
|
+
|
|
|
+ return lang_match;
|
|
|
+ };
|
|
|
+
|
|
|
+ vector<string> result;
|
|
|
+ result.reserve(obs_locales.size());
|
|
|
+
|
|
|
+ for (const string &locale : windows_locales) {
|
|
|
+ string match = windows_to_obs(locale);
|
|
|
+ if (!match.size())
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (find(begin(result), end(result), match) != end(result))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ result.emplace_back(match);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|