Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed: opencc does not work under Windows, when opencc files in a path code page incompatible with UTF-8. #689

Merged
merged 1 commit into from
Aug 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/rime/gear/simplifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include <opencc/Dict.hpp>
#include <opencc/DictEntry.hpp>

#ifdef WIN32
#include <opencc/UTF8Util.hpp>
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";

Expand All @@ -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<opencc::ConversionPtr> conversions =
converter_->GetConversionChain()->GetConversions();
dict_ = conversions.front()->GetDict();
Expand Down