From 31c05c5f848545fb126d342fa98244580aa0df15 Mon Sep 17 00:00:00 2001 From: lindeer Date: Wed, 30 Jul 2025 10:27:42 +0800 Subject: [PATCH 1/2] find config from env --- src/Config.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Config.cpp b/src/Config.cpp index 5c768c07c..839a99535 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -202,6 +202,15 @@ class ConfigInternal { } } + const char* envPath = std::getenv("OPENCC_DATA_DIR"); + if (envPath != nullptr) { + auto path = std::string(envPath) + '/' + fileName; + ifs.open(UTF8Util::GetPlatformString(path).c_str()); + if (ifs.is_open()) { + return path; + } + } + throw FileNotFound(fileName); } }; From 3f1c828be072ebac9bddc8c6c455ddedf7c4e991 Mon Sep 17 00:00:00 2001 From: lindeer Date: Wed, 25 Feb 2026 14:40:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=87=E6=A1=A3=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 64e2d1303..538dc5fda 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,13 @@ Document 文檔: https://byvoid.github.io/OpenCC/ * `jp2t.json` New Japanese Kanji (Shinjitai) to Traditional Chinese Characters (Kyūjitai) 日文新字體到繁體(OpenCC 標準,舊字體) * `tw2t.json` Traditional Chinese (Taiwan standard) to Traditional Chinese 臺灣正體到繁體(OpenCC 標準) +#### 指定配置文件 + +通过环境变量`OPENCC_DATA_DIR`加载指定路径下的配置文件 +```sh +OPENCC_DATA_DIR=/path/to/your/config/dir opencc --help +``` + ## Build 編譯 ### Build with CMake