We have a problem here.
我们这里有一个问题。
We need to translate a website into multiple language. We already use gettext to translate the static content. But we have to translate some text content in multiple language.
我们需要将网站翻译成多种语言。我们已经使用gettext来翻译静态内容。但我们必须用多种语言翻译一些文本内容。
The ui isn't a problem.
ui不是问题。
We found 2 ways to translate the text. 1. use JSON inside our text input Why this solution is bad. Every text input will need to be bigger because we can't guess the real size of the attribute.
我们找到了2种翻译文本的方法。 1.在我们的文本输入中使用JSON为什么这个解决方案很糟糕。每个文本输入都需要更大,因为我们无法猜测属性的实际大小。
-
Use the a translating table that keep reference to the original model and translate every field. It will still need big field because we cant define the field size by record.
使用保留对原始模型的引用的翻译表并翻译每个字段。它仍然需要大场,因为我们无法通过记录来定义字段大小。
-
Finally, the best solution I came with is creating a translating table. The table will keep foreign key of other tables. For each translation, we copy the record that need to be translated. Inside the translation table, there is 4 field, model_name(primary), reference_id(primary), translated_id(primary), locale(primary). This solution make it impossible to have multiple translation for the same model in the same language.
最后,我带来的最佳解决方案是创建一个翻译表。该表将保留其他表的外键。对于每个翻译,我们复制需要翻译的记录。在转换表内,有4个字段,model_name(主要),reference_id(主要),translated_id(主要),locale(主要)。该解决方案使得无法在同一语言中对同一模型进行多次翻译。
-
Last but not least, we could use something like someone proposed...a database gettext. We have a table that contain strings and only string (key, text, locale) so we can search for a model, a string that is the same as the one used in the model and then use the we found instead.
最后但并非最不重要的是,我们可以使用像某人提议的东西......数据库gettext。我们有一个包含字符串和只有字符串(键,文本,语言环境)的表,因此我们可以搜索模型,一个与模型中使用的字符串相同的字符串,然后使用我们找到的字符串。
My opinion is that all of these solutions are hack, the 4 solution is probably the one that looks better.
我的观点是所有这些解决方案都是黑客攻击,4解决方案可能是看起来更好的解决方案。
As I didn't found any good documentation, I would really like to make this question shine.
由于我没有找到任何好的文档,我真的想让这个问题大放异彩。
1 个解决方案
#1
Here is how we dealt with the multiple languages (we had some experts look at this solutions as well!).
以下是我们处理多种语言的方式(我们也有一些专家也在研究这些解决方案!)。
- We have text a table in the database (textid, key, nl, uk, de, fr)
- We have foreignkeys to the text table (from for instance the productnameid)
- Static text that needs to be translated in html pages is surrounded with hashes: ##name##
- right before the html content is send from the server to the client the htmlstream is parsed to translate the content between hashes.
- the translated texts are stored in the cache which makes this solution flexible and still fast
我们在数据库中有一个表格(textid,key,nl,uk,de,fr)
我们有文本表的外键(例如productnameid)
需要在html页面中翻译的静态文本用哈希包围:## name ##
在将html内容从服务器发送到客户端之前,解析htmlstream以在哈希之间转换内容。
翻译后的文本存储在缓存中,这使得该解决方案变得灵活且仍然快速
It works for us, and we build websites that have over 100k pageviews per hour.
它适用于我们,我们构建的网站每小时浏览量超过10万。
#1
Here is how we dealt with the multiple languages (we had some experts look at this solutions as well!).
以下是我们处理多种语言的方式(我们也有一些专家也在研究这些解决方案!)。
- We have text a table in the database (textid, key, nl, uk, de, fr)
- We have foreignkeys to the text table (from for instance the productnameid)
- Static text that needs to be translated in html pages is surrounded with hashes: ##name##
- right before the html content is send from the server to the client the htmlstream is parsed to translate the content between hashes.
- the translated texts are stored in the cache which makes this solution flexible and still fast
我们在数据库中有一个表格(textid,key,nl,uk,de,fr)
我们有文本表的外键(例如productnameid)
需要在html页面中翻译的静态文本用哈希包围:## name ##
在将html内容从服务器发送到客户端之前,解析htmlstream以在哈希之间转换内容。
翻译后的文本存储在缓存中,这使得该解决方案变得灵活且仍然快速
It works for us, and we build websites that have over 100k pageviews per hour.
它适用于我们,我们构建的网站每小时浏览量超过10万。