Esempio n. 1
0
    def generate_translation_jobs(self):
        """Returns a list of tuples, one for each translation job

        If the locale of this response is English, then we just copy over
        the description and we're done.

        If the product of this response isn't set up for auto-translation,
        then we're done.

        If we already have a response with this text that's
        translated, we copy the most recent translation over.

        Otherwise we generate a list of jobs to be done.

        .. Note::

           This happens in a celery task, so feel free to do what you need
           to do here.

        """
        # If the text is in English, we copy it over and we're
        # done. We do this regardless of whether auto-translation is
        # enabled or not for this product.
        if self.locale == "en-US":
            self.translated_description = self.description
            self.save()
            return []

        try:
            prod = Product.objects.get(db_name=self.product)
            system = prod.translation_system
        except Product.DoesNotExist:
            # If the product doesn't exist, then I don't know what's
            # going on, but we shouldn't create any translation jobs
            return []

        if not system:
            # If this product isn't set up for translation, don't
            # translate it.
            return []

        try:
            # See if this text has been translated already--if so, use
            # the most recent translation.
            existing_obj = (
                Response.objects.filter(description=self.description)
                .exclude(translated_description__isnull=True)
                .exclude(translated_description=u"")
                .latest("id")
            )
            self.translated_description = existing_obj.translated_description
            self.save()
            return []
        except Response.DoesNotExist:
            pass

        return [
            # key, system, src language, src field, dst language, dst field
            (compose_key(self), system, self.locale, "description", u"en-US", "translated_description")
        ]
Esempio n. 2
0
    def generate_translation_jobs(self, system=None):
        """Returns a list of tuples, one for each translation job

        If the locale of this response is English, then we just copy over
        the description and we're done.

        If the product of this response isn't set up for
        auto-translation and no translation system was specified in
        the arguments, then we're done.

        If we already have a response with this text that's
        translated, we copy the most recent translation over.

        Otherwise we generate a list of jobs to be done.

        """
        # If the text is in English, we copy it over and we're
        # done. We do this regardless of whether auto-translation is
        # enabled or not for this product.
        if self.locale == 'en-US':
            self.translated_description = self.description
            self.save()
            return []

        if not system:
            try:
                prod = Product.objects.get(db_name=self.product)
                system = prod.translation_system
            except Product.DoesNotExist:
                # If the product doesn't exist, then I don't know
                # what's going on. Regardless, we shouldn't create any
                # translation jobs.
                return []

        if not system:
            # If this product isn't set up for translation, don't
            # translate it.
            return []

        try:
            # See if this text has been translated already--if so, use
            # the most recent translation.
            existing_translation = (Response.objects.filter(
                description=self.description).filter(
                    locale=self.locale).exclude(
                        translated_description__isnull=True).exclude(
                            translated_description=u'').values_list(
                                'translated_description').latest('id'))
            self.translated_description = existing_translation[0]
            self.save()
            statsd.incr('feedback.translation.used_existing')
            return []
        except Response.DoesNotExist:
            pass

        return [
            # key, system, src language, src field, dst language, dst field
            (compose_key(self), system, self.locale, 'description', u'en-US',
             'translated_description')
        ]
Esempio n. 3
0
    def generate_translation_jobs(self, system=None):
        """Returns a list of tuples, one for each translation job

        If the locale of this response is English, then we just copy over
        the description and we're done.

        If the product of this response isn't set up for
        auto-translation and no translation system was specified in
        the arguments, then we're done.

        If we already have a response with this text that's
        translated, we copy the most recent translation over.

        Otherwise we generate a list of jobs to be done.

        """
        # If the text is in English, we copy it over and we're
        # done. We do this regardless of whether auto-translation is
        # enabled or not for this product.
        if self.locale == 'en-US':
            self.translated_description = self.description
            self.save()
            return []

        if not system:
            try:
                prod = Product.objects.get(db_name=self.product)
                system = prod.translation_system
            except Product.DoesNotExist:
                # If the product doesn't exist, then I don't know
                # what's going on. Regardless, we shouldn't create any
                # translation jobs.
                return []

        if not system:
            # If this product isn't set up for translation, don't
            # translate it.
            return []

        try:
            # See if this text has been translated already--if so, use
            # the most recent translation.
            existing_translation = (
                Response.objects
                .filter(description=self.description)
                .filter(locale=self.locale)
                .exclude(translated_description__isnull=True)
                .exclude(translated_description=u'')
                .values_list('translated_description')
                .latest('id')
            )
            self.translated_description = existing_translation[0]
            self.save()
            statsd.incr('feedback.translation.used_existing')
            return []
        except Response.DoesNotExist:
            pass

        return [
            # key, system, src language, src field, dst language, dst field
            (compose_key(self), system, self.locale, 'description',
             u'en-US', 'translated_description')
        ]