diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-03-16 18:33:49 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-03-16 18:33:49 +0100 |
| commit | 7c3b90eb9834ae605c679be2c240d36715225acc (patch) | |
| tree | 1114d70e857174daf0f8e9b8edd08dbe4e2037fe /src | |
| parent | 253c967318e6a75c6c4947b01f12ee3797db1b40 (diff) | |
locale loading unix
Diffstat (limited to 'src')
| -rw-r--r-- | src/fonts.cpp | 36 | ||||
| -rw-r--r-- | src/fonts.h | 5 | ||||
| -rw-r--r-- | src/unix/main_unix.cpp | 20 | ||||
| -rw-r--r-- | src/windows/main_windows.cpp | 37 |
4 files changed, 62 insertions, 36 deletions
diff --git a/src/fonts.cpp b/src/fonts.cpp index 3c1c520..34df8f4 100644 --- a/src/fonts.cpp +++ b/src/fonts.cpp @@ -9,6 +9,42 @@ #include <stdio.h> +ts_font_range ts_locale_to_range(wchar_t* buffer) { + ts_font_range result = FONT_RANGE_ENGLISH; + if (wcscmp(buffer, L"el-GR") == 0) result = FONT_RANGE_GREEK; + if (wcscmp(buffer, L"ko-KR") == 0) result = FONT_RANGE_KOREAN; + if (wcscmp(buffer, L"ja-JP") == 0) result = FONT_RANGE_JAPANESE; + + if (wcscmp(buffer, L"be-BY") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"bg-BG") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"ru-RU") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"ru-MD") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"ro-MD") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"kk-KZ") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"tt-RU") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"ky-KG") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"mn-MN") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"az-Cyrl-AZ") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"uz-Cyrl-UZ") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"sr-Cyrl-CS") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"sr-Latn-CS") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"az-AZ") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"uz-UZ") == 0) result = FONT_RANGE_CYRILLIC; + if (wcscmp(buffer, L"sr-CS") == 0) result = FONT_RANGE_CYRILLIC; + + if (wcscmp(buffer, L"bo-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; + if (wcscmp(buffer, L"zh-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; + if (wcscmp(buffer, L"mn-Mong-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; + if (wcscmp(buffer, L"zh-HK") == 0) result = FONT_RANGE_CHINESE_FULL; + if (wcscmp(buffer, L"zh-TW") == 0) result = FONT_RANGE_CHINESE_FULL; + if (wcscmp(buffer, L"zh-SG") == 0) result = FONT_RANGE_CHINESE_SIMPLE; + if (wcscmp(buffer, L"zh-MO") == 0) result = FONT_RANGE_CHINESE_FULL; + + if (wcscmp(buffer, L"th-TH") == 0) result = FONT_RANGE_THAI; + if (wcscmp(buffer, L"vi-VN") == 0) result = FONT_RANGE_VIETNAMESE; + return result; +} + void ts_load_fonts(float size, ts_font_range locale) { ImGuiIO& io = ImGui::GetIO(); ImFontConfig config; diff --git a/src/fonts.h b/src/fonts.h index 4a3bb93..ef2a23d 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -1,5 +1,7 @@ #pragma once +#include <wchar.h> + typedef enum t_ts_font_range { FONT_RANGE_ENGLISH, FONT_RANGE_GREEK, @@ -12,4 +14,5 @@ typedef enum t_ts_font_range { FONT_RANGE_VIETNAMESE, } ts_font_range; -void ts_load_fonts(float size, ts_font_range locale);
\ No newline at end of file +void ts_load_fonts(float size, ts_font_range locale); +ts_font_range ts_locale_to_range(wchar_t* locale);
\ No newline at end of file diff --git a/src/unix/main_unix.cpp b/src/unix/main_unix.cpp index 0c58d02..ef8dd88 100644 --- a/src/unix/main_unix.cpp +++ b/src/unix/main_unix.cpp @@ -8,6 +8,7 @@ #include "array.h" #include "memory_bucket.h" #include "image.h" +#include "fonts.h" #include "config.h" #include <stdio.h> #include <stdlib.h> @@ -15,6 +16,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> +#include <locale.h> #define GL_SILENCE_DEPRECATION #if defined(IMGUI_IMPL_OPENGL_ES2) #include <GLES2/gl2.h> @@ -69,6 +71,22 @@ static void drop_callback(GLFWwindow* window, int count, const char** paths) } } +ts_font_range _ts_get_font_range_to_load() { + wchar_t buffer[50] = {0}; + char* ll = setlocale(LC_ALL, NULL); + mbstowcs (buffer, ll, 50); + + wchar_t* iter = buffer; + while (*iter) { + if (*iter == ' ') *iter = 0; + if (*iter == '.') *iter = 0; + if (*iter == '@') *iter = 0; + iter++; + } + + return ts_locale_to_range(buffer); +} + // Main code int main(int, char**) { @@ -126,8 +144,8 @@ int main(int, char**) // Setup Dear ImGui style ImGui::Spectrum::StyleColorsSpectrum(); - ImGui::Spectrum::LoadFont(18.0f); + ts_load_fonts(18.0f, _ts_get_font_range_to_load()); ts_load_images(); ts_load_config(); diff --git a/src/windows/main_windows.cpp b/src/windows/main_windows.cpp index 3d136fb..becb1c1 100644 --- a/src/windows/main_windows.cpp +++ b/src/windows/main_windows.cpp @@ -110,41 +110,10 @@ void ts_platform_set_window_title(utf8_int8_t* str) { SetWindowTextW(window_handle, wchar_buffer); } -ts_font_range _ts_get_FONT_RANGE_to_load() { +ts_font_range _ts_get_font_range_to_load() { wchar_t buffer[50]; GetUserDefaultLocaleName(buffer, 50); - - ts_font_range result = FONT_RANGE_ENGLISH; - if (wcscmp(buffer, L"el-GR") == 0) result = FONT_RANGE_GREEK; - if (wcscmp(buffer, L"ko-KR") == 0) result = FONT_RANGE_KOREAN; - if (wcscmp(buffer, L"ja-JP") == 0) result = FONT_RANGE_JAPANESE; - - if (wcscmp(buffer, L"be-BY") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"bg-BG") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"ru-RU") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"ru-MD") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"ro-MD") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"kk-KZ") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"tt-RU") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"ky-KG") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"mn-MN") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"az-Cyrl-AZ") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"uz-Cyrl-UZ") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"sr-Cyrl-CS") == 0) result = FONT_RANGE_CYRILLIC; - if (wcscmp(buffer, L"sr-Latn-CS") == 0) result = FONT_RANGE_CYRILLIC; - - if (wcscmp(buffer, L"bo-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; - if (wcscmp(buffer, L"zh-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; - if (wcscmp(buffer, L"mn-Mong-CN") == 0) result = FONT_RANGE_CHINESE_SIMPLE; - if (wcscmp(buffer, L"zh-HK") == 0) result = FONT_RANGE_CHINESE_FULL; - if (wcscmp(buffer, L"zh-TW") == 0) result = FONT_RANGE_CHINESE_FULL; - if (wcscmp(buffer, L"zh-SG") == 0) result = FONT_RANGE_CHINESE_SIMPLE; - if (wcscmp(buffer, L"zh-MO") == 0) result = FONT_RANGE_CHINESE_FULL; - - if (wcscmp(buffer, L"th-TH") == 0) result = FONT_RANGE_THAI; - if (wcscmp(buffer, L"vi-VN") == 0) result = FONT_RANGE_VIETNAMESE; - - return result; + return ts_locale_to_range(buffer); } int main(int, char**) @@ -194,7 +163,7 @@ int main(int, char**) QueryPerformanceFrequency(&Frequency); - ts_load_fonts(18.0f, _ts_get_FONT_RANGE_to_load()); + ts_load_fonts(18.0f, _ts_get_font_range_to_load()); ts_load_images(); ts_load_config(); |
