From 7b7ee41e13372fbbbb0fb5ab49cb95cbfd02577c Mon Sep 17 00:00:00 2001 From: Viktar Lukashonak Date: Thu, 12 May 2022 19:04:45 +0300 Subject: [PATCH 1/6] Waybar. Issue#1552. Calendar module, LC_TIME variable --- src/modules/clock.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 69fdebb1..c4c460cc 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -69,7 +69,14 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) if (config_["locale"].isString()) { locale_ = std::locale(config_["locale"].asString()); } else { - locale_ = std::locale(""); + char* sysLocale{getenv("LC_TIME")}; + try { + locale_ = sysLocale ? std::locale(sysLocale) : std::locale(""); + } + catch(std::runtime_error const& localeErr) { + spdlog::warn(localeErr.what()); + locale_ = std::locale(); + } } thread_ = [this] { From 448b413eca7022be7580e28719ded6e0ee147694 Mon Sep 17 00:00:00 2001 From: Viktar Lukashonak Date: Fri, 13 May 2022 12:54:18 +0300 Subject: [PATCH 2/6] Issue#1552. Calendar module, LC_TIME variable --- src/modules/clock.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index c4c460cc..5fda73f2 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -66,17 +66,12 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) } } - if (config_["locale"].isString()) { - locale_ = std::locale(config_["locale"].asString()); - } else { - char* sysLocale{getenv("LC_TIME")}; - try { - locale_ = sysLocale ? std::locale(sysLocale) : std::locale(""); - } - catch(std::runtime_error const& localeErr) { - spdlog::warn(localeErr.what()); - locale_ = std::locale(); - } + const char* applyLocale{config_["locale"].isString() ? config_["locale"].asCString() : getenv("LC_TIME")}; + try { + locale_ = applyLocale ? std::locale(applyLocale) : std::locale(""); + } catch(std::runtime_error const& localeE) { + spdlog::warn("Clock module. Wrong \"locale\" or LC_TIME variable(make sure locale is presented in /etc/locale.gen and generated by the locale-gen). Trace: {0}", localeE.what()); + locale_ = std::locale(); } thread_ = [this] { From e615612bf44e71584931bf5d5b03bde0411c9de1 Mon Sep 17 00:00:00 2001 From: Viktar Lukashonak Date: Fri, 13 May 2022 18:51:32 +0300 Subject: [PATCH 3/6] Calendar module: localization issue #1552 --- src/modules/clock.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 5fda73f2..86ffed28 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -232,10 +232,12 @@ auto waybar::modules::Clock::calendar_text(const waybar_time& wtime) -> std::str } else os << date::format("%e", d); /*Print weeks on the right when the endings with spaces*/ - if (ws == 2 && d == last_day && wd.c_encoding() < 6) { - empty_days = 6 - wd.c_encoding(); - os << std::string(empty_days * 3 + 1, ' '); - print_iso_weeknum(os, wn); + if (ws == 2 && d == last_day) { + empty_days = 6 - (wd.c_encoding() - first_dow.c_encoding()); + if(empty_days > 0) { + os << std::string(empty_days * 3 + 1, ' '); + print_iso_weeknum(os, wn); + } } } @@ -293,7 +295,7 @@ auto waybar::modules::Clock::timezones_text(std::chrono::system_clock::time_poin auto waybar::modules::Clock::print_iso_weeknum(std::ostream& os, int weeknum) -> void { std::stringstream res; - res << 'W' << std::setfill('0') << std::setw(2) << weeknum; + res << std::setfill('0') << std::setw(2) << weeknum; if (config_["format-calendar-weeks"].isString()) { os << fmt::format(config_["format-calendar-weeks"].asString(), res.str()); From 5a014305ec1d82952d22429bc218c1ad16e3ecc0 Mon Sep 17 00:00:00 2001 From: Viktar Lukashonak Date: Fri, 13 May 2022 22:58:00 +0300 Subject: [PATCH 4/6] Revert "Issue#1552. Calendar module, LC_TIME variable" This reverts commit 448b413eca7022be7580e28719ded6e0ee147694. --- src/modules/clock.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 86ffed28..92061f53 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -66,12 +66,17 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) } } - const char* applyLocale{config_["locale"].isString() ? config_["locale"].asCString() : getenv("LC_TIME")}; - try { - locale_ = applyLocale ? std::locale(applyLocale) : std::locale(""); - } catch(std::runtime_error const& localeE) { - spdlog::warn("Clock module. Wrong \"locale\" or LC_TIME variable(make sure locale is presented in /etc/locale.gen and generated by the locale-gen). Trace: {0}", localeE.what()); - locale_ = std::locale(); + if (config_["locale"].isString()) { + locale_ = std::locale(config_["locale"].asString()); + } else { + char* sysLocale{getenv("LC_TIME")}; + try { + locale_ = sysLocale ? std::locale(sysLocale) : std::locale(""); + } + catch(std::runtime_error const& localeErr) { + spdlog::warn(localeErr.what()); + locale_ = std::locale(); + } } thread_ = [this] { From bd0f6128d35dc0998da801e1292a27c23976cf19 Mon Sep 17 00:00:00 2001 From: Viktar Lukashonak Date: Fri, 13 May 2022 22:58:38 +0300 Subject: [PATCH 5/6] Revert "Waybar. Issue#1552. Calendar module, LC_TIME variable" This reverts commit 7b7ee41e13372fbbbb0fb5ab49cb95cbfd02577c. --- src/modules/clock.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 92061f53..3f2bf966 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -69,14 +69,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) if (config_["locale"].isString()) { locale_ = std::locale(config_["locale"].asString()); } else { - char* sysLocale{getenv("LC_TIME")}; - try { - locale_ = sysLocale ? std::locale(sysLocale) : std::locale(""); - } - catch(std::runtime_error const& localeErr) { - spdlog::warn(localeErr.what()); - locale_ = std::locale(); - } + locale_ = std::locale(""); } thread_ = [this] { From 315ea991bc2cb59089de0b8517a6c999bca805c5 Mon Sep 17 00:00:00 2001 From: Viktar Lukashonak Date: Fri, 13 May 2022 23:56:08 +0300 Subject: [PATCH 6/6] Calendar module: localization issue #1552 Linter #60 --- src/modules/clock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 3f2bf966..5d42402a 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -232,7 +232,7 @@ auto waybar::modules::Clock::calendar_text(const waybar_time& wtime) -> std::str /*Print weeks on the right when the endings with spaces*/ if (ws == 2 && d == last_day) { empty_days = 6 - (wd.c_encoding() - first_dow.c_encoding()); - if(empty_days > 0) { + if (empty_days > 0) { os << std::string(empty_days * 3 + 1, ' '); print_iso_weeknum(os, wn); }