From 79d2154fa27376c6328ec739a5f77e2ca9f3ab6a Mon Sep 17 00:00:00 2001 From: fxliang Date: Fri, 11 Aug 2023 17:48:17 +0800 Subject: [PATCH] fixed: opencc does not work under Windows, when opencc files in a path code page incompatible with UTF-8. example path with Chinese characters. --- src/rime/gear/simplifier.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rime/gear/simplifier.cc b/src/rime/gear/simplifier.cc index 4ff3c7514..2d38a5f63 100644 --- a/src/rime/gear/simplifier.cc +++ b/src/rime/gear/simplifier.cc @@ -25,6 +25,11 @@ #include #include +#ifdef WIN32 +#include +namespace fs = boost::filesystem; +#endif + static const char* quote_left = "\xe3\x80\x94"; //"\xef\xbc\x88"; static const char* quote_right = "\xe3\x80\x95"; //"\xef\xbc\x89"; @@ -36,7 +41,14 @@ class Opencc { LOG(INFO) << "initializing opencc: " << config_path; opencc::Config config; try { + // windows config_path in CP_ACP, convert it to UTF-8 +#ifdef WIN32 + fs::path path{config_path}; + converter_ = + config.NewFromFile(opencc::UTF8Util::U16ToU8(path.wstring())); +#else converter_ = config.NewFromFile(config_path); +#endif /* WIN32 */ const list conversions = converter_->GetConversionChain()->GetConversions(); dict_ = conversions.front()->GetDict();