具有多数据库的实体框架多语言网站

发布于 2024-08-18 00:21:39 字数 368 浏览 6 评论 0原文

由于问题有点不言自明,我想实现多语言网站的目标。我正在使用带有 MS SQL 2005 的实体数据模型。我想到了为每种语言创建一个具有完全相同的模型和关系的单独数据库的想法。因此,我可以使用采用连接字符串的实体构造函数并将站点切换为所选语言。

我使用 ascx 作为触发事件的语言控件,父级 aspx 将所选语言作为整数(从事件参数)获取,并调用包含相同 linq 查询的方法,但将使用以下连接字符串创建实体上下文那个数据库(语言)

我只能想出这个解决方案,因为我认为添加一种新语言将需要复制英语语言,导入到 Access 并发送给翻译器。然后将被导出回来,并且模型将适合(希望如此)。

我的问题是,这是否真的是一个好方法,还是我错过了任何会给我带来更大麻烦的东西。提前致谢

As the question is a bit self explanatory, I want to achieve the goal of a multi-language website. I am using an Entity Data Model with MS SQL 2005. I came up with an idea of making a seperate database for each language with exactly the same model and relations. So I can use the Entities constructor that takes a connectionString and switch the site to the selected language.

I am using an ascx as the language control that fires an event, and the parent aspx gets the selected language as an integer (from event args) and call the method containing the same linq queries but Entity context will be created with the connection string of that db (of language)

I could only came up with this solution, because I think adding a new language will require a replication of the english one, imported to Access and sent to the translator. Then will be exported back, and the model will fit (HOPEFULLY).

My question is if this is really a good approach or am I missing anything that will create greater hassle to me. Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

╰◇生如夏花灿烂 2024-08-25 00:21:39

一旦不同数据库中的实体相互关联,多数据库就不是一个好的解决方案。一般来说,一个好的方法是使用一种默认语言的标签。这些标签可以采用明确定义的格式(例如“LABEL.TEXT_HELLO”),也可以采用基本语言(例如“Hello World”)。

因此,您所要做的就是构建一个翻译表,其中基本语言是键,并且希望每个键都有一个包含翻译的值。一旦获得翻译,您就可以在前端编写一个方法,以用户使用的语言编写标签。

例如,在 Zend Framework 中,您必须编写

translate('Hello World'); ?>

而不是只是

Hello World


这样做的好处是,如果缺少翻译,您仍然可以使用后备(在本例中为英语)至少向用户显示一些内容。

这样,您就可以在一个数据库中管理您的应用程序,并且使用多种语言的用户无需在应用程序和内容之间切换。

干杯

multi-database is not a good solution as soon as entities within the different databases have relations to each other. Generally a good approach is to work with labels in one default language. These labels can either be in a well defined format (e.g. 'LABEL.TEXT_HELLO') or just in the base language (e.g. 'Hello World').

So all you have to do is building a table for translations where the base language is the key and hopefully there is for each key a value containing the translation. As soon as you have the translations, you can write a method ont he frontend which writes the labels in the language used by the user.

In Zend Framework for example, you have to write <h1><?= $this->translate('Hello World'); ?></h1> instead of just <h1>Hello World</h1>
The good thing about that is, that if ya translation is missing, you can still use the fallback (in this case english) to show the user at least something.

That way, you can manage your app in one database and users who speak several languages do not have to switch between applications and content.

cheers

度的依靠╰つ 2024-08-25 00:21:39

我的方法:创建一个表语言,列出所有可用的语言。将应本地化的每个表与语言相关联。现在,您可以轻松访问本地化内容,例如

Content[content_ID].HeadLine.Where(hl => hl.Language.id == "en-US")

我期待看到其他人和我自己一样仍在学习数据库设计和 EDM 的内容。

My approach: create a table Language that lists all the available languages. Relate each table that should be localized to Language. Now, you can easily access the localized content e.g.

Content[content_ID].HeadLine.Where(hl => hl.Language.id == "en-US")

I look forward to see what other people as I myself is still learning DB design and EDM.

狂之美人 2024-08-25 00:21:39

好的,如果您希望能够轻松实现一种新语言,那么重新发明国际化ASP.NET 中已经内置的功能并不是正确的选择,因为它并不“容易”。

至少,不像使用卫星资源DLL那么容易。您的翻译人员将使用现成的工具来翻译您的资源,并且 ASP.NET 将根据用户当前的文化自动选择正确的 DLL。

阅读 ASP.NET 国际化/全球化功能;没有必要自己发明。

OK, if you want to be able to easily implement a new language, then reinventing the internationalization features already built in to ASP.NET is not the way to go, because it isn't "easy".

At least, not as easy as using a satellite resource DLL. Your translators will use off-the-shelf tooling to translate your resources, and ASP.NET will automatically select the correct DLL based on the user's current culture.

Read up on ASP.NET internationalization/globalization features; there's no need to invent your own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文