I'm using django-multilingual for a Django based website. When I define the __unicode__
function for a model to return this way:
def __unicode__(self):
return unicode(self.title)
However my default language is English and I have some items that are inserted in Dutch only. When I preview the full list, I get "None" as a title.
Is there an easy way to try to get the English title and then check for a title in any other language just for preview?
Iterating over all translations can be easily done like this:
>>> translations = [getattr(obj, "name_" + lang[0].replace("-","_")) for lang in
settings.LANGUAGES]
Where obj is the model object, and lang will represent a tuple ('bg', 'Bulgarian') from your settings file.
lang[0].replace("-","_") is required, in case that you have languages like "uk-gb", because those values are placed into name_uk_gb