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

Make OpenCCBridge.shared a public static var #373

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions Packages/OpenCCBridge/Sources/OpenCCBridge/OpenCCBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ 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(sharedInstance) public static let shared = OpenCCBridge()

private var converter: ChineseConverter?

private override init() {
Expand All @@ -38,10 +40,10 @@ public class OpenCCBridge: NSObject {
}

/// 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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import XCTest
final class OpenCCBridgeTests: XCTestCase {
func testTC2SC() throws {
let text = "繁體中文轉簡體中文"
let converted = OpenCCBridge.convertToSimplified(text)
let converted = OpenCCBridge.shared.convertToSimplified(text)
XCTAssert(converted == "繁体中文转简体中文")
}
}
2 changes: 1 addition & 1 deletion Source/InputMethodController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Source/LanguageModelManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ + (void)setupDataModelValueConverter
if (Preferences.chineseConversionEngine == 1) {
text = [VXHanConvert convertToSimplifiedFrom:text];
} else {
text = [OpenCCBridge convertToSimplified:text];
text = [[OpenCCBridge sharedInstance] convertToSimplified:text];
}
return std::string(text.UTF8String);
};
Expand Down