Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database backed i18n of a PHP website

I have a website written in PHP with 15-20 pages and they have lots of text. I have to translate it to 3 different languages. First, I tried using strings ($text_hello = "你好";) but that option gets very tedious and hard to manage with 50+ strings. I also discovered gettext option and it's good. But I was interested particularly in a (MySQL) database backed option, where all translation would be fetched from database. Also, I may be wrong, but with gettext, you've to have that extra index.php?lang=en_US (?) I want it to change just like it's on Twitter or Facebook, where URL doesn't change. Can you suggest me how to do this or guide me to tutorial/article/previous questions on this topic? Thanks!

Also, I saw people recommending Zend_Translate, but does that require me to re-write my website in Zend framework?

Before asking, I did search for it, but the results I got weren't what I was looking for.

like image 242
tmrhmdv Avatar asked Oct 09 '22 12:10

tmrhmdv


1 Answers

Also, I may be wrong, but with gettext, you've to have that extra index.php?lang=en_US

Yes you are wrong , the lang parameter can be hidden if you like (using session and/or cookie for example). It also can be a part of your SEO strategy (url like /en/mypage or /fr/mypage)

Multilang with databases is an option , but i'm not a big fan of adding extra queries if it just to get some translation for the interface.
Some links which could be usefull : Schema for a multilanguage database
What are best practices for multi-language database design?

Also, I saw people recommending Zend_Translate, but does that require me to re-write my website in Zend framework?

You can just extract Zend_Translate (and it's dependency) and use it as a library

like image 184
grunk Avatar answered Oct 18 '22 05:10

grunk