Laserlicht пре 2 година
родитељ
комит
2f64457a9a
3 измењених фајлова са 32 додато и 40 уклоњено
  1. 0 11
      android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java
  2. 24 21
      lib/Languages.h
  3. 8 8
      lib/vstd/DateUtils.cpp

+ 0 - 11
android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java

@@ -17,9 +17,6 @@ import org.libsdl.app.SDLActivity;
 
 import java.io.File;
 import java.lang.ref.WeakReference;
-import java.util.Date;
-import java.util.Locale;
-import java.text.SimpleDateFormat;
 
 import eu.vcmi.vcmi.util.Log;
 
@@ -156,14 +153,6 @@ public class NativeMethods
         }
     }
 
-    @SuppressWarnings(Const.JNI_METHOD_SUPPRESS)
-    public static String getFormattedDateTime()
-    {
-        String currentDate = new SimpleDateFormat((new SimpleDateFormat()).toLocalizedPattern(), Locale.getDefault()).format(new Date());
-
-        return currentDate;
-    }
-
     private static void internalProgressDisplay(final boolean show)
     {
         final Context ctx = SDL.getContext();

+ 24 - 21
lib/Languages.h

@@ -57,6 +57,9 @@ struct Options
 	/// primary IETF language tag
 	std::string tagIETF;
 
+	/// POSIX locale
+	std::string locale;
+
 	/// VCMI supports translations into this language
 	bool hasTranslation = false;
 };
@@ -65,27 +68,27 @@ inline const auto & getLanguageList()
 {
 	static const std::array<Options, 20> languages
 	{ {
-		{ "czech",      "Czech",      "Čeština",    "CP1250", "cs", true },
-		{ "chinese",    "Chinese",    "简体中文",       "GBK",    "zh", true }, // Note: actually Simplified Chinese
-		{ "english",    "English",    "English",    "CP1252", "en", true },
-		{ "finnish",    "Finnish",    "Suomi",      "CP1252", "fi", true },
-		{ "french",     "French",     "Français",   "CP1252", "fr", true },
-		{ "german",     "German",     "Deutsch",    "CP1252", "de", true },
-		{ "hungarian",  "Hungarian",  "Magyar",     "CP1250", "hu", true },
-		{ "italian",    "Italian",    "Italiano",   "CP1250", "it", true },
-		{ "korean",     "Korean",     "한국어",        "CP949",  "ko", true },
-		{ "polish",     "Polish",     "Polski",     "CP1250", "pl", true },
-		{ "portuguese", "Portuguese", "Português",  "CP1252", "pt", true }, // Note: actually Brazilian Portuguese
-		{ "russian",    "Russian",    "Русский",    "CP1251", "ru", true },
-		{ "spanish",    "Spanish",    "Español",    "CP1252", "es", true },
-		{ "swedish",    "Swedish",    "Svenska",    "CP1252", "sv", true },
-		{ "turkish",    "Turkish",    "Türkçe",     "CP1254", "tr", true },
-		{ "ukrainian",  "Ukrainian",  "Українська", "CP1251", "uk", true },
-		{ "vietnamese",  "Vietnamese",  "Tiếng Việt", "UTF-8", "vi", true }, // Fan translation uses special encoding
-
-		{ "other_cp1250", "Other (East European)",   "", "CP1250", "", false },
-		{ "other_cp1251", "Other (Cyrillic Script)", "", "CP1251", "", false },
-		{ "other_cp1252", "Other (West European)",   "", "CP1252", "", false }
+		{ "czech",      "Czech",      "Čeština",    "CP1250", "cs", "cs_CZ.UTF-8", true },
+		{ "chinese",    "Chinese",    "简体中文",       "GBK",    "zh", "zh_CN.UTF-8", true }, // Note: actually Simplified Chinese
+		{ "english",    "English",    "English",    "CP1252", "en", "en_US.UTF-8", true },
+		{ "finnish",    "Finnish",    "Suomi",      "CP1252", "fi", "fi_FI.UTF-8", true },
+		{ "french",     "French",     "Français",   "CP1252", "fr", "fr_FR.UTF-8", true },
+		{ "german",     "German",     "Deutsch",    "CP1252", "de", "de_DE.UTF-8", true },
+		{ "hungarian",  "Hungarian",  "Magyar",     "CP1250", "hu", "hu_HU.UTF-8", true },
+		{ "italian",    "Italian",    "Italiano",   "CP1250", "it", "it_IT.UTF-8", true },
+		{ "korean",     "Korean",     "한국어",        "CP949",  "ko", "ko_KR.UTF-8", true },
+		{ "polish",     "Polish",     "Polski",     "CP1250", "pl", "pl_PL.UTF-8", true },
+		{ "portuguese", "Portuguese", "Português",  "CP1252", "pt", "pt_BR.UTF-8", true }, // Note: actually Brazilian Portuguese
+		{ "russian",    "Russian",    "Русский",    "CP1251", "ru", "ru_RU.UTF-8", true },
+		{ "spanish",    "Spanish",    "Español",    "CP1252", "es", "es_ES.UTF-8", true },
+		{ "swedish",    "Swedish",    "Svenska",    "CP1252", "sv", "sv_SE.UTF-8", true },
+		{ "turkish",    "Turkish",    "Türkçe",     "CP1254", "tr", "tr_TR.UTF-8", true },
+		{ "ukrainian",  "Ukrainian",  "Українська", "CP1251", "uk", "uk_UA.UTF-8", true },
+		{ "vietnamese",  "Vietnamese",  "Tiếng Việt", "UTF-8", "vi", "vi_VN.UTF-8", true }, // Fan translation uses special encoding
+
+		{ "other_cp1250", "Other (East European)",   "", "CP1250", "", "", false },
+		{ "other_cp1251", "Other (Cyrillic Script)", "", "CP1251", "", "", false },
+		{ "other_cp1252", "Other (West European)",   "", "CP1252", "", "", false }
 	} };
 	static_assert(languages.size() == static_cast<size_t>(ELanguages::COUNT), "Languages array is missing a value!");
 

+ 8 - 8
lib/vstd/DateUtils.cpp

@@ -1,9 +1,8 @@
 #include "StdInc.h"
 #include <vstd/DateUtils.h>
 
-#if defined(VCMI_ANDROID)
-#include "../CAndroidVMHelper.h"
-#endif
+#include "../CConfigHandler.h"
+#include "../Languages.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 
@@ -12,16 +11,17 @@ namespace vstd
 
 	DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt)
 	{
-#if defined(VCMI_ANDROID)
-		CAndroidVMHelper vmHelper;
-		return vmHelper.callStaticStringMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "getFormattedDateTime");
-#endif
+		std::string lang = settings["general"]["language"].String();
+		std::string locale = Languages::getLanguageOptions(lang).locale;
 
 		std::tm tm = *std::localtime(&dt);
 		std::stringstream s;
 		try
 		{
-			s.imbue(std::locale(""));
+			if(locale.empty())
+				s.imbue(std::locale(""));
+			else
+				s.imbue(std::locale(locale));
 		}
 		catch(const std::runtime_error & e)
 		{