1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 |
|
---|
4 | from django.db import models
|
---|
5 | from django.conf import settings
|
---|
6 | from django.utils.translation import get_language, gettext_lazy as _
|
---|
7 |
|
---|
8 | languages_available = settings.LANGUAGES
|
---|
9 |
|
---|
10 | class Message(models.Model):
|
---|
11 | """A message which is to translate"""
|
---|
12 | text = models.TextField(_('original message'), unique=True)
|
---|
13 |
|
---|
14 | def __unicode__(self):
|
---|
15 | """A nice representation for the user"""
|
---|
16 | return self.text
|
---|
17 |
|
---|
18 | def save(self, *args, **kwargs):
|
---|
19 | self.text = self.text.strip()
|
---|
20 | super(Message, self).save(*args, **kwargs)
|
---|
21 |
|
---|
22 | class Translation(models.Model):
|
---|
23 | """Translation"""
|
---|
24 | message = models.ForeignKey(Message)
|
---|
25 | language = models.CharField(_('language'), max_length=5,
|
---|
26 | choices=settings.LANGUAGES)
|
---|
27 | translation = models.TextField(_('translation'))
|
---|
28 |
|
---|
29 | def save(self, *args, **kwargs):
|
---|
30 | self.translation = self.translation.strip()
|
---|
31 | super(Translation, self).save(*args, **kwargs)
|
---|
32 |
|
---|
33 | def __unicode__(self):
|
---|
34 | return u"%s: %s" % (self.language, self.translation)
|
---|