mirror of https://github.com/odrling/Aegisub
Verify that we're actually using a UTF-8 locale and switch to en_US.UTF-8 if not
Should fix #1587 and #1675, but I was never able to reproduce either of them so maybe not.
This commit is contained in:
parent
432640c045
commit
77a2c1bb16
33
src/main.cpp
33
src/main.cpp
|
@ -68,7 +68,7 @@
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/interprocess/streams/bufferstream.hpp>
|
#include <boost/interprocess/streams/bufferstream.hpp>
|
||||||
#include <boost/locale.hpp>
|
#include <boost/locale.hpp>
|
||||||
|
#include <locale>
|
||||||
#include <wx/clipbrd.h>
|
#include <wx/clipbrd.h>
|
||||||
#include <wx/msgdlg.h>
|
#include <wx/msgdlg.h>
|
||||||
#include <wx/stackwalk.h>
|
#include <wx/stackwalk.h>
|
||||||
|
@ -119,14 +119,29 @@ bool AegisubApp::OnInit() {
|
||||||
// be created now
|
// be created now
|
||||||
(void)wxLog::GetActiveTarget();
|
(void)wxLog::GetActiveTarget();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
{
|
||||||
// When launched from Finder, boost::locale fails to get the correct locale
|
// Try to get the UTF-8 version of the current locale
|
||||||
// and falls back to "C", which of course doesn't support unicode
|
auto locale = boost::locale::generator().generate("");
|
||||||
std::locale::global(boost::locale::generator().generate("en_US.UTF-8"));
|
|
||||||
#else
|
// Check if we actually got a UTF-8 locale
|
||||||
// Set the global locale to the utf-8 version of the current locale
|
using codecvt = std::codecvt<wchar_t, char, std::mbstate_t>;
|
||||||
std::locale::global(boost::locale::generator().generate(""));
|
int result = std::codecvt_base::error;
|
||||||
#endif
|
if (std::has_facet<codecvt>(locale)) {
|
||||||
|
wchar_t test[] = L"\xFFFE";
|
||||||
|
char buff[8];
|
||||||
|
auto mb = std::mbstate_t();
|
||||||
|
const wchar_t* from_next;
|
||||||
|
char* to_next;
|
||||||
|
result = std::use_facet<codecvt>(locale).out(mb,
|
||||||
|
test, std::end(test), from_next,
|
||||||
|
buff, std::end(buff), to_next);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we didn't get a UTF-8 locale, force it to a known one
|
||||||
|
if (result != std::codecvt_base::ok)
|
||||||
|
locale = boost::locale::generator().generate("en_US.UTF-8");
|
||||||
|
std::locale::global(locale);
|
||||||
|
}
|
||||||
|
|
||||||
boost::filesystem::path::imbue(std::locale());
|
boost::filesystem::path::imbue(std::locale());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue