48 lines
1.4 KiB
Diff
48 lines
1.4 KiB
Diff
From 78e2ba6f38de67917befdabfe9d40a910b02a88c Mon Sep 17 00:00:00 2001
|
||
From: liuxinhao <liuxinhao@kylinsec.com.cn>
|
||
Date: Fri, 15 Dec 2023 16:13:08 +0800
|
||
Subject: [PATCH 03/17] fix(LC_TIME): set LC_TIME to UTF-8
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
根据环境变量重新设置LC_TIME为UTF-8
|
||
|
||
Closes #21517,#24064
|
||
---
|
||
src/main.cpp | 18 ++++++++++++++++++
|
||
1 file changed, 18 insertions(+)
|
||
|
||
diff --git a/src/main.cpp b/src/main.cpp
|
||
index 05f7153..981fdbf 100644
|
||
--- a/src/main.cpp
|
||
+++ b/src/main.cpp
|
||
@@ -165,6 +165,24 @@ int main(int argc, char *argv[])
|
||
exit(EXIT_SUCCESS);
|
||
}
|
||
|
||
+ /// NOTE: 由于strftime获取系统locale进行格式化,Qt使用UTF8,若编码设置不为UTF8中文环境下会导致乱码
|
||
+ /// 所以LANG后面的编码若不为UTF-8,修改成UTF-8,使获取时间都为UTF-8格式
|
||
+ QString lang = qgetenv("LANG");
|
||
+ if (lang.contains("."))
|
||
+ {
|
||
+#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
|
||
+ QStringList splitRes = lang.split(".", QString::SkipEmptyParts);
|
||
+#else
|
||
+ QStringList splitRes = lang.split(".", Qt::SkipEmptyParts);
|
||
+#endif
|
||
+ if(splitRes.size() == 2 && splitRes.at(1)!="UTF-8" )
|
||
+ {
|
||
+ splitRes.replace(1, "UTF-8");
|
||
+ QString newLocale = splitRes.join(".");
|
||
+ setlocale(LC_TIME, newLocale.toStdString().c_str());
|
||
+ }
|
||
+ }
|
||
+
|
||
// 安装翻译
|
||
installTranslator();
|
||
|
||
--
|
||
2.33.0
|
||
|