1

I am developping a Django 3.0 application. This application has to support two languages, French and English. I don't foresee it supporting any other language in the future.

Given that I only have two language, I want to support them directly in the models and not resort to apps that do funky things like adding them on the fly (for performance and simplicity reasons).

Now, let's say I have a model class that looks like this:

class Organization(models.Model):
  name_en = models.CharField(max_length=100)
  name_fr = models.CharField(max_length=100)

  def __str__(self):
      # how do I return the name_en or name_fr, based on active language ? 

I'm guessing this might have to do with lazy_get_text, but I feel like I'm missing something.

Also, in templates, aside from blocktrans to display/format fields based on active language, is there something else I should be aware of ?

Martin
  • 5,954
  • 5
  • 30
  • 46
  • 1
    See: [How can I get the current language in Django?](https://stackoverflow.com/questions/3356964/) – Flux May 01 '20 at 22:30
  • Thanks, I'll take a look. – Martin May 01 '20 at 22:47
  • I took a look at it and it worked as needed. However, I finally ended up using an app called django-modeltranslation. It does some funky things to the model, but not too muche. When I realized that I would need to create getters for each property of my models to use the current language, the time saving of this app outweighted the cons. – Martin May 07 '20 at 11:54

0 Answers0