1

I'm facing problem in formatting my strings for RTL & LTR Languages, following is the code

let nameEn = "English"
let obtained = 40
let offStr = "Out of"
var messageOne = String.localizedStringWithFormat("%@ %d %@ %d",nameEn,obtained,offStr,obtained+10)
let nameAr = "الإنجليزية"
let offStr2 = "بعيدا عن المكان"
let messageTwo = String.localizedStringWithFormat("%@ %d %@ %d",nameAr,obtained,offStr2,obtained+10)

result in messageOne

English 40 Out of 50

and for messageTwo it is enter image description here

but expected output is

الإنجليزية 40 من أصل 50

Any guess how Can I achieve that? I tried using unicode for RTL \u{200F}, it fixes problem for RTL but LTR gets disturbed by this, Is there a generic way to do this ?

Paebbels
  • 15,573
  • 13
  • 70
  • 139
Zubair
  • 915
  • 2
  • 9
  • 28
  • See my question https://stackoverflow.com/questions/38848130/combine-two-language-text – Prashant Tukadiya Feb 15 '18 at 12:20
  • @PrashantTukadiya I've already tried solution mentioned there, if I use `\u{200F}` in my formatting, then RTL output string out is fine, but it disturbs english & other LTR languages, I want a generic method for matting. – Zubair Feb 15 '18 at 12:23
  • You should create fuc in appdelegate which returns \u{200F}, for RTL and \u{200E}, for LTR in both cases you have to add some unicode – Prashant Tukadiya Feb 15 '18 at 12:35
  • @PrashantTukadiya that's what am doing right now, but I'm curious to find a generic way if there is any. – Zubair Feb 15 '18 at 12:39

0 Answers0