Proper l10n for date/time

master
krzys-h 2016-04-09 18:23:57 +02:00
parent 14e2910f83
commit 139592bc00
8 changed files with 21 additions and 68 deletions

View File

@ -1813,9 +1813,13 @@ void CApplication::SetLanguage(Language language)
char* defaultLocale = setlocale(LC_ALL, ""); // Load system locale
GetLogger()->Debug("Default system locale: %s\n", defaultLocale);
if (!locale.empty()) // Override system locale?
{
setlocale(LC_ALL, locale.c_str());
}
setlocale(LC_NUMERIC, "C"); // Force numeric locale to "C" (fixes decimal point problems)
char* systemLocale = setlocale(LC_ALL, nullptr); // Get current locale configuration
GetLogger()->Debug("Setting locale: %s\n", systemLocale);
std::string systemLocale = setlocale(LC_ALL, nullptr); // Get current locale configuration
GetLogger()->Debug("Setting locale: %s\n", systemLocale.c_str());
// Update C++ locale
try
{

View File

@ -186,55 +186,6 @@ char GetToLower(char letter)
return tolower(letter);
}
// Converting time to string.
void TimeToAscii(time_t time, char *buffer)
{
struct tm when;
int year;
when = *localtime(&time);
year = when.tm_year+1900;
if ( year < 2000 ) year -= 1900;
else year -= 2000;
char format[10];
int hour;
hour = when.tm_hour; // 0..23
if ( hour < 12 ) // morning?
{
strcpy(format, "am");
}
else // afternoon?
{
strcpy(format, "pm");
hour -= 12; // 0..11
}
if ( hour == 0 ) hour = 12;
sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d %s",
when.tm_mon+1, when.tm_mday, year,
hour, when.tm_min, format);
}
// Converting time to string.
void TimeToAsciiClean(time_t time, char *buffer)
{
struct tm when;
int year;
when = *localtime(&time);
year = when.tm_year+1900;
if ( year < 2000 ) year -= 1900;
else year -= 2000;
sprintf(buffer, "%.2d%.2d%.2d%.2d%.2d",
year, when.tm_mon+1, when.tm_mday,
when.tm_hour, when.tm_min);
}
std::string TimeFormat(float time)
{
int minutes = floor(time/60);
@ -254,8 +205,3 @@ void AddExt(char* filename, const char* ext)
if ( strchr(filename, '.') != nullptr ) return; // already an extension?
strcat(filename, ext);
}
int GetCurrentTimestamp()
{
return std::chrono::seconds(std::time(nullptr)).count();
}

View File

@ -31,10 +31,6 @@ extern char GetNoAccent(char letter);
extern char GetToUpper(char letter);
extern char GetToLower(char letter);
extern void TimeToAscii(time_t time, char *buffer);
extern void TimeToAsciiClean(time_t time, char *buffer);
extern std::string TimeFormat(float time);
extern void AddExt(char* filename, const char* ext);
extern int GetCurrentTimestamp();

View File

@ -50,6 +50,10 @@ CLevelParserParam::CLevelParserParam(int value)
: m_value(boost::lexical_cast<std::string>(value))
{}
CLevelParserParam::CLevelParserParam(long value)
: m_value(boost::lexical_cast<std::string>(value))
{}
CLevelParserParam::CLevelParserParam(float value)
: m_value(boost::lexical_cast<std::string>(value))
{}

View File

@ -54,6 +54,7 @@ public:
//! Create param with given value
//@{
CLevelParserParam(int value);
CLevelParserParam(long value);
CLevelParserParam(float value);
CLevelParserParam(std::string value);
CLevelParserParam(bool value);

View File

@ -4646,7 +4646,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s
line = MakeUnique<CLevelParserLine>("Created");
line->AddParam("date", MakeUnique<CLevelParserParam>(GetCurrentTimestamp()));
line->AddParam("date", MakeUnique<CLevelParserParam>(time(nullptr)));
levelParser.AddLine(std::move(line));
line = MakeUnique<CLevelParserLine>("Mission");
@ -5700,7 +5700,8 @@ void CRobotMain::Autosave()
std::string dir = m_playerProfile->GetSaveFile("autosave" + boost::lexical_cast<std::string>(id));
char timestr[100];
TimeToAscii(time(nullptr), timestr);
time_t now = time(nullptr);
strftime(timestr, 99, "%x %X", localtime(&now));
std::string info = std::string("[AUTOSAVE] ")+timestr;
m_playerProfile->SaveScene(dir, info);

View File

@ -81,7 +81,7 @@ void CScreenIO::IOReadName()
}
time(&now);
TimeToAsciiClean(now, line);
strftime(line, 99, "%y%m%d%H%M", localtime(&now));
sprintf(name, "%s - %s %d", line, resume.c_str(), m_main->GetLevelRank());
pe->SetText(name);

View File

@ -1282,9 +1282,9 @@ void CStudio::AdjustDialog()
{
pli->SetPos(ppos);
pli->SetDim(ddim);
pli->SetTabs(0, ddim.x-(50.0f+130.0f+16.0f)/640.0f);
pli->SetTabs(0, ddim.x-(50.0f+140.0f+16.0f)/640.0f);
pli->SetTabs(1, 50.0f/640.0f, Gfx::TEXT_ALIGN_RIGHT);
pli->SetTabs(2, 130.0f/640.0f);
pli->SetTabs(2, 140.0f/640.0f);
//? pli->ShowSelect();
}
@ -1575,7 +1575,7 @@ void CStudio::UpdateDialogList()
CWindow* pw;
CList* pl;
int i = 0;
char time[100];
char timestr[100];
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9));
if ( pw == nullptr ) return;
@ -1590,8 +1590,9 @@ void CStudio::UpdateDialogList()
for (auto& prog : programs)
{
std::ostringstream temp;
TimeToAscii(CResourceManager::GetLastModificationTime(SearchDirectory(false) + prog), time);
temp << prog << '\t' << CResourceManager::GetFileSize(SearchDirectory(false) + prog) << " \t" << time;
time_t now = CResourceManager::GetLastModificationTime(SearchDirectory(false) + prog);
strftime(timestr, 99, "%x %X", localtime(&now));
temp << prog << '\t' << CResourceManager::GetFileSize(SearchDirectory(false) + prog) << " \t" << timestr;
pl->SetItemName(i++, temp.str().c_str());
}
}