PHP 国际化 [英] Internationalization in PHP

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

问题描述

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

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

或者

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

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

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

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

推荐答案

除了已经提到的gettextPHP 5.3 具有原生国际化支持

如果这不是一个选项,请考虑使用 Zend Framework 的 Zend_Translate, Zend_Locale以及相关的组件.Zend_Translate 支持多种适配器,包括但不限于简单数组、gettext、XmlTm 等.

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天全站免登陆