为多语言PHP应用程序存储字符串的推荐方法 [英] Recommended way to store strings for a multi-language PHP application

查看:84
本文介绍了为多语言PHP应用程序存储字符串的推荐方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我将字符串与描述它们的关键字相关联,然后将它们存储在结构为id int, id varchar(16), language char(2), string varchar的数据库表中.然后,我创建一个PHP包装函数,以根据访问者当前的语言来获取每个字符串.

Normally I associate strings to keywords that describe them, and then store them in a database table with a structure of id int, id varchar(16), language char(2), string varchar. Then I make a PHP wrapper function to fetch each string depending on the visitor’s current language.

有人告诉我(并在我认为的地方读过)使用PHP的内置方法来处理国际化.但是我没有找到任何真正的令人信服"的信息来说明为什么它比我的数据库方法更合适.

I have been told (and read somewhere I think) to use PHP’s built in methods to handle internationalization. But I have not found any really "convincent" information about why it should be more appropriate than my database way to do it.

处理国际化网站字符串的最合适方法是什么?为什么?有什么我应该一直喜欢它更好的性能吗?如果有一个性能更好的产品,那么我将改用它.

What is the most appropriate method to handle internationalized websites strings and why? is there one that I should always prefer for its better performance? If there is one with a better performance then I will switch to use it.

推荐答案

这取决于您的目标.如果您需要网站用户在线更新翻译,那么您的数据库方法就可以了.但是,如果要由专业翻译人员提供翻译,则最好将翻译与网站脱钩.在这种情况下,最好使用gettext之类的方法-您将能够发送.po文件进行翻译,然后将其重新集成到您的网站中.

It depends on what your objectives are. If you need your translations to be updated on-line by website users, then your database approach is ok. However, if translations are to be provided by professional translators, then it's better to decouple the translation from the web site. Using something like gettext is a better idea in this case - you will be able to send out .po files for translation, then integrate it back into your web site.

考虑整个过程,管理翻译人员,管理更改等

Think about the whole process, managing translators, managing changes, etc.

这篇关于为多语言PHP应用程序存储字符串的推荐方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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