Page 1 of 1

ios Answer dialog and utf text from array?

Posted: Wed Feb 08, 2012 3:03 pm
by strongbow
Hi all

I have what I think is a strange problem (obviously my lack of understanding at the moment...).

On iOS the answer dialog can display foreign characters like umlauts etc e.g. ü, ä, ö. However, when I have language strings containing these characters in an array, they do not seem to display correctly. Strangely they do appear in the console log correctly so I know they're stored in the array ok.

I tested it by just inserting a straight

answer "Bitte wählen Sie eine Station."

which works ok.

But when I use my function as follows, it doesn't work. It displays the text but with the umlaut displayed as "√§".

i.e. "Bitte w√§hlen Sie eine Station."

function is:

Code: Select all

on smAnswer pMsg
   -- display a message in correct current language
   -- gLang is an array of message keys and texts for current language.
   -- pMsg is the key for the text we want to extract.

   put gLang[pMsg] into tMsg
   if tMsg is empty then
      smLog "Error: could not find translation into " & gSMPrefs["Lang"] & " for string[" & pMsg & "]"
      answer pMsg
   else
     answer "Bitte wählen Sie eine Station."   -- THIS works ok but next line not.
      answer tMsg
   end if
end smAnswer
Any ideas? I've already tried variations on putting into a field and getting it from there, converting to/from UTF8 etc that is needed elsewhere... No doubt it's something simple that I've overlooked... I hope!

cheers

Alan

Re: ios Answer dialog and utf text from array?

Posted: Wed Feb 08, 2012 3:39 pm
by Mark
Hi Alan,

Probably you need to convert from UTF8 to text or maybe UTF16 to text. What is the encoding of the original string?

To convert, try one of these:

Code: Select all

put uniDecode(tMsg) into tMsg // UTF16
put uniDecode(uniEncode(tMsg,"UTF8")) into tMsg // UTF8
Kind regards,

Mark

Re: ios Answer dialog and utf text from array?

Posted: Wed Feb 08, 2012 4:17 pm
by strongbow
Hi Mark

Ahh, thanks for that. I'd actually tried a variation of that but I now realise that the one I'd used was for saving UTF8 to a file... oops.

So the key thing was converting the UTF8 encoded string to a single-byte string suitable for iOS answer dialog, using

put uniDecode(uniEncode(tMsg,"UTF8")) into tMsg

Thanks again for the quick response. :-)

cheers

Alan

Re: ios Answer dialog and utf text from array?

Posted: Wed Feb 08, 2012 4:31 pm
by Klaus
I'm impatiently waiting for the day that RunRev promised, where "Unicode! It just works!" 8)

Re: ios Answer dialog and utf text from array?

Posted: Wed Feb 08, 2012 4:33 pm
by Mark
Me too, Klaus. Me too. RealStudio has it. Why not LiveCode, I wonder?

Mark

Re: ios Answer dialog and utf text from array?

Posted: Wed Feb 08, 2012 4:38 pm
by strongbow
Me three, four and five!