فهرست منبع

Revert "another approach"

This reverts commit 2f64457a9a5b447fcc4a0060edeece0e4074b01a.
Laserlicht 2 سال پیش
والد
کامیت
e93a04409e
3فایلهای تغییر یافته به همراه40 افزوده شده و 32 حذف شده
  1. 11 0
      android/vcmi-app/src/main/java/eu/vcmi/vcmi/NativeMethods.java
  2. 21 24
      lib/Languages.h
  3. 8 8
      lib/vstd/DateUtils.cpp

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

@@ -17,6 +17,9 @@ 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;
 
@@ -153,6 +156,14 @@ 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();

+ 21 - 24
lib/Languages.h

@@ -57,9 +57,6 @@ struct Options
 	/// primary IETF language tag
 	std::string tagIETF;
 
-	/// POSIX locale
-	std::string locale;
-
 	/// VCMI supports translations into this language
 	bool hasTranslation = false;
 };
@@ -68,27 +65,27 @@ inline const auto & getLanguageList()
 {
 	static const std::array<Options, 20> languages
 	{ {
-		{ "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 }
+		{ "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 }
 	} };
 	static_assert(languages.size() == static_cast<size_t>(ELanguages::COUNT), "Languages array is missing a value!");
 

+ 8 - 8
lib/vstd/DateUtils.cpp

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