Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django: Generating sitemap for multilingual sites

Tags:

django

I've created a small article site. I am using, translema to store the same article in several languages (it creates copies of selected fields in the database, so they can be translated), How can I generate sitemaps in this case?

(Forget to say, that I am using localurl application, so my urls look like this http://site/en).

like image 478
Oleg Tarasenko Avatar asked Jan 22 '10 08:01

Oleg Tarasenko


3 Answers

To generate sitemap per language you can use something like this:

from django.contrib.sitemaps import Sitemap
from pages.models import Page

class PageSitemap(Sitemap):
   priority = 0.5
   # this generates urls per language
   i18n = True

   def items(self):
     pages = Page.objects.filter(
        status=Page.PUBLISHED).order_by('-updated_at')
    return pages

   def lastmod(self, obj):
     return obj.updated_at
like image 156
Dimitris Kougioumtzis Avatar answered Nov 18 '22 06:11

Dimitris Kougioumtzis


The sitemap app works by letting you write sitemap classes, that each have an items method. You simply have to construct one such class per language you have, and make sure you query only models with that specific language for each class. The documentation has a simple sitemap example to get you started.

like image 22
Emil Stenström Avatar answered Nov 18 '22 07:11

Emil Stenström


not sure what the "translema" is but if you would use the Candy Translate instead it will be:

  • much faster (do not use DB)
  • will create the sitemap for you that will contain all language versions
like image 1
varciasz Avatar answered Nov 18 '22 05:11

varciasz