Page 1 of 1

PHP import/export language packages? [Solved]

Posted: Wed Oct 17, 2007 9:32 am
by douphp
Hello,

I need a little help with exporting data from a database that contains language packages.

To explain in short I have a small PHP script that is multilingual and all the phrases are stored in the database. It currently can export the phrases for a specific language package and it can also import the exported data. So it allows the usage of other language packages in the future.

It works great with the default language package I have setup, which is English; however I am having problems with other languages such as Polish, Greek, Russian etc... When I export the data and then try to import the data using my script all the special characters turn into question marks.

Since the exported data is in a flat PHP file I use PHP fwrite to write to the file. I tried to use PHP's utf8_encode, however that did not do much help. I also tested to change the collation of the database, which also did not help.

So I am rather lost as to how scripts like vBulletin can export language packages and then import it, while dealing with character issues.

Any help would be appreciated.

Thanks

Posted: Wed Oct 17, 2007 9:44 am
by CoderGoblin

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
Notice the <meta> tag... if you don't define it you can run into problems.
Then you need to look at the character set of the database itself. Is this UTF8 ?
Then if you are using any files check the saved encoding, again make sure this is UTF8.
Finally I use the following so pregs work with UTF8 characters... probably not necessary in your PHP but keep it in mind...

Code: Select all

mb_internal_encoding("UTF-8");
date_default_timezone_set('Europe/Berlin');

Posted: Wed Oct 17, 2007 11:28 am
by douphp
Thanks for your reply.

Yes the DB is UTF8, I tested other collations as well; however UTF8 seems to work best for most the languages I have tested. I also have the meta "charset" set in the HTML headers. I will give "mb_internal_encoding" a try. I have not used Multibyte string functions in the past, do most servers today have these set of functions? I ask mainly because I would like to give out the script to others once its completed and would like it to work on most if not all servers.

Thanks again!

Posted: Thu Oct 18, 2007 12:19 am
by douphp
I believe I got it working. I had to add this at the top of my script:

Code: Select all

header('Content-Type: text/html; charset=UTF-8');
Funny thing is it worked fine on one server without it, while on another server it did not which was the one I was developing on. In any case having that in the script helped me to get it working on both servers and for different languages.