针对国际受众,多种语言构建的Google App Engine网站

时间:2022-11-10 23:15:11

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.

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

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?

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

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?

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

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?

第一个文件夹:http://www.mysite.com/fr/about-us这个方法可以工作,但代码编码很麻烦,我宁愿没有比需要更长的网址。思考?

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

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

2 个解决方案

#1


1  

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.

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

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

总的来说,这似乎更像是个人偏好而不是其他任何东西。

#2


3  

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

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

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)

#1


1  

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.

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

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

总的来说,这似乎更像是个人偏好而不是其他任何东西。

#2


3  

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

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

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)