diff --git a/Packages/OpenCCBridge/Sources/OpenCCBridge/OpenCCBridge.swift b/Packages/OpenCCBridge/Sources/OpenCCBridge/OpenCCBridge.swift index 18ea60dd..6bb93d71 100644 --- a/Packages/OpenCCBridge/Sources/OpenCCBridge/OpenCCBridge.swift +++ b/Packages/OpenCCBridge/Sources/OpenCCBridge/OpenCCBridge.swift @@ -29,19 +29,21 @@ import OpenCC /// Since SwiftyOpenCC only provide Swift classes, we create an NSObject subclass /// in Swift in order to bridge the Swift classes into our Objective-C++ project. public class OpenCCBridge: NSObject { - private static let shared = OpenCCBridge() + + @objc public static let shared = OpenCCBridge() + private var converter: ChineseConverter? - private override init() { + override init() { try? converter = ChineseConverter(options: .simplify) super.init() } /// Converts to Simplified Chinese. - /// + /// /// - Parameter string: Text in Traditional Chinese. /// - Returns: Text in Simplified Chinese. - @objc public static func convertToSimplified(_ string: String) -> String? { - shared.converter?.convert(string) + @objc public func convertToSimplified(_ string: String) -> String? { + converter?.convert(string) } } diff --git a/Source/InputMethodController.swift b/Source/InputMethodController.swift index 7d091760..5ba4bac7 100644 --- a/Source/InputMethodController.swift +++ b/Source/InputMethodController.swift @@ -302,7 +302,7 @@ extension McBopomofoInputMethodController { if Preferences.chineseConversionStyle == 1 { return text } - return Preferences.chineseConversionEngine == 1 ? VXHanConvert.convertToSimplified(from: text) : OpenCCBridge.convertToSimplified(text) ?? "" + return Preferences.chineseConversionEngine == 1 ? VXHanConvert.convertToSimplified(from: text) : OpenCCBridge.shared.convertToSimplified(text) ?? "" } let buffer = convertToSimplifiedChineseIfRequired(text) diff --git a/Source/LanguageModelManager.mm b/Source/LanguageModelManager.mm index 9cef327e..c3ab3db3 100644 --- a/Source/LanguageModelManager.mm +++ b/Source/LanguageModelManager.mm @@ -114,7 +114,7 @@ + (void)setupDataModelValueConverter if (Preferences.chineseConversionEngine == 1) { text = [VXHanConvert convertToSimplifiedFrom:text]; } else { - text = [OpenCCBridge convertToSimplified:text]; + text = [[OpenCCBridge shared] convertToSimplified:text]; } return std::string(text.UTF8String); };