Zend_Translate 的 MySQL 适配器
我目前正处于一个相当大的项目的规划阶段,我将在 Zend 框架中开发该项目。我面临的问题之一是客户不仅想要翻译内容,还想要翻译界面。我目前正在使用 gettext 和 poedit 来管理我的语言文件,但这对于客户来说不是一个选择,因为他们无法通过 FTP 访问该网站。
因此,我正在考虑一个 mysql 后端,在前端有一个接口,供客户管理他自己的接口翻译。然而,Zend_Translate 仍然没有 mysql 适配器。
那么,现在有人有 Zend_Translate 的适配器脚本,以便它可以与 mysql 表一起使用吗?或者有任何反对使用 mysql 的论点以及解决这个问题的其他可能的解决方案吗?
I'm currently in the planning phase of a rather large project that I'll develop in the Zend Framework. One of the problems I'm facing is that the customers will want to translate not only the content but also the interface. I'm currently using gettext and poedit to manage my language files but this is not an option for the customer as they, for one, wont have FTP access to the site.
Hence, I'm thinking of a mysql back end with an interface in the front end for the customer to manage his own translations of the interface. There is however still no mysql adapater for Zend_Translate.
So, does anybody now of an adapter script for Zend_Translate so it can work with a mysql table? Or any arguments against using mysql and possible other solutions for this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过不同的方式解决这个问题:
扩展 Zend_Translate_Adapter 以创建您自己的。所有新适配器只负责从源中获取翻译。也就是说,您只需要从数据库中获取翻译。查看其他适配器并了解它们是如何实现的。
从数据库获取数据并将其传递给 Zend_Translate_Adapter_Array
使用 Zend_Translate_Adapter_Csv 或 Ini。由于会有更多的阅读翻译的文字,因此该解决方案将减少对数据库的查询数量。当客户端添加新语言或更改现有语言时,只需将其写入文件,而不是数据库。
如果您决定使用数据库适配器,也许您可以以某种方式“标记”翻译,以便在主页上仅获取主页的翻译,在联系页面上仅获取联系页面的翻译...
哈!
You could solve this problem on different ways:
Extend Zend_Translate_Adapter to create your own. All new adapters are only responsible from getting the translations out from the source. That is, you would need only to fetch the translations from the database. Look at other adapters and see how they are implemented.
Fetch the data from the database and pass it to Zend_Translate_Adapter_Array
Use Zend_Translate_Adapter_Csv or Ini. As there would be more reading the writing on the translations, this solution would cut down the number of queries to the database. When the client adds a new language or changes an existing one, simply write it to a file, not the database.
If you decide to go with the database adapter, maybe you could "tag" somehow the translations, so that on the home page you fetch only the translations for the home page, on the contact page only the translations for the contact page...
HTH!
默认的 Zend 适配器可以很好地处理缓存,所以我会坚持使用它们,除非您确实需要数据库。
您可以直接操作翻译文件(例如 po 模板),而不是将翻译数据存储在数据库中。如果您只需要添加(附加到文件)新的翻译字符串,这将是最佳选择。
您可以使用 Zend_Translate 的 选项来记录未翻译的消息(到文件或任何日志适配器,包括数据库),
然后处理日志,甚至创建侦听器来翻译保存的字符串。
Default Zend adapters handle caching well, so I'd stick to them, unless you really need database.
Instead storing the translation data in the database, you may directly operate on the translation files (e.g. po templates). This would be the best choice if you just needed to add (append to file) new translation strings.
You may use Zend_Translate's option to log untranslated messages (to file or any log adapter, including database),
and then handle the logs, or even create listener translating the saved strings.
具体方法如下: http://cloetensbrecht.be/zend_translate_mysql.html
Here's how: http://cloetensbrecht.be/zend_translate_mysql.html