文章分类阅读
会员登录
新增下载
| How to support utf-8 encoding when programming for Joomla |
|
| 作者:白建鹏 | |||
| 2007-06-24 | |||
|
Joomla 1.0.x versions have no intrincic support for utf-8 encoding. But more and more users turn to accept utf-8 encoding as the global option for their site. What is worse is that, most Joomla Extension developers, especailly those living in English language countries, have not realized the importance of supporting utf-8 encoding, or they don't know how to do that. (For Chinese visitors: 很多Joomla扩展开发者不知道如何在编程时加入对utf-8语言编码的支持,鉴于这些开发者绝大部分都在国外,因此本文用英文撰写。如果你对开发编程没有兴趣,就不必继续读下去浪费时间了)
Some of those developers want to support utf-8. At present, they usually intend to use htmlentities function when they programming. But function htmlentities has its limitations. It can't extract certain amount of characters from a long string or description correctly. We often see totally unreadable symbols under this circumstance, especially when handling with double bytes characters such as Chinese, Korean or Japanese. For example, we Joomla users always like to show latest forum posts in a module on the frontpage. I found that many modules claimed to do this job but fail to show proper Chinese post titles. Because when such a module try to substr the post title for the first 20 or 25 characters, this functions can't work with utf-8 encoding and result in unreadable symbols. The only way I use to handle this problem is setting the title length to over 120 characters at the backend of such a module. Then the post tile can be show completely without substr and so it is correct Chnese words now. But this resolution brings a new problem: the frontend appearance is a bit ugly. Adjusting of title length can't sovle all the problem comes with substr. For example, we often use Chinese name for a category title in a gallery component. This time the title name is just saved. When viewing at frontend, the category name always show strange symbols other than the exact Chinese name I entered at backend. Well. How could this happen? I am not a programmer. But I have strong love to Joomla and strong willing to see the solution for this issue. In my opinion, that is because those developers used wrong function and wrong code. As I know, Andreas Gohr had developed a file named utf8.php to solve similar problem in DokuWiki. The certified translation team, http://www.joomla.org.tw had implemented this utf8.php file into the Chinese version of Joomla 1.0.x. But this does not mean other extensions developers will use this file and its functions since they even don't know the existence of this file. They always try to develop extensions based on original official version of Joomla 1.0.12. But Joomla team did not include this utf8.php into the package. You can download this utf8.php and study its codes. I am sure this can solve all above issues for there is one function named utf8_substr in this file to replace the older substr. Thank you all for pay attention to this topic. I hope you will use this utf8.php file and give full support to utf-8 encoding in your following developing life.
|











