Search code examples
iosswifttextmultilingual

Load text in Punjabi language in iOS


I have received response from back-end in the below mentioned form, I want to display content in Punjabi, Gurmukhi Punjabi and English language simultaneously,

  {
            "AK_Index" = "APNE SEVAK KEE AAPE RAKE";
            Ang = 747;
            Author = "Guru Arjan Dev Ji";
            Bani = "<null>";
            "Bani_ID" = "<null>";
            English = "Guru Nanak has met the Supreme Lord God; I am a sacrifice to Your Feet. ||4||1||47||";
            "English_Initials" = gnmptckb;
            Gurmukhi = "guru nwnku imilAw pwrbRhmu qyirAw crxw kau bilhwrw ]4]1]47]";
            "Gurmukhi_Initials" = "gnmpqckb]";
            ID = 32133;
            Kirtan = Kirtan;
            "Kirtan_ID" = 2853;
            Punjabi = "gurU nwnk Awpxy prm pRBU nUM iml ipAw hY Aqy aus dy pYrW qoN GolI jWdw hY[";
            Raag = "Raag Soohee";
            "Teeka_Arth" = "hy pRBU! mYN qyry crnW qoN sdky jWdw hW[ ijs mnu`K nUM gurU nwnk iml ipAw, aus nUM prmwqmw iml ipAw ]4]1]47]";
            "Teeka_Pad_Arth" = "kau = nUM, qoN ]4]1]47]";
        }
    

Attached is screenshot what the result would look like. The screenshot is from android. I want exact same result in iOS.

enter image description here How to achieve this in iOS. Any help will be appreciated.


Solution

  • Finally got it working using "Gurblipi.ttf" font which internally changes the English text to Punjabi language.

    let attributedString = NSMutableAttributedString()
    
    for shabadDetail in shabadDetailList {
        attributedString.append(NSMutableAttributedString(string: shabadDetail.gurmukhi, attributes: [NSAttributedStringKey.font : FontHelper.guruLippi(fontsize: textview.font!.pointSize), NSAttributedStringKey.foregroundColor: TextFormatting.gurbaniColor]))
        attributedString.append(NSAttributedString(string: TextFormatting.doubleLineBreak))
    }
    
    textview.attributedText = attributedString
    textview.textAlignment = .center
    

    No encoding is required from native or back-end.