This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » General discussion » i18n over mysql special characters problem
i18n over mysql special characters problem [message #56385] Thu, 17 July 2008 14:31 Go to next message
senorpedro  is currently offline 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 Go to previous messageGo to next message
larsf  is currently offline larsf
Messages: 22
Registered: June 2008
Location: Stuttgart / Germany
Junior Member

I had the same issue over here as well...
Many thanks for the hint, worked great! Smile

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? Rolling Eyes


cheers,
Lars.
Re: i18n over mysql special characters problem [message #56571 is a reply to message #56385 ] Mon, 21 July 2008 09:19 Go to previous messageGo to next message
larsf  is currently offline larsf
Messages: 22
Registered: June 2008
Location: Stuttgart / Germany
Junior Member

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? Wink

Cheers,
Lars.
Re: i18n over mysql special characters problem [message #90234 is a reply to message #56385 ] Sat, 19 December 2009 15:29 Go to previous message
samsow  is currently offline 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 )
Previous Topic:How do I extend sfMessageSource
Next Topic:Struggling with many to many relation
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software