views:

22

answers:

2

I'm using google translate with my website to translate short, frequently used phrases. Instead of asking google for a translation every time, I thought of caching the translations in a MySQL table.

Anyway, it works fine for latin characters, but fails for others like asian. What collation/charset would be the best to use?

Also - I've tried the default (latin1_swedish_ci) and utf8_unicode_ci

+2  A: 

One of those should do the trick: http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html

Also, as seen in the MySQL documentation:

Client applications that need to communicate with the server using Unicode should set the client character set accordingly; for example, by issuing a SET NAMES 'utf8' statement.

So, if you select the utf8_unicode_ci encoding, you will need to execute a SET NAMES 'utf8' query for every connection to your database (run it after a mysql_select_db() or whatever you're using).

Etienne de Martel
Oh I've tried ucs2 and utf8, but they don't work. It's probably PHP or the query that's losing the characters, or maybe it just doesn't support the exotic languages I'm testing it with. I think I'll treat the translations as binary data, and base64encode them or something.
Matt
Yeah, you also need to set it for the connection. I edited.
Etienne de Martel
Okay, I added mysql_query("SET NAMES 'utf8'") or die(mysql_error()); just before my query but it didn't work. Does it have to be sent straight after the db is selected, so no other queries can run before it? My code isn't straightforward enough to allow me to do that too easily, but I can if I need to.
Matt
Actually ignore that - I added it directly after mysql_select_db() and it's still not working.
Matt
+1  A: 

Collation has nothing to do with international characters. Charset does.
Usual solution is utf8.

Dunno what do you mean "I've tried utf8_unicode_ci", but at least you have to tell database, what charset your data is. SET NAMES utf8 query can do that, if your data from google uses that charset

Col. Shrapnel