From 61795e0463d9e6e782332915c5ceeb1b541b666f Mon Sep 17 00:00:00 2001 From: XProger Date: Sun, 24 Feb 2019 00:29:13 +0300 Subject: [PATCH] Linux automatic language selector --- src/platform/nix/build.sh | 2 +- src/platform/nix/main.cpp | 23 +++++++++++++++++++++++ src/utils.h | 3 ++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/platform/nix/build.sh b/src/platform/nix/build.sh index f84633e..6801d59 100755 --- a/src/platform/nix/build.sh +++ b/src/platform/nix/build.sh @@ -1,3 +1,3 @@ set -e -clang++ -std=c++11 -Os -s -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections -DNDEBUG -D_POSIX_THREADS -D_POSIX_READER_WRITER_LOCKS main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/minimp3/minimp3.cpp ../../libs/tinf/tinflate.c -I../../ -o../../../bin/OpenLara -lX11 -lGL -lm -lpthread -lpulse-simple -lpulse +clang++ -std=c++11 -Os -s -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections -Wno-invalid-source-encoding -DNDEBUG -D_POSIX_THREADS -D_POSIX_READER_WRITER_LOCKS main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/minimp3/minimp3.cpp ../../libs/tinf/tinflate.c -I../../ -o../../../bin/OpenLara -lX11 -lGL -lm -lpthread -lpulse-simple -lpulse strip ../../../bin/OpenLara --strip-all --remove-section=.comment --remove-section=.note diff --git a/src/platform/nix/main.cpp b/src/platform/nix/main.cpp index 0f52ce5..0f35a0d 100644 --- a/src/platform/nix/main.cpp +++ b/src/platform/nix/main.cpp @@ -353,6 +353,27 @@ void WndProc(const XEvent &e,Display*dpy,Window wnd) { } } +int checkLanguage() { + char *lang = getenv("LANG"); + if (!lang || strlen(lang) < 2) return 0; + + uint16 id; + memcpy(&id, lang, 2); + + if (id == TWOCC("en")) return STR_LANG_EN - STR_LANG_EN; + if (id == TWOCC("fr")) return STR_LANG_FR - STR_LANG_EN; + if (id == TWOCC("de")) return STR_LANG_DE - STR_LANG_EN; + if (id == TWOCC("es")) return STR_LANG_ES - STR_LANG_EN; + if (id == TWOCC("it")) return STR_LANG_IT - STR_LANG_EN; + if (id == TWOCC("pl")) return STR_LANG_PL - STR_LANG_EN; + if (id == TWOCC("uk")) return STR_LANG_RU - STR_LANG_EN; + if (id == TWOCC("be")) return STR_LANG_RU - STR_LANG_EN; + if (id == TWOCC("ru")) return STR_LANG_RU - STR_LANG_EN; + if (id == TWOCC("ja")) return STR_LANG_JA - STR_LANG_EN; + + return 0; +} + int main(int argc, char **argv) { cacheDir[0] = saveDir[0] = contentDir[0] = 0; @@ -405,6 +426,8 @@ int main(int argc, char **argv) { gettimeofday(&t, NULL); startTime = t.tv_sec; + Core::defLang = checkLanguage(); + joyInit(); sndInit(); Game::init(argc > 1 ? argv[1] : NULL); diff --git a/src/utils.h b/src/utils.h index 27d0f7c..528a9b4 100644 --- a/src/utils.h +++ b/src/utils.h @@ -95,7 +95,8 @@ typedef unsigned short uint16; typedef unsigned int uint32; typedef unsigned long long uint64; -#define FOURCC(str) uint32(((uint8*)(str))[0] | (((uint8*)(str))[1] << 8) | (((uint8*)(str))[2] << 16) | (((uint8*)(str))[3] << 24) ) +#define FOURCC(str) uint32( ((uint8*)(str))[0] | (((uint8*)(str))[1] << 8) | (((uint8*)(str))[2] << 16) | (((uint8*)(str))[3] << 24) ) +#define TWOCC(str) uint32( ((uint8*)(str))[0] | (((uint8*)(str))[1] << 8) ) #define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1)) #define COUNT(arr) int(sizeof(arr) / sizeof(arr[0]))