Commits

Branko Vukelic  committed d78c52c

Added get_available_languages admin method

  • Participants
  • Parent commits e55eb7d

Comments (0)

Files changed (2)

File i18n_model/models.py

         language_code = language_code or get_language()
         return self.get(i18n_language=language_code)
 
+    def get_available_languages(self):
+        return [t.i18n_language for t in self.all()]
+
     def __new__(cls, *args, **kwargs):
         for language in settings.LANGUAGES:
             language_code = language[0]

File tests/test_translation_method.py

             self.post.translations.de().get(),
             self.post.translations.lang('de').get()
         )
+
+    def test_get_available_translations(self):
+        """
+        Test getting the languages in which model is translated
+        """
+
+        PostI18N.translate(
+            self.post,
+            'de',
+            title='Test-Titel',
+            body='Dies ist ein Test Beitrag',
+        )
+
+        self.assertEqual(
+            self.post.translations.get_available_languages(),
+            ['de']
+        )
+
+        PostI18N.translate(
+            self.post,
+            'it',
+            title='Titolo di prova',
+            body='Questo è un post di prova'
+        )
+
+        self.assertEqual(
+            self.post.translations.get_available_languages(),
+            ['de', 'it']
+        )
+
+