Google App Engine 网站专为国际受众打造,支持多种语言

发布于 2024-09-30 00:38:25 字数 726 浏览 4 评论 0原文

我正在谷歌应用程序引擎上构建一个网站,其核心代码和数据库旨在处理不同的语言和地区。

我真正想要的是关于如何构建 url 的建议,特别是针对 gae/django/python 设置,以便网站知道应该根据 url 加载页面的语言。

以下是我的建议,请提出您认为最好的建议:

子域:http://fr.mysite。 com/ 但这是否可能有不同的子域,例如“en”、“fr”、“de”,并且仍然指向您帐户中的同一个谷歌应用程序?

域名扩展:http://www.mysite.fr/ 是否可以为每种语言购买不同的域名,然后将其指向同一个应用程序?

第一个文件夹:http://www.mysite.com/fr/about-us 这种方法可以工作,但是编码起来会很烦人,而且我不想有比需要更长的网址。想法?

还有其他我没有想到的选择吗?任何建议将不胜感激,谢谢。

I'm building a site on google app engine and its core code and database is designed to handle different languages and regions.

What I'm really looking for are suggestions on how the url's should be structured, specifically for a gae/django/python setup, so the website knows what language it should be loading the pages in depending on the url.

Here are my suggestions, please chime in on what you think is best:

SUBDOMAIN: http://fr.mysite.com/
But is this possible to have different subdomains, such as "en", "fr", "de", and still point to the same google app in your account?

DOMAIN EXTENSION: http://www.mysite.fr/ Would it be possible to purchase different domain names for each of the languages, then point it to the same app?

FIRST FOLDER: http://www.mysite.com/fr/about-us This method would work, but would be annoying to code for and I'd rather not have longer urls than needed. Thoughts?

Are there any other options I'm not thinking of? Any advice would be appreciated, thanks.

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

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

发布评论

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

评论(2

仙女山的月亮 2024-10-07 00:38:25

我只是想指出,这也可以通过 url 中的前缀来完成。
像这样:

www.site.com/en/rest_of_url

www.site.com/fr/rest_of_url

该应用程序将设置如下:

 class LanguageHandler(webapp2.RequestHandler):
     def dispatch(self):
         request = self.request
         args = request.route_args
         if len(args) and args[0] in ['en','fr']:
             self.language = args[0]
             request.route_args = args[1:]
         try:
             # Dispatch the request.
             webapp2.RequestHandler.dispatch(self)
         finally:
             # The web page response Header will now include the 2 letter language code...
             self.response.headers['Content-Language'] = str(self.language)

 class HomePage(LanguageHandler):
     def get(self):
         # self.language is now 'en' or 'fr'
         # ...code goes here...

 app = webapp2.WSGIApplication([
     (r'/(en|fr)', HomePage),
 ], debug = True)

I just wanted to point out that this could also be done with a prefix in the url.
Like these:

www.site.com/en/rest_of_url

www.site.com/fr/rest_of_url

the app would be setup like this:

 class LanguageHandler(webapp2.RequestHandler):
     def dispatch(self):
         request = self.request
         args = request.route_args
         if len(args) and args[0] in ['en','fr']:
             self.language = args[0]
             request.route_args = args[1:]
         try:
             # Dispatch the request.
             webapp2.RequestHandler.dispatch(self)
         finally:
             # The web page response Header will now include the 2 letter language code...
             self.response.headers['Content-Language'] = str(self.language)

 class HomePage(LanguageHandler):
     def get(self):
         # self.language is now 'en' or 'fr'
         # ...code goes here...

 app = webapp2.WSGIApplication([
     (r'/(en|fr)', HomePage),
 ], debug = True)
油饼 2024-10-07 00:38:25

从发展的角度来看,这三种都是可能的。 “域名扩展”模型可能会被证明是昂贵的,并且可能是不可能的,具体取决于您的资源和您希望支持的语言 - 例如,.fr 仅限于法国境内的居民或实体。

“第一个文件夹”模型的编程可能并不困难。设置处理程序时,您可以执行以下操作:

application = webapp.WSGIApplication(
[
  ('/(en|fr|de)/', IndexController),
]

然后将语言标识符作为第一个参数显式传递给处理程序。

正如您所指出的,从 url 的角度来看,子域将是最干净的。正如 PythonRuntime 环境 文档中所述,您可以将多个子域映射到相同的应用程序 - 事实上托管应用程序都会响应 [anything].[应用程序名称].appspot.com。可以从请求对象中提取用于访问的主机。

总的来说,这似乎更多的是个人偏好。

All three of those are possibilities from a development standpoint. The "domain extension" model is likely to prove to be expensive and possibly impossible depending on your resources and the languages you wish to support - .fr for example is restricted to only residents or entities with a French presence.

The "first folder" model may not be that difficult to program for. When setting up your handlers, you could do something like this:

application = webapp.WSGIApplication(
[
  ('/(en|fr|de)/', IndexController),
]

Which would then explicitly pass the language identifier in as the first parameter to the handler.

Subdomains, as you pointed out, are going to be the cleanest from a url perspective. As noted in the PythonRuntime Environment docs you can map multiple subdomains to the same application - in fact hosted applications will all respond to [anything].[application name].appspot.com. The host used for access can be extracted from the request object.

Overall it seems like more of a personal preference than anything else.

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