Hey, i am currently working on a django app for my studies, and came to the point of l18n. Localizing the site itself was very easy, but now i have to allow users, to transl
It depends on who will provide the translations. If you want to provide a web interface to translation, then you need to develop that yourself, and also represent the translations in the database.
If the same translators who translated the site will also translate the data, you can provide them with the same model that they use for the site (presumably gettext), and you can then also use gettext for this content.
Also looking for content localization plugin, or how to write it. Can add to the list django-i18n-model
I think you should operate in two steps:
For the first step, you should tell Django that the user-inserted strings are to be translated. I think there is no native way to do so. Maybe you can extract the strings from your db putting them in locale-specific files, run 'makemessages' on them, obtaint django.po files and translate.
Second, use ugettext to show those strings on your web application.
Hope this can help the ones with your same problem.
I have 2 languages on my site: English and Arabic Users can switch between languages clicking on a flag. In models i use a proxy model:
class Product(models.Model):
name=models.CharField(max_length=100)
name_ar=models.CharField(max_length=100, default='')
def __unicode__(self):
return self.name
class Product_ar(Product):
def __unicode__(self):
return self.name_ar
class Meta:
proxy=True
In forms I use 2 forms instead of one:
class CollectionEditForm_en(forms.Form):
name = forms.CharField(label=_('Name'), max_length=100, widget=forms.TextInput(attrs={'size':'50'}))
product = forms.ModelChoiceField(label=_('product'), queryset=Product.objects.filter(enabled=True), empty_label=None)
class CollectionEditForm_ar(forms.Form):
name = forms.CharField(label=_('Name'), max_length=100, widget=forms.TextInput(attrs={'size':'50'}))
product = forms.ModelChoiceField(label=_('product'), queryset=Product_ar.objects.filter(enabled=True), empty_label=None)
In code check language this way:
if request.LANGUAGE_CODE=='ar':
CollectionEditForm=CollectionEditForm_ar
else:
CollectionEditForm=CollectionEditForm_en
So in templates i check:
{% if LANGUAGE_CODE == "ar" %}
<a href="/product/{{product.alias}}/">{{product.name_ar}}</a>
{% else %}
<a href="/product/{{product.alias}}/">{{product.name}}</a>
{% endif %}
Hope this solution will help somebody
"i must provide a way of translating theses names and descriptions to the users."
"Is there a natural way in django to do this?"
Are you asking if Django can translate from language to language? Are you asking about something like http://translate.google.com/ ?
I don't think Django can translate user input into another language.
If you are going to do the translation for your users, this must be part of your data model.
Django's i18n filter allows you to have a table of translation strings. The documentation says this.
I use django-multilingual for localize content and django-localeurl for choosing language based on url (for example mypage/en/).
You can see how multilingua and localeurl work on JewishKrakow.net page.