ios Answer dialog and utf text from array?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

ios Answer dialog and utf text from array?

Post by strongbow » Wed Feb 08, 2012 3:03 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: ios Answer dialog and utf text from array?

Post by Mark » Wed Feb 08, 2012 3:39 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: ios Answer dialog and utf text from array?

Post by strongbow » Wed Feb 08, 2012 4:17 pm

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

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: ios Answer dialog and utf text from array?

Post by Klaus » Wed Feb 08, 2012 4:31 pm

I'm impatiently waiting for the day that RunRev promised, where "Unicode! It just works!" 8)

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: ios Answer dialog and utf text from array?

Post by Mark » Wed Feb 08, 2012 4:33 pm

Me too, Klaus. Me too. RealStudio has it. Why not LiveCode, I wonder?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: ios Answer dialog and utf text from array?

Post by strongbow » Wed Feb 08, 2012 4:38 pm

Me three, four and five!

Post Reply