0

I'm doing the following to create a label that I use as part of attribution for a photo:

CCLabelTTF *imageSourceLabel = [CCLabelTTF labelWithString:[_organism imageSource] fontName:[[UIFont systemFontOfSize:12] fontName] fontSize:12];

Several of the image sources include Turkish letters. For example, in this URL:

http://commons.wikimedia.org/wiki/File:Şahlûr-33.jpg

This displays improperly in my iPad app; the Turkish letters are missing.

How do I create a label that will work with text like that in the URL above?


Edit:

Nevermind... the problem is with exporting from Excel. See the comments on the answer below. This link provides some additional information: Excel to CSV with UTF8 encoding


Additional Edit:

Actually, it's still a problem, even after I export correctly and verify that I have the proper UTF-8 (or is it 16?) letters in the CSV file. For example, this string:

Dûrzan cîrano / CC BY-SA 3.0

Is displayed like this:

incorrect turkish characters

and this string:

Christian Mehlführer / CC-BY 2.5

is displayed like this:

enter image description here

It's definitely being processed improperly upon import, as CCLOG generates the following:

Photo Credit: Dûrzan cîrano / CC BY-SA 3.0

More Info:

Upon import, I'm storing the following value as a string in an array:

"Christian Mehlf\U00c3\U00bchrer / CC-BY 2.5"

Wikipedia says the UTF-8 value for ü, in hex, is C3 BC. It looks like the c3bc is in there, but masked as \U00c3\U00bc.

Is there any way to convert this properly? Or is something fundamentally broken at the CSV import level?


The solution is below.

Community
  • 1
  • 1
Clay
  • 2,949
  • 3
  • 38
  • 54

2 Answers2

1

There were several problems:

  1. Excel on the Mac doesn't export UTF-8 properly. The solution I used was to paste the data into Google Spreadsheet and export from there. More info here: Excel to CSV with UTF8 encoding

  2. I realized that once I had the proper data in the CSV file, that I was importing it with the improper settings. I'm using parseCSV and needed to set _encoding in the -init method to NSUTF8StringEncoding instead of the default, NSISOLatin1StringEncoding.

Community
  • 1
  • 1
Clay
  • 2,949
  • 3
  • 38
  • 54
0

if you try this:

[CCLabelTTF labelWithString:[[_organism imageSource] stringByUnescapingHTML] fontName:[[UIFont systemFontOfSize:12] fontName] fontSize:12];

it will likely work better. I suspect your url string is escaped HTML.

Joshua Smith
  • 6,561
  • 1
  • 30
  • 28
  • Is `stringByUnescapingHTML` available on iOS? – Clay Apr 30 '13 at 04:16
  • Actually -- sort of never mind... I'm importing the string from a .csv file, exported from Excel. The characters are correct in Excel, but they are incorrect after export, in the .csv file. Hence, the problem has nothing to do with cocos2d. Nevertheless, I'm not sure how to fix the export issue from Excel. Thanks. – Clay Apr 30 '13 at 04:21
  • 1
    csv is a text format, unless you can instruct excel to export in utf16 format (not possible?) you need to use a different approach, perhaps openoffice can do that. Also check this: http://stackoverflow.com/questions/13019620/how-to-save-excel-file-as-csv-with-utf-16-formatting – CodeSmile Apr 30 '13 at 07:50
  • @LearnCocos2D Thanks for the link. It sounds like importing the Excel file to Google Spreadsheet and exporting to CSV from there might work, too. This question is relevant: http://stackoverflow.com/questions/4221176/excel-to-csv-with-utf8-encoding – Clay Apr 30 '13 at 13:53
  • @LearnCocos2D I provided more info at the bottom of the original question. Any more ideas? Thanks. – Clay Apr 30 '13 at 15:07