PHP国际化 [英] Internationalization in PHP

查看:117
本文介绍了PHP国际化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究将i18n集成到项目中的最佳方法.

我已经想到了几种方法,首先是一种存储字符串和相关语言环境的数据库方案,但是这样做的问题是选择字符串并不是那么容易,因为我不想像这样执行查询:

SELECT text FROM locales WHERE locale = 'en_GB' AND text_id = 245543

SELECT text FROM locales WHERE locale = 'en_GB' AND text_primary = 'hello'

下一个方法是将它们存储在诸如locales/en_gb/login/strings.php之类的文件中,然后尝试通过像这样专门开发的类来访问它们:

$Language = Registry::Construct('Language',array('en_GB'));
echo $Language->login->strings->hello;

与此相关的问题是,我将不得不构建一个通过管理面板更新这些文件的系统,这非常耗时,不仅是构建用于管理字符串的系统,而且实际上是随着站点的增长来管理字符串

  • 还有什么其他对大型系统有利的方法
  • 是否有任何自动方式来进行翻译"
  • 我应该坚持使用数据库方法并构建一个系统供用户翻译带评级的字符串/建议更好的版本吗?
  • 您过去尝试过什么系统,我应该研究一下还是完全避免使用它们.

解决方案

除了已经提到的gettext Zend_Translate Zend_Locale 以及与此相关的组件. Zend_Translate支持许多适配器,包括但不限于简单数组,gettext,XmlTm等.

I am currently researching the best methods to integrate i18n into projects.

There's several methods I have thought of doing this, first being a database scheme to store the strings and relevant locale, but the problem with this is that it would not be that easy to select the strings, because i would not like to perform quesries like so:

SELECT text FROM locales WHERE locale = 'en_GB' AND text_id = 245543

Or

SELECT text FROM locales WHERE locale = 'en_GB' AND text_primary = 'hello'

The next method would be to store them within files such as locales/en_gb/login/strings.php and then try and access them via an class specifically developed like so:

$Language = Registry::Construct('Language',array('en_GB'));
echo $Language->login->strings->hello;

The issue with this is I would have to build a system that would update these files via an administration panel witch is very time consuming, not just building the system to manage the strings but actually managing the strings as the site grows

  • What other methods are there that will be beneficial for a large system
  • Is there any automated way to do 'Translation' as such
  • Should I stick with a database method and build a system for users to translate strings with rating / suggest better version ?
  • What systems have you tried in the past and should I look into them or totally avoid them.

解决方案

In addition to gettext already mentioned, PHP 5.3 has native Internationalization support

If that's not an option, consider using Zend Framework's Zend_Translate, Zend_Locale and related components for that. Zend_Translate supports a number of adapters, including but not limited to simple arrays, gettext, XmlTm and others.

这篇关于PHP国际化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