| i18n over mysql special characters problem [message #56385] |
Thu, 17 July 2008 14:31  |
senorpedro Messages: 1 Registered: July 2008 |
Junior Member |
|
|
hi folks
i'm currently trying to implement i18n over mysql on my website. the problem is that german special characters are displayed with the wrong charset (iso-8859 instead of utf8).
i have the following configuration:
- charset: utf-8 (in settings.yml)
- encoding: utf8 (in databases.yml)
- the MySQL database and tables are utf8_general_ci
- MySQL connection_collation is also utf8_general_ci
- The default charset in php.ini is UTF-8
- in apache.conf i have AddDefaultCharset UTF-8
- The http-header is text/html; charset=utf-8
- The tag <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> is correct
- all the script files involved (.php and .sql) are utf8
now when i call the page in firefox i get broken special characters. when i manually switch the page encoding via firefox-menu to iso-8859 then the special characters are displayed correctly.
i did a little research and found out that when i add the following 2 lines to the constructor of the class sfMessageSource_MySQL:
mysql_query("SET CHARACTER SET utf8", $this->db);
mysql_query("SET NAMES utf8", $this->db);
it works.
now since manipulating core symfony files is generally a bad idea, my question is how can i make symfony to get the right character set when using i18n over mysql? can i maybe define the character set which the mysql_connect has to use, or is there some other method?
|
|
|
| Re: i18n over mysql special characters problem [message #56454 is a reply to message #56385 ] |
Fri, 18 July 2008 10:54   |
|
I had the same issue over here as well...
Many thanks for the hint, worked great! 
I found the email address of the author of that class in the source code and wrote him an email with a link to this thread, maybe he will consider it for symfony 1.2? 
cheers,
Lars.
|
|
|
| Re: i18n over mysql special characters problem [message #56571 is a reply to message #56385 ] |
Mon, 21 July 2008 09:19   |
|
I foudn another issue when using the symfony i18n:extract dommand with --auto-save and --auto-delete: Sometimes it can occur that different translation strings end up with the same id.
In order to fix this, I applied the following changes in ./PEAR/symfony/i18n/sfMessageSource_MySQL.class.php in the function called 'save':
Replace this
foreach ($messages as $message)
{
$count++;
$inserted++;
$message = mysql_real_escape_string($message, $this->db);
$statement = "INSERT INTO trans_unit
(cat_id,id,source,date_added) VALUES
({$cat_id}, {$count},'{$message}',$time)";
mysql_query($statement, $this->db);
}
by this
foreach ($messages as $message)
{
$count++;
$inserted++;
$message = mysql_real_escape_string($message, $this->db);
$statement = "INSERT INTO trans_unit
(cat_id,id,source,date_added) VALUES
({$cat_id}, {$count},'{$message}',$time);";
mysql_query($statement, $this->db);
}
$updateIds = "UPDATE trans_unit SET id = msg_id;";
mysql_query($updateIds, $this->db);
This simply sets all the id fields to the according msg_id fields and therefore ensures that the ids are unique.
Maybe it helps anyone or we will find this fix in the next release? 
Cheers,
Lars.
|
|
|
| Re: i18n over mysql special characters problem [message #90234 is a reply to message #56385 ] |
Sat, 19 December 2009 15:29  |
samsow Messages: 23 Registered: May 2007 Location: Italy |
Junior Member |
|
|
About the special characters problem, a ticket has been open 1 year ago:
http://trac.symfony-project.org/ticket/5671
and closed giving the responsibility to a Propel bug which has been fixed.
But I think it is not a Propel bug (sfMessageSource_MySQL don't use Propel) and the problem remain in symfony 1.3. Maybe this ticket have to be reopen ?
In the meantime, and to not make change in the symfony libraries, the solution can be to overwrite the sfMessageSource_MySQL class (see
http://forum.symfony-project.org/index.php/m/90233/#msg_9023 3 )
|
|
|