ICU custom text transform (Tibetan-Latin)

I've been trying to figure out how to create a custom transform so I can implement it for the Tibetan language.

I know we can do something like this:

import Foundation
let shanghai = "上海"
shanghai.applyingTransform(.toLatin, reverse: false)
// → "shàng hǎi"

And I know I could build a StringTransform using ICU syntax like it was explained here:
https://oleb.net/blog/2016/01/icu-text-transforms/

But Any doesn't work for Tibetan.

import Foundation

var mutableString = NSMutableString(string: "ཆོས་")

var stringTransform = StringTransform(rawValue: "Any-Latin;")
var latinText = mutableString.applyingTransform(stringTransform, reverse: false)
//This doesnt work I would liek to have it be --> chos 
//The word is actually made out of the following characters:
//0: ཆ U+0F46     TIBETAN LETTER CHA
//1: ོ U+0F7C     TIBETAN VOWEL SIGN O
//2: ས U+0F66     TIBETAN LETTER SA

I'm not sure if it is possible to create custom transforms, anyone knows if its possible to view the code for some other transformation like Mandarin to Latin?
https://developer.apple.com/documentation/foundation/stringtransform/1409304-mandarintolatin

Or if this is not possible will I have to create a parser? or anyone has a better Idea.

Thanks for reading.

All of the custom string transforms are implemented in the ICU library; it sounds like they just don't have a Tibetan transliteration implemented. You'll have to do it by hand. (Or contribute to that library, though it's written in C.)

2 Likes

Oh, I see, that makes sense. Ok, I'll check what would be the process to add that transliteration to the ICU Library and if it'll be too complicated I'll go work on writing a parser in Swift.

Thanks for your reply @jrose

Terms of Service

Privacy Policy

Cookie Policy