當前位置: 首頁>>代碼示例>>Python>>正文


Python AutoFormat.count_units方法代碼示例

本文整理匯總了Python中weblate.trans.formats.AutoFormat.count_units方法的典型用法代碼示例。如果您正苦於以下問題:Python AutoFormat.count_units方法的具體用法?Python AutoFormat.count_units怎麽用?Python AutoFormat.count_units使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在weblate.trans.formats.AutoFormat的用法示例。


在下文中一共展示了AutoFormat.count_units方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: merge_upload

# 需要導入模塊: from weblate.trans.formats import AutoFormat [as 別名]
# 或者: from weblate.trans.formats.AutoFormat import count_units [as 別名]
    def merge_upload(self, request, fileobj, overwrite, author=None, merge_header=True, method=""):
        """
        Top level handler for file uploads.
        """
        # Load backend file
        try:
            # First try using own loader
            store = self.subproject.file_format_cls(fileobj, self.subproject.template_store)
        except:
            # Fallback to automatic detection
            fileobj.seek(0)
            store = AutoFormat(fileobj)

        # Optionally set authorship
        if author is None:
            author = self.get_author_name(request.user)

        # List translations we should process
        translations = Translation.objects.filter(language=self.language, subproject__project=self.subproject.project)
        # Filter out those who don't want automatic update, but keep ourselves
        translations = translations.filter(Q(pk=self.pk) | Q(subproject__allow_translation_propagation=True))

        ret = False

        if method in ("", "fuzzy"):
            # Do actual merge
            for translation in translations:
                ret |= translation.merge_store(request, author, store, overwrite, merge_header, (method == "fuzzy"))
        else:
            # Add as sugestions
            ret = self.merge_suggestions(request, store)

        return ret, store.count_units()
開發者ID:ujdhesa,項目名稱:weblate,代碼行數:35,代碼來源:translation.py

示例2: merge_upload

# 需要導入模塊: from weblate.trans.formats import AutoFormat [as 別名]
# 或者: from weblate.trans.formats.AutoFormat import count_units [as 別名]
    def merge_upload(self,
                     request,
                     fileobj,
                     overwrite,
                     author=None,
                     merge_header=True,
                     method=''):
        '''
        Top level handler for file uploads.
        '''
        filecopy = fileobj.read()
        fileobj.close()
        # Load backend file
        try:
            # First try using own loader
            store = self.subproject.file_format_cls(
                StringIOMode(fileobj.name, filecopy),
                self.subproject.template_store)
        except Exception:
            # Fallback to automatic detection
            store = AutoFormat(StringIOMode(fileobj.name, filecopy), )

        # Optionally set authorship
        if author is None:
            author = self.get_author_name(request.user)

        # List translations we should process
        # Filter out those who don't want automatic update, but keep ourselves
        translations = Translation.objects.filter(
            language=self.language,
            subproject__project=self.subproject.project).filter(
                Q(pk=self.pk)
                | Q(subproject__allow_translation_propagation=True))

        ret = False

        if method in ('', 'fuzzy'):
            # Do actual merge
            if self.subproject.has_template():
                # Merge on units level
                self.merge_translations(request, author, store, overwrite,
                                        (method == 'fuzzy'))
            else:
                # Merge on file level
                for translation in translations:
                    ret |= translation.merge_store(request, author, store,
                                                   overwrite, merge_header,
                                                   (method == 'fuzzy'))
        else:
            # Add as sugestions
            ret = self.merge_suggestions(request, store)

        return ret, store.count_units()
開發者ID:beck,項目名稱:weblate,代碼行數:55,代碼來源:translation.py


注:本文中的weblate.trans.formats.AutoFormat.count_units方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。