Read and write accents and Swedish Characters?

Hi,

I’m trying to print é, è, å,ä,ö etc but the symbols looks like garbage when I print them out to the console.

I read about using Sublime Text 2 but that doesn’t work either.

http://forums.coronalabs.com/topic/35356-accents-in-widgetnewbutton-label/

I have tried to save to UTF-8 and UTF-16. When I save to UTF-8 the program prints out garbage, with UTF-16 it doesn’t event start. I think that has to do with some invisible characters at the beginning but not sure.

I say this workaround but it’s something that I want to avoid as I will have several special characters and a lot of words with these special characters:

http://forums.coronalabs.com/topic/8617-how-to-use-accents-in-texcandy/

I’m using Windows 7, English language.

Any help is appreciated!

Best regards,

Tomas

Hi, Tomas

In what context are using different file encodings? Do you load text files into your app at runtime? Do you get the files in a download scenario? Are the files static in your app? Or is it the lua-files you are encoding?

(On a swedish mac, åäö prints perfectly directly from code…)

Bit hard to help without code. For my needs (sending over internet) I use this, perhaps you can to: http://developer.coronalabs.com/code/utf-8-encode-and-decode 

Hi,

In this example I just print it out:

http://i42.tinypic.com/b991er.png

I wrote that code in Notepad++ and I didn’t change any encoding so it was UTF-8 without BOM per default.

Best regards,

Tomas

Best regards,

Tomas

It might be that your Windows version is english. 

Do the special characters show correctly in the simulator as text? The user will never see the print statements anyway… 

Hi,

I will use these characters within the application as well. It’s a translation game and the words are taken from a database and if the word is “apple” a translation will come from the database as well which is “äpple” (Special character) and from the translation the program will find the appropriate images which represent that letters.

So for example the word apple will draw out images from a table and the “index” from that table are that letter so to get the five images I would draw from the table like this:

imageLocation["ä"] imageLocation["p"] imageLocation["p"] imageLocation["l"] imageLocation["e"]

and that table has the location to “ä.png”, “p.png” etc.

When I run this “display.newText(“ä”, 10,10)” the “ä” is displayed without any problems.

http://i43.tinypic.com/1ryfsn.png

The data looks good in the database however I’m not retrieving the information from the database yet, right now I just set the word statically to “äpple”. Then the word is being shuffled and I try to get the letter image like this:

display.newImage(letterLocation[string.upper(string.sub(shuffledWord, i,i))],(20) + (widthParameter \* 53), (display.contentHeight - 100) + heightParameter)

I will check the link above from jonjonsson as well and see what it says.

Best regards,

Tomas

ok.

From what i can understand there is nothing that hinders you from having a more indirect connection between the letter and the image itself.

When you ask for the letter ä, it could return the filename"letter_ae.png" like a dictionary.

From my experience it is always safer to skip using special characters in file names, since you can never be completely sure how different devices and platforms will handle it.

Lycka till!

Hi, Tomas

In what context are using different file encodings? Do you load text files into your app at runtime? Do you get the files in a download scenario? Are the files static in your app? Or is it the lua-files you are encoding?

(On a swedish mac, åäö prints perfectly directly from code…)

Bit hard to help without code. For my needs (sending over internet) I use this, perhaps you can to: http://developer.coronalabs.com/code/utf-8-encode-and-decode 

Hi,

In this example I just print it out:

http://i42.tinypic.com/b991er.png

I wrote that code in Notepad++ and I didn’t change any encoding so it was UTF-8 without BOM per default.

Best regards,

Tomas

Best regards,

Tomas

It might be that your Windows version is english. 

Do the special characters show correctly in the simulator as text? The user will never see the print statements anyway… 

Hi,

I will use these characters within the application as well. It’s a translation game and the words are taken from a database and if the word is “apple” a translation will come from the database as well which is “äpple” (Special character) and from the translation the program will find the appropriate images which represent that letters.

So for example the word apple will draw out images from a table and the “index” from that table are that letter so to get the five images I would draw from the table like this:

imageLocation["ä"] imageLocation["p"] imageLocation["p"] imageLocation["l"] imageLocation["e"]

and that table has the location to “ä.png”, “p.png” etc.

When I run this “display.newText(“ä”, 10,10)” the “ä” is displayed without any problems.

http://i43.tinypic.com/1ryfsn.png

The data looks good in the database however I’m not retrieving the information from the database yet, right now I just set the word statically to “äpple”. Then the word is being shuffled and I try to get the letter image like this:

display.newImage(letterLocation[string.upper(string.sub(shuffledWord, i,i))],(20) + (widthParameter \* 53), (display.contentHeight - 100) + heightParameter)

I will check the link above from jonjonsson as well and see what it says.

Best regards,

Tomas

ok.

From what i can understand there is nothing that hinders you from having a more indirect connection between the letter and the image itself.

When you ask for the letter ä, it could return the filename"letter_ae.png" like a dictionary.

From my experience it is always safer to skip using special characters in file names, since you can never be completely sure how different devices and platforms will handle it.

Lycka till!