def set_translation(self, lang, field, text):
        """
        Store a translation string in the specified field for a Translatable
        istance

        @type lang: string
        @param lang: a string with the name of the language

        @type field: string
        @param field: a string with the name that we try to get

        @type text: string
        @param text: a string to be stored as translation of the field
        """
        # Do not allow user to set a translations in the default language
        auto_slug_obj = None

        if lang == self._get_default_language():
            raise CanNotTranslate(
                _('You are not supposed to translate the default language. '
                  'Use the model fields for translations in default language')
            )

        # Get translation, if it does not exits create one
        trans_obj = self.get_translation_obj(lang, field, create=True)
        trans_obj.translation = text
        trans_obj.save()

        # check if the field has an autoslugfield and create the translation
        if INSTALLED_AUTOSLUG:
            if self.translatable_slug:
                try:
                    auto_slug_obj = self._meta.get_field(self.translatable_slug).populate_from
                except AttributeError:
                    pass

        if auto_slug_obj:
            tobj = self.get_translation_obj(lang, self.translatable_slug, create=True)
            translation = self.get_translation(lang, auto_slug_obj)
            tobj.translation = slugify(translation)
            tobj.save()

        # Update cache for this specif translations
        key = self._get_translation_cache_key(lang, field)
        cache.set(key, text)
        # remove cache for translations dict
        cache.delete(self._get_translations_cache_key(lang))
        return trans_obj
def set_translation ( self , lang , field , text ) : auto_slug_obj = None if lang == self . _get_default_language ( ) : raise CanNotTranslate ( _ ( 'You are not supposed to translate the default language. ' 'Use the model fields for translations in default language' ) ) trans_obj = self . get_translation_obj ( lang , field , create = True ) trans_obj . translation = text trans_obj . save ( ) if INSTALLED_AUTOSLUG : if self . translatable_slug : try : auto_slug_obj = self . _meta . get_field ( self . translatable_slug ) . populate_from except AttributeError : pass if auto_slug_obj : tobj = self . get_translation_obj ( lang , self . translatable_slug , create = True ) translation = self . get_translation ( lang , auto_slug_obj ) tobj . translation = slugify ( translation ) tobj . save ( ) key = self . _get_translation_cache_key ( lang , field ) cache . set ( key , text ) cache . delete ( self . _get_translations_cache_key ( lang ) ) return trans_obj
Store a translation string in the specified field for a Translatable
        istance

        @type lang: string
        @param lang: a string with the name of the language

        @type field: string
        @param field: a string with the name that we try to get

        @type text: string
        @param text: a string to be stored as translation of the field