1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-21 17:17:06 +02:00

another approach

This commit is contained in:
Laserlicht 2023-09-24 12:54:35 +02:00 committed by GitHub
parent a4769782c5
commit 2f64457a9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 39 deletions

View File

@ -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();

View File

@ -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
{ "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 }
{ "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!");

View File

@ -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)
{