Add config for time widget locale (#44)

This makes the `DateTimeStyle` string respect the current locale or
whatever valid locale is set via configuration option `DateTimeLocale`.

---------

Co-authored-by: Sebastian Zerbe <zerbe@phil.hhu.de>
This commit is contained in:
Sebastian Zerbe 2023-09-01 02:14:13 +02:00 committed by GitHub
parent aee06ab49d
commit 2cc0ec0a66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 0 deletions

View file

@ -60,6 +60,9 @@ TimeSpace: 300
# Set datetime style
# DateTimeStyle: %a %D - %H:%M:%S %Z
# Set datetime locale (defaults to system locale if not set or set to empty string)
# DateTimeLocale: de_DE.utf8
# Adds a audio input(aka. microphone) widget
AudioInput: false

View file

@ -177,6 +177,7 @@ void Config::Load()
AddConfigVar("BatteryFolder", config.batteryFolder, lineView, foundProperty);
AddConfigVar("DefaultWorkspaceSymbol", config.defaultWorkspaceSymbol, lineView, foundProperty);
AddConfigVar("DateTimeStyle", config.dateTimeStyle, lineView, foundProperty);
AddConfigVar("DateTimeLocale", config.dateTimeLocale, lineView, foundProperty);
AddConfigVar("CheckPackagesCommand", config.checkPackagesCommand, lineView, foundProperty);
for (int i = 1; i < 10; i++)
{

View file

@ -16,6 +16,7 @@ public:
std::vector<std::string> workspaceSymbols = std::vector<std::string>(9, "");
std::string defaultWorkspaceSymbol = "";
std::string dateTimeStyle = "%a %D - %H:%M:%S %Z"; // A sane default
std::string dateTimeLocale = ""; // use system locale
// Script that returns how many packages are out-of-date. The script should only print a number!
// See data/update.sh for a human-readable version

View file

@ -605,6 +605,7 @@ namespace System
time_t stdTime = time(NULL);
tm* localTime = localtime(&stdTime);
std::stringstream str;
str.imbue(std::locale(Config::Get().dateTimeLocale.c_str()));
str << std::put_time(localTime, Config::Get().dateTimeStyle.c_str());
return str.str();
}