网站本地化
我想询问翻译静态内容的最佳实践或最简单的方法。例如翻译、“搜索”或“保存更改”。
我当前的想法是:
根据用户浏览器区域设置(可能是IP地址的地理位置,但我更喜欢浏览器区域设置)选择一个子域,例如“fr.myweb.com”。根据语言设置设置 cookie、会话变量。这部分相当简单。
现在到了翻译部分。根据语言更改图像不会成为问题,因为“_fr”前缀就足够了。但是翻译字符串,如保存更改、搜索、订购商品等。嗯,我在这里不确定。
由于它全部基于 PHP 和 MySQL,所以我想到了类似的东西:
两个表:
- 第一个表包含默认语言的所有单词的列表
- 第二个表包含三列(不包括自动增量)- language_id,翻译,word_id
获取所有单词,缓存查询或其他任何内容,现在调用 trans('fr', 'search') 将翻译该单词。这应该可行,尽管我不知道这是否是正确的方法或者是否有更好的方法。注意:没有谷歌翻译。
另外,由于我使用 js/ajax,我也不确定这部分。从 cookie 获取语言并制作警报地图等,然后只需调用“message['fr']”,我也不确定这部分。
有什么想法对于两种语言来说都是理想的吗?我尝试了谷歌,但对结果不满意。任何建议/链接表示赞赏。
问候
I would like to ask about best practices or the simplest way possible of translating static content. E.g. translating, "search" or "save changes".
My current idea is:
depending on users browser locale (maybe geolocation of IP address, but I prefer browser locale) choose a subdomain, e.g. "fr.myweb.com". Set a cookie, session variable, depending on settings with the language. This part is fairly straightforward.
Now comes the translating part. Changing images depending on language wont be a problem, since a "_fr" prefix is enough. But translating strings like save changes, search, order items, etc. . Well, I am not sure here.
Since its all based on PHP and MySQL, I was thinking of something like:
Two tables:
- First one has list of all words in default language
- Second one has three columns (excluding auto increment) - language_id, translation, word_id
Get all words, cache the query or whatever and now calling trans('fr', 'search') would translate the word. This should work, although I dont know if its the right approach or if there is a better way. Note: No google translations.
Also since I use js/ajax, I am not sure about this part either. Get the language from cookie and do a map of alerts, etc. and then just call "message['fr']", I am not sure about this part either.
Any ideas what would be ideal for both languages? I tried google, but wasnt satisfied with the results. Any advice/link is appreciated.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查找 PHP 的 Gettext: http://php.net/manual/en/book.gettext .php。它是提供网络内容翻译的事实上的标准。基本上,您构建翻译文件(例如,您可以使用 Poedit),将 PHP 指向它们,将语言环境设置为任何内容需要并使用
_( '要翻译的字符串' )
来获取翻译。Look up Gettext for PHP: http://php.net/manual/en/book.gettext.php. It's the de facto standard for providing web content translations. Basically you build translation files (you can use for example Poedit), point PHP to them, set the locale to whatever is needed and use
_( 'string to translate' )
to fetch the translations.