Skip to content

Commit 4727395

Browse files
committed
WIP backend translations
1 parent bb11ccd commit 4727395

File tree

10 files changed

+1092
-39
lines changed

10 files changed

+1092
-39
lines changed

django/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ migrate:
5252
$(DOCKER_EXEC) python3 manage.py migrate
5353
make collectstatic
5454

55+
makemessages:
56+
$(DOCKER_EXEC) python3 manage.py makemessages --all
57+
58+
compilemessages:
59+
$(DOCKER_EXEC) python3 manage.py compilemessages
60+
5561
createcachetable:
5662
$(DOCKER_EXEC) python3 manage.py createcachetable
5763

django/gsmap/admin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def make_published(self, request, queryset):
249249
updated,
250250
) % updated, messages.SUCCESS)
251251
# todo refactor when upgrading to django 3.2 as action decorator
252-
make_published.short_description = "Publish selected annotations"
252+
make_published.short_description = _("Publish selected annotations")
253253
make_published.allowed_permissions = ('publish',)
254254

255255
# @admin_.action(description='Publish selected annotations')
@@ -261,7 +261,7 @@ def make_unpublished(self, request, queryset):
261261
updated,
262262
) % updated, messages.SUCCESS)
263263
# todo refactor when upgrading to django 3.2 as action decorator
264-
make_unpublished.short_description = "Unpublish selected annotations"
264+
make_unpublished.short_description = _("Unpublish selected annotations")
265265
make_unpublished.allowed_permissions = ('publish',)
266266

267267
def has_publish_permission(self, request):
@@ -303,7 +303,7 @@ def export_as_csv(self, request, queryset):
303303
r.data
304304
])
305305
return response
306-
export_as_csv.short_description = "Export selected annotations"
306+
export_as_csv.short_description = _("Export selected annotations")
307307
export_as_csv.allowed_permissions = ('export',)
308308

309309
def has_export_permission(self, request):

django/gsmap/models.py

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ def get_available_name(self, name, max_length=None):
4949

5050
class Municipality(models.Model):
5151
class Meta:
52-
verbose_name_plural = 'municipalities'
52+
verbose_name_plural = _('municipalities')
5353
ordering = ['name']
54+
verbose_name = _("municipality")
5455

