Browse Source

Add more strings to translate

Baptiste Jonglez 8 years ago
parent
commit
75b88a3961
4 changed files with 43 additions and 17 deletions
  1. 1 1
      celutz/settings.py
  2. 3 2
      panorama/admin.py
  3. 10 0
      panorama/apps.py
  4. 29 14
      panorama/models.py

+ 1 - 1
celutz/settings.py

@@ -37,7 +37,7 @@ INSTALLED_APPS = (
     # For Celery
     'kombu.transport.django',
     'rest_framework',
-    'panorama',
+    'panorama.apps.PanoramaConfig',
     'api'
 )
 

+ 3 - 2
panorama/admin.py

@@ -4,6 +4,7 @@ from __future__ import unicode_literals
 import os
 
 from django.contrib import admin
+from django.utils.translation import ugettext_lazy as _
 
 from .models import Panorama, ReferencePoint, Reference
 from .utils import path_exists
@@ -29,8 +30,8 @@ class PanoramaAdmin(admin.ModelAdmin):
         for pano in queryset:
             pano.delete_tiles()
             pano.generate_tiles()
-        self.message_user(request, "Launched tiles regeneration, it may take some time to complete")
-    regenerate_tiles.short_description = "Regenerate tiles for the selected panoramas"
+        self.message_user(request, _("Launched tiles regeneration, it may take some time to complete"))
+    regenerate_tiles.short_description = _("Regenerate tiles for the selected panoramas")
 
 
 @admin.register(ReferencePoint)

+ 10 - 0
panorama/apps.py

@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals, division, print_function
+
+from django.apps import AppConfig
+from django.utils.translation import ugettext_lazy as _
+
+
+class PanoramaConfig(AppConfig):
+    name = 'panorama'
+    verbose_name = _("Panorama")

+ 29 - 14
panorama/models.py

@@ -110,6 +110,10 @@ class ReferencePoint(Point):
     def __str__(self):
         return self.name
 
+    class Meta:
+        verbose_name = _("reference point")
+        verbose_name_plural = _("reference points")
+
 
 class Panorama(ReferencePoint):
     loop = models.BooleanField(default=False, verbose_name=_("360° panorama"),
@@ -117,12 +121,13 @@ class Panorama(ReferencePoint):
     image = models.ImageField(verbose_name=_("image"), upload_to="pano",
                               width_field="image_width",
                               height_field="image_height")
-    image_width = models.PositiveIntegerField(default=0)
-    image_height = models.PositiveIntegerField(default=0)
+    image_width = models.PositiveIntegerField(default=0, verbose_name=_("image width"))
+    image_height = models.PositiveIntegerField(default=0, verbose_name=_("image height"))
     # Set of references, i.e. reference points with information on how
     # they relate to this panorama.
     references = models.ManyToManyField(ReferencePoint, through='Reference',
-                                        related_name="referenced_panorama")
+                                        related_name="referenced_panorama",
+                                        verbose_name=_("references"))
 
     def tiles_dir(self):
         return os.path.join(settings.MEDIA_ROOT, settings.PANORAMA_TILES_DIR,
@@ -135,6 +140,7 @@ class Panorama(ReferencePoint):
     def has_tiles(self):
         return path_exists(self.tiles_dir()) and len(os.listdir(self.tiles_dir())) > 0
     has_tiles.boolean = True
+    has_tiles.short_description = _("Tiles available?")
 
     def delete_tiles(self):
         """Delete all tiles and the tiles dir"""
@@ -272,6 +278,10 @@ class Panorama(ReferencePoint):
                 (ref2.x - ref1.x)
         return target_cap % 360
 
+    class Meta:
+        verbose_name = _("panorama")
+        verbose_name_plural = _("panoramas")
+
 
 @python_2_unicode_compatible
 class Reference(models.Model):
@@ -282,8 +292,10 @@ class Reference(models.Model):
     are represented by (azimuth, elevation) couples."""
 
     # Components of the ManyToMany relation
-    reference_point = models.ForeignKey(ReferencePoint, related_name="refpoint_references")
-    panorama = models.ForeignKey(Panorama, related_name="panorama_references")
+    reference_point = models.ForeignKey(ReferencePoint, related_name="refpoint_references",
+                                        verbose_name=_("reference point"))
+    panorama = models.ForeignKey(Panorama, related_name="panorama_references",
+                                 verbose_name=_("panorama"))
     # Position of the reference point in the panorama image
     x = models.PositiveIntegerField()
     y = models.PositiveIntegerField()
@@ -297,21 +309,24 @@ class Reference(models.Model):
         # Check that the reference point and the panorama are different
         # (remember that panoramas can *also* be seen as reference points)
         if self.panorama.pk == self.reference_point.pk:
-            raise ValidationError("A panorama can't reference itself.")
+            raise ValidationError(_("A panorama can't reference itself."))
         # Check than the position is within the bounds of the image.
         w = self.panorama.image_width
         h = self.panorama.image_height
         if self.x >= w or self.y >= h:
-            raise ValidationError("Position ({x}, {y}) is outside the bounds "
-                                  "of the image ({width}, {height}).".format(
-                                      x=self.x,
-                                      y=self.y,
-                                      width=w,
-                                      height=h))
+            raise ValidationError(_("Position {xy} is outside the bounds "
+                                    "of the image ({width}, {height}).").format(
+                                        xy=(self.x, self.y),
+                                        width=w,
+                                        height=h))
 
     def __str__(self):
-        return '{ref}: at {xy} in {pano}'.format(
+        return _('{refpoint} at {xy} in {pano}').format(
                 pano=self.panorama.name,
                 xy=(self.x, self.y),
-                ref=self.reference_point.name,
+                refpoint=self.reference_point.name,
                 )
+
+    class Meta:
+        verbose_name = _("reference")
+        verbose_name_plural = _("references")