diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.h index 6c0982ce5..a304f41da 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.h @@ -16,6 +16,7 @@ #include "IImagePresenter.h" #include #include +#include namespace irr { @@ -112,6 +113,7 @@ namespace irr m_touch_id_map.clear(); } void setUpsideDown(bool val) { m_upside_down = val; } + static std::string getSystemLanguageCode(); private: void createWindow(); void createViewAndDriver(); diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm b/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm index be0655ba4..5f1f1a83b 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm @@ -858,6 +858,11 @@ namespace irr { [static_cast(DataStorage)->View display]; } + std::string CIrrDeviceiOS::getSystemLanguageCode() + { + NSString* language = [[NSLocale preferredLanguages] firstObject]; + return std::string([language UTF8String]); + } } #ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ diff --git a/src/utils/translation.cpp b/src/utils/translation.cpp index b442cabd6..9d4ca05c3 100644 --- a/src/utils/translation.cpp +++ b/src/utils/translation.cpp @@ -49,6 +49,9 @@ #include "main_android.hpp" #endif +#ifdef IOS_STK +#include "../../lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.h" +#endif // set to 1 to debug i18n #define TRANSLATE_VERBOSE 0 @@ -322,7 +325,14 @@ Translations::Translations() //: m_dictionary_manager("UTF-16") language = p_lang; else { -#ifdef WIN32 +#ifdef IOS_STK + language = irr::CIrrDeviceiOS::getSystemLanguageCode(); + if (language.find("zh-Hans") != std::string::npos) + language = "zh_CN"; + else if (language.find("zh-Hant") != std::string::npos) + language = "zh_TW"; + language = StringUtils::findAndReplace(language, "-", "_"); +#elif defined(WIN32) // Thanks to the frogatto developer for this code snippet: char c[1024]; GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME,