url国际化应该如何进行?

发布于 2024-10-30 04:57:46 字数 1179 浏览 2 评论 0原文

我有一个关于网站 URL 地址国际化的问题。

问题是如何正确地制作它?

我想做的是这样的事情。

假设您的地址栏中有一个URL

www.mydomain.com/en/book

,那么如果您输入www.mydomain.com/de/book code> 您将被重定向到德语版本的网站,因此网址将更改为 www.mydomain.com/de/buch 等。

想法

我考虑制作一个表格,用作不同语言之间的字典。对于网站内容,我仍然会使用i18n,但我认为对于url它不能应用。

实现

我考虑过修改 routing.py,在调用任何连接之前,我会在 URL 中识别用户想要的语言,并将其存储在会话变量供以后与i18n一起使用。然后我会将用户重定向到该语言的正确网址并调用 poper 控制器/操作

欢迎任何想法、建议或推荐。

编辑(2011-04-04 18:35):

  1. 我刚刚提醒自己,我已经在 Opera 博客;
  2. StackOverflow 上有一个问题: Pylons 应用程序国际化,但它只处理网站国际化,没有问题包含网址
  3. WZeberaFFS 指出了如果不考虑参考以前的语言设置可能会出现的一个小问题;
  4. 附加问题:数据库中应该存储什么才能使其快速运行?我有自己的想法,但稍后我会尝试一下。

I have a question regarding the internationalization of a website's URL addresses.

The question is how to make it properly?

What I would like to do is something like this.

Assume you have an URL in your address bar

www.mydomain.com/en/book

then if you type www.mydomain.com/de/book you will be redirected to a german version of a site so the url will change to www.mydomain.com/de/buch and so on.

Idea:

I thought about making a table that would be used as a dictionary between different languages. For the website content I would still use i18n, but I think that for urls it cannot be applied.

The implementation:

I thought about modifying routing.py in a way that before any connection is invoked I would recognize in the URL a language that user wants, and store it in a session variable for later use with i18n. Then I would redirect user to a correct url for this lanugage and invoke a poper controller/action.

Any ideas, suggestions or recomendations are welcome.

Edit (2011-04-04 18:35):

  1. I have just reminded myself that I have already encountered a similar problem on Opera Blog;
  2. there is a problem on StackOverflow: Pylons application Internationalization, but it deals solely on site internationalization, no problem with URLs included;
  3. WZeberaFFS has pointed our a small issue that may arise if no reference or previous language settings are taken into account;
  4. Additional question: What should be stored in database, to make it work fast? I have my own idea, but I will give it a try later on.

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

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

发布评论

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

评论(2

傾旎 2024-11-06 04:57:46

我相信您的实现将像日志一样工作,因为您对不同页面没有相同的名称,例如您有一个名为 www.mydomain.com/en/music 的页面,并且如果 music 在德语中是 book,那么问题是,如果你想去 www.mydomain.com/fr/music 那么你不知道如果您来自 /de//en/。但这只是一个问题,如果你在不同的页面上有冲突的名称,那么它仍然会起作用,如果你在两种不同的语言中对一个单词有相同的名称,你不会真正知道它们在哪里形成,但你会知道它们的走向。

如果您遇到这个问题,那么您必须保存会话或希望客户发送推荐。

I believe your implementation will work as log as you don't have the same name of to different pages like if you have a page called www.mydomain.com/en/music and if music in German is book, then the problem will be that if you want to go to www.mydomain.com/fr/music then you don't know if you are coming form /de/ or /en/. But this is only a problem if you have colliding names on different pages cross languish it will still work if you have the same name for a word in 2 different languish you wont really know where they cam form but you will know where they are heading.

If you have that problem then you have to save a session or hope that the client sends a referral.

就像说晚安 2024-11-06 04:57:46

我不知道如何在 Python 中完成此操作,但通常人们通过某种 URL 重写器或 URL 过滤器来执行此类操作 - 这些操作将消耗您的 URL 并同时重定向到正确的页面设置区域设置。

I have no idea how it could be done in Python, but usually people do such things through some kind of URL Re-writer or URL filter - something that will consume your URL and re-direct to proper page setting Locale at the same time.

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