Skip to content

Commit b6a7707

Browse files
committed
fix: simplify UTF-8 encoding setup for Windows compatibility
- Remove nested try-catch blocks and setenv() calls (not available on Windows) - Simplify locale setup to basic setlocale() call - Fix Windows compilation issues from previous PR
1 parent d58d455 commit b6a7707

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

app/src/main.cpp

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#include <borealis.hpp>
2-
#include <locale>
32
#include <clocale>
4-
#include <cstdlib>
5-
#ifndef _WIN32
6-
#include <unistd.h>
7-
#endif
83
#ifdef _WIN32
94
#include <windows.h>
105
#endif
@@ -46,35 +41,12 @@
4641
using namespace brls::literals; // for _i18n
4742

4843
int main(int argc, char* argv[]) {
49-
// Set UTF-8 locale for proper character encoding (fixes Croatian, Arabic, and other Unicode characters)
50-
// This must be done before any file I/O or text operations
51-
#if !defined(__PS4__) && !defined(__PSV__) && !defined(__SWITCH__)
52-
// Set environment variables first
53-
setenv("LC_ALL", "en_US.UTF-8", 1);
54-
setenv("LANG", "en_US.UTF-8", 1);
55-
56-
try {
57-
// Try to set UTF-8 locale
58-
std::locale::global(std::locale("en_US.UTF-8"));
59-
std::setlocale(LC_ALL, "en_US.UTF-8");
60-
} catch (...) {
61-
// Fallback: try C.UTF-8 or just UTF-8
62-
try {
63-
setenv("LC_ALL", "C.UTF-8", 1);
64-
setenv("LANG", "C.UTF-8", 1);
65-
std::locale::global(std::locale("C.UTF-8"));
66-
std::setlocale(LC_ALL, "C.UTF-8");
67-
} catch (...) {
68-
// On some systems, just set UTF-8 for specific categories
69-
std::setlocale(LC_CTYPE, "UTF-8");
70-
std::setlocale(LC_ALL, "");
71-
}
72-
}
44+
// Set UTF-8 locale for proper character encoding
45+
#if !defined(__PS4__) && !defined(__PSV__) && !defined(__SWITCH__) && !defined(_WIN32)
46+
std::setlocale(LC_ALL, "C.UTF-8");
7347
#elif defined(_WIN32)
74-
// Windows: Set UTF-8 code page
7548
SetConsoleOutputCP(CP_UTF8);
7649
SetConsoleCP(CP_UTF8);
77-
// Also set locale
7850
std::setlocale(LC_ALL, ".UTF8");
7951
#endif
8052

0 commit comments

Comments
 (0)