Delete a translation from a model.

        :param language_code: The language to remove.
        :param related_name: If given, only the model matching that related_name is removed.
12233
def delete_translation(self, language_code, related_name=None):
        
        if language_code is None:
            raise ValueError(get_null_language_error())

        if related_name is None:
            metas = self._parler_meta
        else:
            metas = [self._parler_meta[related_name]]

        num_deleted = 0
        for meta in metas:
            try:
                translation = self._get_translated_model(language_code, meta=meta)
            except meta.model.DoesNotExist:
                continue

            # By using the regular model delete, the cache is properly cleared
            # (via _delete_cached_translation) and signals are emitted.
            translation.delete()
            num_deleted += 1

            # Clear other local caches
            try:
                del self._translations_cache[meta.model][language_code]
            except KeyError:
                pass
            try:
                del self._prefetched_objects_cache[meta.rel_name]
            except (AttributeError, KeyError):
                pass

        if not num_deleted:
            raise ValueError("Translation does not exist: {0}".format(language_code))

        return num_deleted
160690
def for_language(self, language_code):
        
        clone = self._clone()
        clone._default_language = language_code
        return clone
250137
public function translationRemoved(array $locationIds, $languageCode)
    {
        $languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id;

        $actions = [];
        foreach ($locationIds as $locationId) {
            $actions[] = 'eznode:' . $locationId;
        }
        $this->gateway->bulkRemoveTranslation($languageId, $actions);
    }
945247
public function deleteTranslationFromVersion($contentId, $versionNo, $languageCode)
    {
        try {
            return $this->innerGateway->deleteTranslationFromVersion($contentId, $versionNo, $languageCode);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
659360
def delete_model_translation(self, request, translation):
        
        master = translation.master
        for qs in self.get_translation_objects(request, translation.language_code, obj=master, inlines=self.delete_inline_translations):
            if isinstance(qs, (tuple, list)):
                # The objects are deleted one by one.
                # This triggers the post_delete signals and such.
                for obj in qs:
                    obj.delete()
            else:
                # Also delete translations of inlines which the user has access to.
                # This doesn't trigger signals, just like the regular
                qs.delete()
1029360
def delete(self):
        
        del_query = self._clone()

        # The delete is actually 2 queries - one to find related objects,
        # and one to delete. Make sure that the discovery of related
        # objects is performed on the same database as the deletion.
        del_query._clear_ordering()
        get_es_connection(self.es_url, self.es_kwargs).delete_by_query(self.index, self.type, self._build_query())
        # Clear the result cache, in case this QuerySet gets reused.
        self._result_cache = None
879333
def get_cached_translated_field(instance, field_name, language_code=None, use_fallback=False):
    
    if language_code is None:
        language_code = instance.get_current_language()

    # In django-parler 1.1 the order of the arguments was fixed, It used to be language_code, field_name
    # This serves as detection against backwards incompatibility issues.
    if len(field_name) <= 5 and len(language_code) > 5:
        raise RuntimeError("Unexpected language code, did you swap field_name, language_code?")

    translated_model = instance._parler_meta.get_model_by_field(field_name)
    values = _get_cached_values(instance, translated_model, language_code, use_fallback)
    if not values:
        return None

    # Allow older cached versions where the field didn't exist yet.
    return values.get(field_name, None)
1082127
def remove_core_element(self, model):
        
        gv_name = model
        if self.global_variable_is_editable(gv_name, "Deletion"):
            try:
                self.model.global_variable_manager.delete_variable(gv_name)
            except AttributeError as e:
                logger.warning("The respective global variable '{1}' couldn't be removed. -> {0}"
                            "".format(e, model))
640747
public function removeExistingTranslation($languageCode)
    {
        return $this->translations()
            ->where('file_id', $this->id)
            ->where('language_code', $languageCode)
            ->delete();
    }
786292
def get_language_title(language_code):
    
    from parler import appsettings
    # Avoid weird lookup errors.
    if not language_code:
        raise ValueError("Missing language_code in get_language_title()")

    if appsettings.PARLER_SHOW_EXCLUDED_LANGUAGE_TABS:
        # this allows to edit languages that are not enabled in current project but are already
        # in database
        languages = ALL_LANGUAGES_DICT
    else:
        languages = LANGUAGES_DICT

    try:
        return _(languages[language_code])
    except KeyError:
        language_code = language_code.split('-')[0]  # e.g. if fr-ca is not supported fallback to fr
        language_title = languages.get(language_code, None)
        if language_title is not None:
            return _(language_title)
        else:
            return language_code
1051401
def _cache_translation_needs_fallback(instance, language_code, related_name, timeout=cache.default_timeout):
    
    if not appsettings.PARLER_ENABLE_CACHING or not instance.pk or instance._state.adding:
        return

    tr_model = instance._parler_meta.get_model_by_related_name(related_name)
    key = get_translation_cache_key(tr_model, instance.pk, language_code)
    cache.set(key, {'__FALLBACK__': True}, timeout=timeout)
1203949
def delete_translations(self, language=None):
        
        from .models import Translation

        return Translation.objects.delete_translations(obj=self, language=language)
552090
public function deleteTranslationFromContent($contentId, $languageCode)
    {
        try {
            return $this->innerGateway->deleteTranslationFromContent($contentId, $languageCode);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1275765
def remove_item_languages(self, item, languages):
        
        # get the langs we have to add to the TransModelLanguage
        qs = TransLanguage.objects.filter(code__in=languages)
        remove_langs = [lang for lang in qs]
        if not remove_langs:
            return

        ct_item = ContentType.objects.get_for_model(item)
        item_lan, created = TransItemLanguage.objects.get_or_create(content_type_id=ct_item.id, object_id=item.id)
        for lang in remove_langs:
            item_lan.languages.remove(lang)
        if item_lan.languages.count() == 0:
            item_lan.delete()
446339
def remove_filter(func, language=None):
    
    if not (language in _filters and func in _filters[language]):
        return False
    _filters[language].remove(func)
    return True
1120139
def get_all_languages(self, sort='code'):
    
    langs = list(self.culturecode_set.all().as_languages())
    langs.extend(self.language_set.exclude(iso_639_1__in=[x.iso_639_1 for x in langs]))
    if sort in ['name_en', 'name_native']:
        langs.sort(key=lambda x: getattr(x, sort))
    elif sort == 'code':
        codes = self.languages.split(',')

        def code_sort(x):
            return codes.index(x.sort_code)

        langs.sort(key=code_sort)
    else:
        raise ValueError(
            'Invalid code option %s.  Valid options are: code, name_en, name_native' % sort)
    return langs
877596
def on_delete_model_translation(instance, **kwargs):
    
    translation = instance

    parent_object = translation.master
    parent_object.set_current_language(translation.language_code)

    # Also delete any associated plugins
    # Placeholders are shared between languages, so these are not affected.
    for item in ContentItem.objects.parent(parent_object, limit_parent_language=True):
        item.delete()