• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python formats.AutoFormat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中weblate.trans.formats.AutoFormat的典型用法代码示例。如果您正苦于以下问题:Python AutoFormat类的具体用法?Python AutoFormat怎么用?Python AutoFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了AutoFormat类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: merge_upload

    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,代码行数:33,代码来源:translation.py


示例2: merge_upload

    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,代码行数:53,代码来源:translation.py


示例3: test_content

    def test_content(self):
        """Test content based guess from ttkit"""
        with open(TEST_PO, 'rb') as handle:
            data = handle.read()

        handle = BytesIO(data)
        store = AutoFormat.parse(handle)
        self.assertIsInstance(store, AutoFormat)
        self.assertIsInstance(store.store, pofile)
开发者ID:ccfwwm,项目名称:weblate,代码行数:9,代码来源:test_formats.py


示例4: upload

    def upload(self, request, project, language, fileobj, method):
        '''
        Handles dictionary upload.
        '''
        from weblate.trans.models.changes import Change
        store = AutoFormat.parse(fileobj)

        ret = 0

        # process all units
        for dummy, unit in store.iterate_merge(False):
            source = unit.get_source()
            target = unit.get_target()

            # Ignore too long words
            if len(source) > 190 or len(target) > 190:
                continue

            # Get object
            word, created = self.get_or_create(
                project=project,
                language=language,
                source=source,
                defaults={
                    'target': target,
                },
            )

            # Already existing entry found
            if not created:
                # Same as current -> ignore
                if target == word.target:
                    continue
                if method == 'add':
                    # Add word
                    word = self.create(
                        request,
                        action=Change.ACTION_DICTIONARY_UPLOAD,
                        project=project,
                        language=language,
                        source=source,
                        target=target
                    )
                elif method == 'overwrite':
                    # Update word
                    word.target = target
                    word.save()

            ret += 1

        return ret
开发者ID:Acidburn0zzz,项目名称:weblate,代码行数:51,代码来源:dictionary.py


示例5: upload

    def upload(self, request, project, language, fileobj, method):
        """
        Handles dictionary update.
        """
        # Load file using translate-toolkit
        store = AutoFormat.load(fileobj)

        ret, skipped = self.import_store(request, project, language, store, method)

        if ret == 0 and skipped > 0 and isinstance(store, csvfile):
            # Retry with different CSV scheme
            fileobj.seek(0)
            store = csvfile(fileobj, ("source", "target"))
            ret, skipped = self.import_store(request, project, language, store, method)

        return ret
开发者ID:barmi,项目名称:weblate,代码行数:16,代码来源:dictionary.py


示例6: upload

    def upload(self, request, project, language, fileobj, method):
        '''
        Handles dictionary update.
        '''
        filecopy = fileobj.read()
        fileobj.close()
        # Load file using translate-toolkit
        store = AutoFormat.load(StringIOMode(fileobj.name, filecopy))

        ret, skipped = self.import_store(
            request, project, language, store, method
        )

        if ret == 0 and skipped > 0 and isinstance(store, csvfile):
            # Retry with different CSV scheme
            store = csvfile(
                StringIOMode(fileobj.name, filecopy),
                ('source', 'target')
            )
            ret, skipped = self.import_store(
                request, project, language, store, method
            )

        return ret
开发者ID:beck,项目名称:weblate,代码行数:24,代码来源:dictionary.py


示例7: single_test

 def single_test(self, filename, fileclass):
     with open(filename, 'rb') as handle:
         store = AutoFormat.parse(handle)
         self.assertIsInstance(store, fileclass)
     self.assertEqual(fileclass, detect_filename(filename))
开发者ID:ccfwwm,项目名称:weblate,代码行数:5,代码来源:test_formats.py


示例8: single_test

 def single_test(self, filename, fileclass):
     with open(filename, 'r') as handle:
         store = AutoFormat.parse(handle)
         self.assertIsInstance(store, fileclass)
开发者ID:franco999,项目名称:weblate,代码行数:4,代码来源:test_formats.py


示例9: merge_upload

    def merge_upload(self, request, fileobj, overwrite, author=None,
                     merge_header=True, method='', fuzzy='',
                     merge_comments=False):
        """Top level handler for file uploads."""
        filecopy = fileobj.read()
        fileobj.close()

        # Strip possible UTF-8 BOM
        if filecopy[:3] == codecs.BOM_UTF8:
            filecopy = filecopy[3:]

        # Load backend file
        try:
            # First try using own loader
            store = self.store.parse(
                StringIOMode(fileobj.name, filecopy),
                self.subproject.template_store
            )
        except Exception:
            # Fallback to automatic detection
            store = AutoFormat.parse(
                StringIOMode(fileobj.name, filecopy),
            )

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

        # Check valid plural forms
        if hasattr(store.store, 'parseheader'):
            header = store.store.parseheader()
            if 'Plural-Forms' in header and \
                    self.language.get_plural_form() != header['Plural-Forms']:
                raise Exception('Plural forms do not match the language.')

        # 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
                ret = self.merge_translations(
                    request,
                    store,
                    overwrite,
                    (method == 'fuzzy'),
                    fuzzy
                )
            else:
                # Merge on file level
                for translation in translations:
                    ret |= translation.merge_store(
                        request,
                        author,
                        store,
                        overwrite,
                        merge_header,
                        (method == 'fuzzy'),
                        fuzzy,
                        merge_comments=merge_comments,
                    )
        else:
            # Add as sugestions
            ret = self.merge_suggestions(request, store, fuzzy)

        return ret, store.count_units()
开发者ID:acamara7es,项目名称:weblate,代码行数:75,代码来源:translation.py



注:本文中的weblate.trans.formats.AutoFormat类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python forms.SearchForm类代码示例发布时间:2022-05-26
下一篇:
Python data.data_dir函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap