当前位置: 首页>>代码示例>>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;未经允许,请勿转载。