简体   繁体   English

Python/Django 的数据库本地化(多语言)设计

[英]Database localization (multilingual) design for Python/Django

I am currently in the process of creating an app, on which the information will be accessed by people who speak different languages.我目前正在创建一个应用程序,使用不同语言的人可以访问该应用程序中的信息。 The information will be highly unique, so using translation tools will not be good enough.这些信息将非常独特,因此使用翻译工具还不够好。 All the information will need to be in different languages, and when the user logs in, the information is displayed according to his settings.所有的信息都需要使用不同的语言,当用户登录时,信息会根据他的设置显示。 Now, the application is based off Django and MySQL. I see that Django has a localization feature, but I don't quite understand it.现在,该应用程序基于 Django 和 MySQL。我看到 Django 具有本地化功能,但我不太明白。 Is it calling a translation mechanism or something?是调用翻译机制还是什么? I don't get it.我不明白。

Putting that aside, I was wondering what was the best approach to solve this issue.抛开这一点,我想知道解决这个问题的最佳方法是什么。 The number of different languages is unknown for now.不同语言的数量目前未知。 So I don't think storing the exact translation of each column within one table is a good idea, even though it would save time when querying.所以我不认为将每个列的准确翻译存储在一个表中是个好主意,尽管它会在查询时节省时间。 (no inner joins etc). (没有内部连接等)。

1) Should I look into the Django localization feature? 1) 我应该查看 Django 本地化功能吗? What is it exactly?究竟是什么? [I don't really want to store the translations into files.] [我真的不想将翻译存储到文件中。]

2) What Database design is best for multilingual applications? 2) 哪种数据库设计最适合多语言应用程序? I found those ones:我找到了那些:

How people usually solve this issue?人们通常如何解决这个问题? Thanks a lot!非常感谢!

EDIT: I am not looking especially for something that is THAT easy to use.编辑:我并不是特别在寻找易于使用的东西。 Mostly for something that is performant and won't create a giant mess in my DB... is that possible?主要是为了一些高性能的东西,不会在我的数据库中造成巨大的混乱......这可能吗?

1) Django i18n mechanism is used to allow localization of static text- labels in templates, field names, error messages- basically every text you don't store in database. 1) Django i18n 机制用于允许本地化 static 文本 - 模板中的标签、字段名称、错误消息 - 基本上是您未存储在数据库中的所有文本。 It won't help much for translation of database contents.它对数据库内容的翻译帮助不大。

2) Every major effort at multilingual django models I have seen uses one of the following approaches: 2)我看到的多语言 django 模型的每一项主要努力都使用以下方法之一:

  • Adding modlename_lang columns to the same table.将 modlename_lang 列添加到同一个表中。
  • Storing shared fields in one table and translations in another.在一个表中存储共享字段,在另一个表中存储翻译。

I would advise you to decide which of these approaches you like more, and just use the best documented model translation app for the chosen approach.我会建议您决定您更喜欢这些方法中的哪一种,并针对所选方法使用记录最好的 model 翻译应用程序。

If you're going to have a few languages, then I'd advise to go for the first approach.如果您要使用几种语言,那么我建议您拨打 go 以获取第一种方法。 On the other hand, if the number of languages gets larger, the second approach may be more viable.另一方面,如果语言的数量越来越多,第二种方法可能更可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM