Commits

Apostolis Bessas  committed 524bfe4

Create translations builder that marks the source strings.

This allows the compiler to tell them apart and manage the source strings differently than the transaltions themselves.

  • Participants
  • Parent commits ddf8666

Comments (0)

Files changed (2)

File transifex/resources/formats/compilation/__init__.py

 from .decorators import NormalDecoratorBuilder, PseudoDecoratorBuilder, \
         EmptyDecoratorBuilder
 from .builders import AllTranslationsBuilder, EmptyTranslationsBuilder, \
-        ReviewedTranslationsBuilder, SourceTranslationsBuilder
+        ReviewedTranslationsBuilder, SourceTranslationsBuilder, \
+        MarkedSourceTranslationsBuilder
 from .factories import SimpleCompilerFactory, FillEmptyCompilerFactory, \
         AlwaysFillEmptyCompilerFactory, EmptyCompilerFactory
 from .mode import Mode

File transifex/resources/formats/compilation/builders.py

                 resource=self.resource
         ).values_list('id', flat=True))
         missing_ids = source_entities - set(map(lambda x: x[0], translations))
-        source_strings = Translation.objects.filter(
-            source_entity__in=missing_ids,
-            language=self.resource.source_language
+        if not missing_ids:
+            return self._output(translations)
+        source_strings = self._get_source_strings(missing_ids)
+        return self._output(itertools.chain(translations, source_strings))
+
+    def _get_source_strings(self, ids):
+        """Get a list of the source strings of the resource.
+
+        Args:
+            The ids to fetch source strings for.
+        """
+        return Translation.objects.filter(
+            source_entity__in=ids, language=self.resource.source_language
         ).values_list(*self._fields)
-        return self._output(itertools.chain(translations, source_strings))
 
 
 class ReviewedSourceTranslationsBuilder(TranslationsBuilder):
             language=self.resource.source_language
         ).values_list(*self._fields)
         self._output(itertools.chain(translations, source_strings))
+
+
+class MarkedSourceTranslationsBuilder(SourceTranslationsBuilder):
+    """Mark the source strings, so that the compiler knows
+    how to handle those.
+    """
+
+    def _get_source_strings(self, ids):
+        """Mark the source strings with a _txss before returning them."""
+        strings = super(
+            MarkedSourceTranslationsBuilder, self
+        )._get_source_strings(ids)
+        res = []
+        for s in strings:
+            res.append(list(s))
+            res[-1][1] = s[1] + '_txss'
+        return res