Multiple domains, multiple languages on GAE and Django
I’m using the very excellent app-engine-patch to run Django on Google App Engine.
One requirement is that my sites are multi-lingual.
www.french.com is a French site with its own design.
www.english.com is has different language, different look.
The app-engine-patch provides ragendja’s dynamicsite module – very handy.
This will let me match domain names to sites very easily.
For the language, I have simply amended it – I should override it with a pluggable. This is left for an exercise for the reader.
I created a mapping table:
class SiteLanguage(db.Model):
language = db.StringProperty()
site = db.ReferenceProperty(Site)
def __unicode__(self):
return self.language + '-' + str(self.site)
Then I opened dynamicsite.py, and added the language setter at line 28ish:
#set language appropriately
lang = SiteLanguage.gql('WHERE site = :1', site).get()
if lang:
translation.activate(lang.language)
request.LANGUAGE_CODE = translation.get_language()
with the imports too of course:
from django.utils import translation
from xxx.models import SiteLanguage
and popped it in my admin screens so I can assign sites to languages:
class SiteLanguageAdmin(admin.ModelAdmin):
list_display = ('site','language',)
admin.site.register(SiteLanguage, SiteLanguageAdmin)
Done!