5556
CANTONS_CHOICES = [
5657
('GR', 'Graubünden'),
@@ -117,6 +118,8 @@ class SnapshotPermission(IntFlag):
117118
class Snapshot(models.Model):
118119
class Meta:
119120
ordering = ['-created']
121+
verbose_name = _("snapshot")
122+
verbose_name_plural = _("snapshots")
120123

121124
id = models.CharField(
122125
max_length=8, unique=True,
@@ -324,27 +327,28 @@ def resave(sender, instance, created, **kwargs):
324327

325328
class Category(TranslatableModel):
326329
class Meta:
327-
verbose_name_plural = 'categories'
330+
verbose_name_plural = _('categories')
328331
ordering = ['namespace']
332+
verbose_name = _("category")
329333

330-
created = models.DateTimeField(auto_now_add=True)
331-
modified = models.DateTimeField(auto_now=True)
332-
deleted = models.BooleanField(default=False)
334+
created = models.DateTimeField(_("created"), auto_now_add=True)
335+
modified = models.DateTimeField(_("modified"), auto_now=True)
336+
deleted = models.BooleanField(_("deleted"), default=False)
333337

334338
# my_order = models.PositiveIntegerField(default=0, blank=False, null=False)
335-
hide_in_list = models.BooleanField(default=False)
339+
hide_in_list = models.BooleanField(_("hide in list"), default=False)
336340

337341
namespace = models.CharField(max_length=255, default='core/beteiligung')
338-
icon = models.FileField(upload_to='category-icons', null=True, blank=True)
339-
color = models.CharField(max_length=7, default='#cccccc')
342+
icon = models.FileField(_("icon"), upload_to='category-icons', null=True, blank=True)
343+
color = models.CharField(_("color"), max_length=7, default='#cccccc')
340344

341345
group = models.ForeignKey(
342346
Group, default=None, blank=True,
343347
null=True, on_delete=models.SET_NULL
344348
)
345349

346350
translations = TranslatedFields(
347-
name=models.CharField(max_length=255),
351+
name=models.CharField(_("name"), max_length=255),
348352
)
349353
# workspace = models.ForeignKey(Workspace, on_delete=models.CASCADE)
350354

@@ -355,12 +359,13 @@ def __str__(self):
355359

356360
class Usergroup(TranslatableModel):
357361
class Meta:
358-
verbose_name_plural = 'usergroups'
362+
verbose_name_plural = _('usergroups')
363+
verbose_name = _("usergroup")
359364
# ordering = ['name']
360365

361-
created = models.DateTimeField(auto_now_add=True)
362-
modified = models.DateTimeField(auto_now=True)
363-
deleted = models.BooleanField(default=False)
366+
created = models.DateTimeField(_("created"), auto_now_add=True)
367+
modified = models.DateTimeField(_("modified"), auto_now=True)
368+
deleted = models.BooleanField(_("deleted"), default=False)
364369

365370
key = models.CharField(
366371
max_length=50, unique=True,
@@ -373,7 +378,7 @@ class Meta:
373378
)
374379

375380
translations = TranslatedFields(
376-
name=models.CharField(max_length=255),
381+
name=models.CharField(_("name"), max_length=255),
377382
)
378383

379384
def __str__(self):
@@ -384,6 +389,8 @@ def __str__(self):
384389
class Workspace(TranslatableModel):
385390
class Meta:
386391
ordering = ['-created']
392+
verbose_name = _("workspace")
393+
verbose_name_plural = _("workspaces")
387394

388395
id = models.CharField(
389396
max_length=8, unique=True,
@@ -404,7 +411,7 @@ class Meta:
404411
]
405412
mode = models.CharField(max_length=3, choices=MODE_CHOICES, default="OFF")
406413

407-
group =models.ForeignKey(
414+
group = models.ForeignKey(
408415
Group, default=None, blank=True,
409416
null=True, on_delete=models.SET_NULL
410417
)
@@ -459,21 +466,23 @@ class Annotation(models.Model):
459466
class Meta:
460467
ordering = ['-created']
461468
permissions = [
462-
('publish_annotation', 'Can publish annotations'),
463-
('export_annotation', 'Can export annotations'),
469+
('publish_annotation', _('Can publish annotations')),
470+
('export_annotation', _('Can export annotations')),
464471
]
472+
verbose_name = _("annotation")
473+
verbose_name_plural = _("annotations")
465474

466-
created = models.DateTimeField(auto_now_add=True)
467-
modified = models.DateTimeField(auto_now=True)
468-
deleted = models.BooleanField(default=False)
469-
public = models.BooleanField(default=False)
475+
created = models.DateTimeField(_("created"), auto_now_add=True)
476+
modified = models.DateTimeField(_("modified"), auto_now=True)
477+
deleted = models.BooleanField(_("deleted"), default=False)
478+
public = models.BooleanField(_("public"), default=False)
470479

471480
KIND_CHOICES = [
472-
('COM', 'Comment'),
473-
('PLY', 'Polygon'),
481+
('COM', _('Comment')),
482+
('PLY', _('Polygon')),
474483
]
475-
kind = models.CharField(max_length=3, choices=KIND_CHOICES)
476-
data = models.JSONField(default=dict)
484+
kind = models.CharField(_("kind"), max_length=3, choices=KIND_CHOICES)
485+
data = models.JSONField(_("data"), default=dict)
477486
category = models.ForeignKey(
478487
Category, default=None, blank=True,
479488
null=True, on_delete=models.SET_NULL
@@ -482,8 +491,8 @@ class Meta:
482491
Usergroup, default=None, blank=True,
483492
null=True, on_delete=models.SET_NULL
484493
)
485-
author_email = models.EmailField(max_length=254)
486-
rating = models.DecimalField(default=0, decimal_places=2, max_digits=6)
494+
author_email = models.EmailField(_("author email"), max_length=254)
495+
rating = models.DecimalField(_("rating"), default=0, decimal_places=2, max_digits=6)
487496
workspace = models.ForeignKey(Workspace, on_delete=models.CASCADE)
488497

489498
def save(self, *args, **kwargs):
@@ -540,6 +549,8 @@ def __str__(self):
540549
class Attachement(models.Model):
541550
class Meta:
542551
ordering = ['my_order']
552+
verbose_name = _("attachment")
553+
verbose_name_plural = _("attachments")
543554

544555
created = models.DateTimeField(auto_now_add=True)
545556
modified = models.DateTimeField(auto_now=True)
@@ -553,26 +564,26 @@ class Meta:
553564
@receiver(post_save, sender=Annotation)
554565
def send_new_annotation_email(sender, instance, created, **kwargs):
555566

556-
if created:
567+
if created and instance.author_email:
557568
recipient = instance.author_email
558-
subject = 'Kommentar freischalten'
559-
message = 'Besten Dank für Ihren Kommentar!\n'
569+
subject = _('Kommentar freischalten')
570+
message = _('Besten Dank für Ihren Kommentar!\n')
560571

561572
website = get_website(Site.objects.get_current())
562573

563-
if instance.workspace.annotations_open:
574+
if instance.workspace.annotations_open or instance.workspace.polygon_open:
564575
idstr = str(instance.id)
565576

566577
uniquestr = recipient + idstr + SECRET_KEY
567578
publishKeyHex = hashlib.md5(uniquestr.encode()).hexdigest()
568579
publish_url = reverse('annotation-publish', args=[idstr, publishKeyHex])
569580

570-
message += 'Sie können ihn unter folgender URL freischalten:\n'
571-
message += f'{website["base"]}{publish_url}\n'
581+
message += _('Sie können ihn unter folgender URL freischalten:\n')
582+
message += _(f'{website["base"]}{publish_url}\n')
572583
message += '--' * 30
573584
else:
574-
message += "Leider ist die Beteiligung nun abgeschlossen.\n"
575-
message += f"Zur Karte mit allen öffentlichen Kommentaren: {website['base']}/de/{instance.workspace.pk}/{instance.workspace.snapshots.first().pk}/"
585+
message += _("Leider ist die Beteiligung nun abgeschlossen.\n")
586+
message += _(f"Zur Karte mit allen öffentlichen Kommentaren: {website['base']}/de/{instance.workspace.pk}/{instance.workspace.snapshots.first().pk}/")
576587
message += '--' * 30
577588

578589
send_mail(
4.76 KB
Binary file not shown.

0 commit comments

Comments
 (0)