2

Did anyone find a way to transliterate Kanji symbols into Latin (Romanization) in Swift?

let sourceText: String = "見る"
let regularAnswer: String = sourceText
let latinAnswer: String = regularAnswer.applyingTransform(.toLatin, reverse: false)!

print(regularAnswer) //prints: 見る
print(latinAnswer)   //prints: jiànru

Correct would be Miru instead of jiànru. It seems that swift has difficulties to distinct Chinese from Japanese here. I did not find any way to specify that. Thank you in advance!

pawello2222
  • 46,897
  • 22
  • 145
  • 209
NilsBerni
  • 83
  • 2
  • 13
  • 2
    I have spent about an hour googling and it seems there is just no support for Kanji transliteration. The problem is that this is not something developed by Apple, this is part of Unicode (http://userguide.icu-project.org/transforms/general#TOC-ICU-Transliterators). And it seems that proper transliteration of Kanji is not straightforward because it needs a dictionary of words – Sulthan Jul 28 '20 at 21:50
  • Thank you, you seem to have expertise in this. Do you know if there is a library or another way to get that done since I see google translate and other services seem to do it right. Or is the only way collecting all the Kanji transliterations manually? – NilsBerni Jul 29 '20 at 12:43
  • Yes, that's what a dictionary is. This is something easy for google or a cloud. This is not simple for an algorithmic solution. I am not an expert at all, I just googled for a bit and read the docs. – Sulthan Jul 29 '20 at 12:46

0 Answers0