Created
May 8, 2021 09:22
-
-
Save zhaozzq/2e851ed3b1686530e634634f6ada63d3 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