-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalize.cpp
More file actions
55 lines (53 loc) · 1.33 KB
/
localize.cpp
File metadata and controls
55 lines (53 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "localize.hpp"
#include <clocale>
#include <filesystem>
#include <string>
#if defined(_WIN32)
#include <windows.h>
#elif defined(__APPLE__)
#include <mach-o/dyld.h>
#endif
void localizeInit() {
setlocale(LC_ALL, "");
bindtextdomain(
"craftive",
[&] -> std::string {
#ifdef _CRAFTIVE_DEBUG
#ifdef _CRAFTIVE_DEBUGGING_LOCALES_DIR
return _CRAFTIVE_DEBUGGING_LOCALES_DIR;
#else
return (std::filesystem::current_path() / "locales").string();
#endif
#else
#if defined(_WIN32) || defined(__APPLE__)
std::filesystem::path epath;
#if defined(_WIN32)
wchar_t wpath[MAX_PATH]{};
GetModuleFileNameW(nullptr, wpath, MAX_PATH);
epath = wpath;
#elif defined(__APPLE__)
char path[PATH_MAX];
auto size = sizeof(path);
_NSGetExecutablePath(path, &size);
epath = path;
#endif
if (epath.empty())
#if defined(_WIN32)
return (std::filesystem::current_path() / "locales").string();
#else
return "/usr/share/locale";
#endif
auto dir = epath.parent_path();
#if defined(__APPLE__)
dir = dir.parent_path() / "Resources";
#endif
return (dir / "locales").string();
#else
return "/usr/share/locale";
#endif
#endif
}().c_str()
);
bind_textdomain_codeset("craftive", "UTF-8");
textdomain("craftive");
}