Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an internationalized Google App Engine application

I would like to provide my Python GAE website in the user's own language, using only the tools available directly in App Engine. For that, I would like to use GNU gettext files (.po and .mo files).

Has someone successfully combined Python Google App Engine and gettext files? If so, could you please provide the steps you used?

I had started a discussion in GAE's Google group, but haven't been able to extract from it how I'd like to do it: I don't want to add external dependencies, like Babel (suggested in the discussion). I want to use plain vanilla Google App Engine, so no manual update of Django or this kind of stuff.

At first, I will start using the language sent by the browser, so no need to manually force the language by using cookies etc. However, I might add a language changing feature later, once the basic internationalization works.

As a background note to give you more details about what I'm trying to do, I would like to internationalize Issue Tracker Tracker, an open source application I've hosted on Launchpad. I plan to use Launchpad's translation platform (explaining why I'd like to use .mo files). You can have a look at the source code in it's Bazaar branch (sorry no link due to stackoverflow spam prevention limit for new users...)

Thanks for helping me advance on this project!

like image 623
Emilien Avatar asked Dec 22 '09 13:12

Emilien


People also ask

What is the back end application engine?

The Google App Engine is a platform for building scalable web applications and mobile backends. The App Engine provides you with built-in services and APIs such as NoSQL datastores, memcache, and a user authentication API, which is common to most applications (source two).

Can I use Google App Engine for free?

App Engine standard environment pricing. Apps in the standard environment have a free tier for App Engine resources. Any use of App Engine resources beyond the free tier incurs charges as described in this section.


2 Answers

As my needs were simple, I used a simple hack instead of (unavailable) gettext. I created a file with string translations, translate.py. Approximately like this:

en={}
ru={}

en['default_site_title']=u"Site title in English"
ru['default_site_title']=u"Название сайта по-русски"

Then in the main code I defined a function which returns a dictionary with translations into the most suitable language from the list (the first one to have a translation is used or English):

import translate

def get_messages(languages=[]):
    msgs=translate.en
    for lang in languages:
        if hasattr(translate,lang):
            msgs=getattr(translate,lang)
            break
    return msgs

Usage:

msgs = get_messages(["it","ru","en"])
hi = msgs['hello_message'] % 'yourname'

I also defined a helper function which extracts a list of languages from Accept-Language header.

It's not the most flexible solution, but it doesn't have any external dependencies and works for me (in a toy project). I think translate.py may be generated automatically from gettext files.

In case you want to see more, my actual source is here.

like image 57
sastanin Avatar answered Sep 20 '22 09:09

sastanin


You can use the Django internationalisation tool, like explained here.

They are also saying that there is no easy way to do this.

I hope that helps you :)

like image 40
Joschua Avatar answered Sep 20 '22 09:09

Joschua