Zend框架中的多语言站点 [英] Multilingual Site in Zend Framework

查看:84
本文介绍了Zend框架中的多语言站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个网站上提供多语言支持. 我可以使用Zend_Translate翻译字符串,但是内容呢? 例如,是否必须为每种语言的同一产品添加多个记录?还是有其他方法吗? 我是多语言新手,请帮忙. 预先感谢.

---加法-----------------------------

好吧,我决定使用混合解决方案来使用google translation api并将其存储在数据库中以供进一步编辑.那么存储翻译的数据库结构到底是什么呢???

  1. 我应将不同语言的译文保存在与父记录相同的表中.即针对产品表中的产品,并在身份验证语言中添加了额外的列.
  2. 一个通用的单个表,用于存储所有表的所有翻译.例如翻译(id bigint,table_name vc(50),table_id bigint,langugae,column_name vc(50),翻译)

我应该将记录保存在相关表中

解决方案

几种可行的方法:

  1. 使用gettext(或 Poedit 之类的软件)从内容中提取数据.通过变量插值可以实现.
  2. 创建视图过滤器,如下所述: Zend框架和翻译
  3. 在数据库中具有单独的数据内容.
    如果您以标记(例如 Markdown )格式存储内容,那么任何人都可以轻松地对其进行翻译.创建不同语言的搜索引擎很容易.

似乎第三种方法需要最多的努力,但这是值得的.

评论后更新

我假设您将产品数据存储在数据库中,例如:

- product_data
-- id
-- price
-- name
-- description
-- etc…

因此,您应该对其进行修改,以为每种语言的翻译字符串添加字段:

- product_data
-- id
-- price

- product_data_translations
-- product_id
-- language (e.g. en)
-- name
-- description
-- etc

然后,您可以轻松地构建SQL查询以提取翻译后的数据where product_id=x and language="fr".

您也可以使用教义I18N 为您自动完成.

您需要手动翻译内容(或使用Google API自动翻译内容),但是您可以使用例如 解决方案

Few possible approaches:

  1. Using gettext (or software like Poedit) to extract the data from the content. Possible with variable interpolation.
  2. Creating view filter like described in: Zend Framework and Translation
  3. Have separate content of the data in the database.
    If you store the content in markup (e.g. Markdown) format, anyone can translate it easily. It's easy to create search engine in different languages.

Seems the third approach requires the most efforts, but it is worth.

Update after comment

I assume you store your product data in the database, in fields like:

- product_data
-- id
-- price
-- name
-- description
-- etc…

So you should modify it, to add fields for translated strings in each language:

- product_data
-- id
-- price

- product_data_translations
-- product_id
-- language (e.g. en)
-- name
-- description
-- etc

Then you can easily build SQL queries to extract translated data where product_id=x and language="fr".

You may use also Doctrine I18N to do it for you automatically.

You need to translate the content manually (or automate the translation using Google API), but then, you can easily index it using for example Zend_Search_Lucene.

这篇关于Zend框架中的多语言站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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