Designed for an international audience in multiple languages, the Google App Engine

I create a site on the Google engine, and its main code and database are designed to handle different languages ​​and regions.

What I'm really looking for is suggestions on how the URL should be structured, in particular for setting up gae / django / python, so the website knows what language it should load pages, depending on the URL .

Here are my suggestions, please call back what you think is best:

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

DOMAIN EXTENSION: http://www.mysite.fr / Is it possible to purchase different domain names for each of the languages, then specify it in the same application?

FIRST FOLDER: http://www.mysite.com/fr/about-us This method will work, but it will be annoying to the code, d most likely do not have longer URLs than necessary. Thoughts?

Are there any other options that I don't think about? Any advice would be appreciated, thanks.

+3
source share
2 answers

- . " ", , , , , - ,.fr .

" " . - :

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

.

, , URL. PythonRuntime Environment, - []. [ ].appspot.com. , , .

, - .

+1

, 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)
+3

Source: https://habr.com/ru/post/1772726/


All Articles