How to localize the application in Google App Engine?

What are the options for localizing an application in Google App Engine? How do you do this using Webapp, Django, web2py or [insert framework here].

1. Readable URLs and entity key names

Readable URLs are good for usability and search engine optimization (Stack Overflow is a good example of how to do this). Google App Engine recommends keyword queries for performance reasons. It follows that it is good practice to use the key name of an object in a URL so that an entity can be retrieved from the data store as quickly as possible.

Some characters have special meanings in URLs (&, ",", etc.). To be able to use key names as parts of a URL, they must not contain any of these characters. I am currently using the following function to create key names:

import re import unicodedata def urlify(unicode_string): """Translates latin1 unicode strings to url friendly ASCII. Converts accented latin1 characters to their non-accented ASCII counterparts, converts to lowercase, converts spaces to hyphens and removes all characters that are not alphanumeric ASCII. Arguments unicode_string: Unicode encoded string. Returns String consisting of alphanumeric (ASCII) characters and hyphens. """ str = unicodedata.normalize('NFKD', unicode_string).encode('ASCII', 'ignore') str = re.sub('[^\w\s-]', '', str).strip().lower() return re.sub('[-\s]+', '-', str) 

This is basically a whitelist for approved characters. It is great for English and Swedish, however it is not suitable for non-Western scripts and removes letters from some Western languages ​​(for example, Norwegian and Danish with their Ε“ and ΓΈ).

Can anyone suggest a method that works with a lot of languages? Would it be better to remove the problematic characters (blacklist)?

2. Translation of templates

Does Django Internationalize and Localize on Google App Engine? Are there any additional steps that need to be completed? Can I use Django i18n and l10n for Django templates when using Webapp?

The Jinja2 template language provides integration with Babel . How well does this work in your experience?

What options are available for the selected template language?

3. Translated data warehouse content

When serving content (or storing it) in a data warehouse: is there a better way than getting the accept_language parameter from an HTTP request and matching it with the language property that you set with each object?

+4
source share
2 answers

As for point 1, there really is no need to go to such lengths: just use Unicode key names. They will be encoded as UTF-8 in the data warehouse for you.

With respect to paragraph 3, there are many ways to process language recognition. Of course, accept_language should be part of this, and you will find web_ accept_language support especially useful here (I hope that Django or your picker system is something similar). However, quite often it happens that the language setting of the user’s browser is incorrect, so you need to make sure that there is some way for the user to override the detected language - for example, by changing the link on each page the language by setting the cookie preferences.

+3
source

Regarding point 2, I asked a similar question a few months ago. I managed to get the application internationalized, but only the content, not the URL (also did not plan to do this).

I also added a fix that I made for my code so that people can see what changes have been made to this Google App Engine application. Take a look at my second comment on the accepted answer.

Good luck with the other two points!

+2
source

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


All Articles