Created
May 20, 2022 03:09
-
-
Save rijieli/01215f0d70576bc74e30060be5ef4d92 to your computer and use it in GitHub Desktop.
Transliterate Chinese between simplified and traditional (the wrong way).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
struct ChineseTransliterator { | |
static func transliterate(text: String, sourceView: UIView) { | |
let textView = UITextView() | |
textView.isHidden = true | |
textView.text = text | |
textView.selectAll(nil) | |
sourceView.addSubview(textView) | |
DispatchQueue.main.asyncAfter(deadline: .now()) { | |
textView.perform(NSSelectorFromString("_transliterateChinese:"), with: self) | |
print(textView.text ?? "") | |
textView.removeFromSuperview() | |
} | |
} | |
} | |
// Above was a joke, use the following | |
let input = "简体中文内容" | |
let output = input.applyingTransform( | |
StringTransform(rawValue: "Simplified-Traditional"), | |
reverse: false | |
) ?? input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment