Merge 6d126d0acc
into 19f65187cb
This commit is contained in:
commit
bb3d86bea2
1 changed files with 27 additions and 0 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ANSI_COLOR_RED "\x1b[31m"
|
#define ANSI_COLOR_RED "\x1b[31m"
|
||||||
|
@ -52,6 +53,21 @@ namespace console {
|
||||||
static termios initial_state;
|
static termios initial_state;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
static bool locale_isvalid( const char * l )
|
||||||
|
{
|
||||||
|
return !(l == nullptr || l[0] == '\0' || (strcasestr(l, "utf-8") == nullptr && strcasestr(l, "utf8") == nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool locale_setverify( int c, const char * l )
|
||||||
|
{
|
||||||
|
setlocale(c, l);
|
||||||
|
auto locale = setlocale(c, nullptr);
|
||||||
|
|
||||||
|
return !strcmp( l, locale );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// Init and cleanup
|
// Init and cleanup
|
||||||
//
|
//
|
||||||
|
@ -115,6 +131,17 @@ namespace console {
|
||||||
}
|
}
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
auto locale = setlocale(LC_ALL, nullptr);
|
||||||
|
|
||||||
|
if (!locale_isvalid(locale)) {
|
||||||
|
auto lang = getenv("LANG");
|
||||||
|
if (!locale_isvalid(lang) || !locale_setverify(LC_ALL, lang)) {
|
||||||
|
locale_setverify(LC_ALL, "C.UTF-8") || locale_setverify(LC_ALL, "C.utf8") || setlocale(LC_ALL, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto usedlocale = setlocale(LC_ALL, nullptr);
|
||||||
|
fprintf(stderr,"Console: using '%s' locale.\n", usedlocale);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue