From 2cc0ec0a661a87704362734611dddaa1146fb993 Mon Sep 17 00:00:00 2001 From: Sebastian Zerbe Date: Fri, 1 Sep 2023 02:14:13 +0200 Subject: [PATCH] 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 --- data/config | 3 +++ src/Config.cpp | 1 + src/Config.h | 1 + src/System.cpp | 1 + 4 files changed, 6 insertions(+) diff --git a/data/config b/data/config index 4b6aa37..b8be032 100644 --- a/data/config +++ b/data/config @@ -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 diff --git a/src/Config.cpp b/src/Config.cpp index 66bfd3d..fa46539 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -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++) { diff --git a/src/Config.h b/src/Config.h index 26d82d3..37fd32f 100644 --- a/src/Config.h +++ b/src/Config.h @@ -16,6 +16,7 @@ public: std::vector workspaceSymbols = std::vector(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 diff --git a/src/System.cpp b/src/System.cpp index d098bc9..0d9d202 100644 --- a/src/System.cpp +++ b/src/System.cpp @@ -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(); }