每一个可以努力的日子,都是一份厚礼。
PHP
Microsoft AJAX Translation WordPress Plugin
2012 3月 2nd
The Microsoft AJAX Translation WordPress plugin offers a “Translate” button that allows readers to translate your blog’s posts into a specified language with a quick, light ajax call to the Microsoft Translator API.
Why Microsoft AJAX Translation?
As of December 1, 2011, Google Translate API v1 is no longer available; it was officially deprecated due to the substantial economic burden. Google Translate API v2 is now available as a paid service only, and the number of requests your application can make per day is limited.
This is dramatic news. All of those “free” programs that hitchhiked on Google Translate are history. A lot of wordpress plugins that depended on the free Google Translation Engine also not work any more.
Fortunately, Microsoft still provide a free translation API for programmer. That’s why I decide to develop this plugin, which uses Microsoft Translator API. It is a surprisingly adequate substitute for Google Translate.
MVC之患上肥胖症的Controller
2012 1月 11th
来这边负责做的一个项目,用了一个叫做 Yii Framework 的 MVC 框架,刚开始的时候自以为结构很稳健(当然,是相对于现有的烂系统来讲)。但是随着对业务逻辑理解的深入,我开始意识到问题的严重,我错误地理解了 MVC 中的 Controller,想当然地根据以往的经验,把所有的业务逻辑都放在 Controller 的 action 中去实现,于是,每一个 Controller 的代码都上千行,越来越臃肿。
最终导致我下定决心对这两个月工作进行重构的,是一个对外开放 API 接口的需求。按照现在的架构,代码基本无法复用,我需要把很多功能再重复写一遍,这实在是无法接受的。面向对象编程不仅仅是课本上的名词啊!真正开始实践才发现要有面向对象意识,有全局观,是多么难得的一件事情。
【暴走漫画】坑爹的UTF8和UTF-8网页编码
2012 1月 2nd
一、遇到的问题
曾经被字符集间复杂的转换搞怕了,正好新项目要求国际化,需要能够显示多种语言,于是一开始就规定统统使用 UTF-8 编码。
- 所有代码文件使用 UTF-8 编码存盘
- MySQL数据库所有表,所有字段设置 Collation (中文翻译为“整理”?)属性为 “utf8_general_ci”
- 所有页面输出
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
即便是这样,PHP 从数据库中读取内容,显示到网页上,还是出现了乱码,英文没问题,中文统统都是?问号。这样也行?艰苦卓绝的 debug 开始了……