本文整理汇总了Python中pywikibot.i18n.twntranslate函数的典型用法代码示例。如果您正苦于以下问题:Python twntranslate函数的具体用法?Python twntranslate怎么用?Python twntranslate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了twntranslate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, generator, templates, **kwargs):
"""
Constructor.
@param generator: the pages to work on
@type generator: iterable
@param templates: a dictionary which maps old template names to
their replacements. If remove or subst is True, it maps the
names of the templates that should be removed/resolved to None.
@type templates: dict
"""
self.availableOptions.update({"subst": False, "remove": False, "summary": None, "addedCat": None})
super(TemplateRobot, self).__init__(**kwargs)
self.generator = generator
self.templates = templates
site = pywikibot.Site()
if self.getOption("addedCat"):
self.options["addedCat"] = pywikibot.Category(site, self.getOption("addedCat"))
comma = site.mediawiki_message("comma-separator")
# get edit summary message if it's empty
if not self.getOption("summary"):
params = {"list": comma.join(self.templates.keys()), "num": len(self.templates)}
if self.getOption("remove"):
self.options["summary"] = i18n.twntranslate(site, "template-removing", params)
elif self.getOption("subst"):
self.options["summary"] = i18n.twntranslate(site, "template-substituting", params)
else:
self.options["summary"] = i18n.twntranslate(site, "template-changing", params)
开发者ID:Nivgov,项目名称:AvodatGemer,代码行数:31,代码来源:template.py
示例2: run
def run(self):
if not self.Page.botMayEdit(Site.username):
return
whys = self.analyzePage()
if self.archivedThreads < int(self.get("minthreadstoarchive", 2)):
# We might not want to archive a measly few threads
# (lowers edit frequency)
pywikibot.output(u"There are only %d Threads. Skipping" % self.archivedThreads)
return
if whys:
pywikibot.output(u"Archiving %d thread(s)." % self.archivedThreads)
# Save the archives first (so that bugs don't cause a loss of data)
for a in sorted(self.archives.keys()):
self.commentParams["count"] = self.archives[a].archivedThreads
comment = i18n.twntranslate(language, "archivebot-archive-summary", self.commentParams)
self.archives[a].update(comment)
# Save the page itself
rx = re.compile("{{" + self.tpl + "\n.*?\n}}", re.DOTALL)
self.Page.header = rx.sub(self.attr2text(), self.Page.header)
self.commentParams["count"] = self.archivedThreads
self.commentParams["archives"] = ", ".join(["[[" + a.title() + "]]" for a in self.archives.values()])
if not self.commentParams["archives"]:
self.commentParams["archives"] = "/dev/null"
self.commentParams["why"] = ", ".join(whys)
comment = i18n.twntranslate(language, "archivebot-page-summary", self.commentParams)
self.Page.update(comment)
开发者ID:h4ck3rm1k3,项目名称:pywikipediabot,代码行数:27,代码来源:archivebot.py
示例3: run
def run(self):
if not self.Page.Page.botMayEdit(Site.username):
return
whys = self.analyzePage()
if self.archivedThreads < int(self.get('minthreadstoarchive',2)):
# We might not want to archive a measly few threads
# (lowers edit frequency)
return
if whys:
#Save the archives first (so that bugs don't cause a loss of data)
for a in sorted(self.archives.keys()):
self.commentParams['count'] = self.archives[a].archivedThreads
comment = i18n.twntranslate(language,
'archivebot-archive-summary',
self.commentParams)
self.archives[a].update(comment)
#Save the page itself
rx = re.compile('{{'+self.tpl+'\n.*?\n}}',re.DOTALL)
self.Page.header = rx.sub(self.attr2text(),self.Page.header)
self.commentParams['count'] = self.archivedThreads
self.commentParams['archives'] \
= ', '.join(['[['+a.title+']]' for a in self.archives.values()])
if not self.commentParams['archives']:
self.commentParams['archives'] = '/dev/null'
self.commentParams['why'] = ', '.join(whys)
comment = i18n.twntranslate(language,
'archivebot-page-summary',
self.commentParams)
self.Page.update(comment)
开发者ID:Protonk,项目名称:pywikipedia2,代码行数:30,代码来源:archivebot.py
示例4: __init__
def __init__(self, generator, templates, subst=False, remove=False, editSummary="", acceptAll=False, addedCat=None):
"""
Arguments:
* generator - A page generator.
* replacements - A dictionary which maps old template names to
their replacements. If remove or subst is True,
it maps the names of the templates that should be
removed/resolved to None.
* remove - True if the template should be removed.
* subst - True if the template should be resolved.
"""
self.generator = generator
self.templates = templates
self.subst = subst
self.remove = remove
self.editSummary = editSummary
self.acceptAll = acceptAll
self.addedCat = addedCat
site = pywikibot.getSite()
if self.addedCat:
self.addedCat = catlib.Category(site, u"%s:%s" % (site.namespace(14), self.addedCat))
comma = site.mediawiki_message("comma-separator")
# get edit summary message if it's empty
if not self.editSummary:
Param = {"list": comma.join(self.templates.keys()), "num": len(self.templates)}
if self.remove:
self.editSummary = i18n.twntranslate(site, "template-removing", Param)
elif self.subst:
self.editSummary = i18n.twntranslate(site, "template-substituting", Param)
else:
self.editSummary = i18n.twntranslate(site, "template-changing", Param)
开发者ID:hroest,项目名称:pywikibot-compat,代码行数:34,代码来源:template.py
示例5: testMultipleNonNumbers
def testMultipleNonNumbers(self):
"""Test error handling for multiple non-numbers."""
with self.assertRaisesRegex(ValueError, "invalid literal for int\(\) with base 10: 'drei'"):
i18n.twntranslate('de', 'test-multiple-plurals', ["drei", "1", 1])
with self.assertRaisesRegex(ValueError, "invalid literal for int\(\) with base 10: 'elf'"):
i18n.twntranslate('de', 'test-multiple-plurals',
{'action': u'Ändere', 'line': "elf", 'page': 2})
开发者ID:Tillsa,项目名称:pywikibot_test_wikidata,代码行数:7,代码来源:i18n_tests.py
示例6: run
def run(self):
if not self.page.botMayEdit():
return
whys = self.analyze_page()
mintoarchive = int(self.get_attr('minthreadstoarchive', 2))
if self.archived_threads < mintoarchive:
# We might not want to archive a measly few threads
# (lowers edit frequency)
pywikibot.output(u'Only %d (< %d) threads are old enough. Skipping'
% (self.archived_threads, mintoarchive))
return
if whys:
pywikibot.output(u'Archiving %d thread(s).' % self.archived_threads)
# Save the archives first (so that bugs don't cause a loss of data)
for a in sorted(self.archives.keys()):
self.comment_params['count'] = self.archives[a].archived_threads
comment = i18n.twntranslate(self.site.code,
'archivebot-archive-summary',
self.comment_params)
self.archives[a].update(comment)
# Save the page itself
rx = re.compile('{{' + self.tpl + '\n.*?\n}}', re.DOTALL)
self.page.header = rx.sub(self.attr2text(), self.page.header)
self.comment_params['count'] = self.archived_threads
self.comment_params['archives'] \
= ', '.join(['[[' + a.title() + ']]'
for a in self.archives.values()])
if not self.comment_params['archives']:
self.comment_params['archives'] = '/dev/null'
self.comment_params['why'] = ', '.join(whys)
comment = i18n.twntranslate(self.site.code,
'archivebot-page-summary',
self.comment_params)
self.page.update(comment)
开发者ID:anrao91,项目名称:pywikibot-core,代码行数:35,代码来源:archivebot.py
示例7: testMultipleWrongParameterLength
def testMultipleWrongParameterLength(self):
"""Test wrong parameter length."""
err_msg = 'Length of parameter does not match PLURAL occurrences'
with self.assertRaisesRegex(ValueError, err_msg):
i18n.twntranslate('de', 'test-multiple-plurals', (1, 2))
with self.assertRaisesRegex(ValueError, err_msg):
i18n.twntranslate('de', 'test-multiple-plurals', ["321"])
开发者ID:Tillsa,项目名称:pywikibot_test_wikidata,代码行数:8,代码来源:i18n_tests.py
示例8: testMultipleNonNumbers
def testMultipleNonNumbers(self):
"""Test error handling for multiple non-numbers."""
with self.assertRaisesRegex(ValueError, "invalid literal for int\(\) with base 10: 'drei'"):
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', ["drei", "1", 1])
% {'action': u'Ändere', 'line': u'drei'},
u'Bot: Ändere drei Zeilen von einer Seite.')
with self.assertRaisesRegex(ValueError, "invalid literal for int\(\) with base 10: 'elf'"):
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals',
{'action': u'Ändere', 'line': "elf", 'page': 2}),
u'Bot: Ändere elf Zeilen von mehreren Seiten.')
开发者ID:edgarskos,项目名称:pywikibot_scripts,代码行数:12,代码来源:i18n_tests.py
示例9: testMultipleWrongParameterLength
def testMultipleWrongParameterLength(self):
"""Test wrong parameter length."""
with self.assertRaisesRegex(ValueError, "Length of parameter does not match PLURAL occurrences"):
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', (1, 2))
% {'action': u'Ändere', 'line': u'drei'},
u'Bot: Ändere drei Zeilen von mehreren Seiten.')
with self.assertRaisesRegex(ValueError, "Length of parameter does not match PLURAL occurrences"):
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', ["321"])
% {'action': u'Ändere', 'line': u'dreihunderteinundzwanzig'},
u'Bot: Ändere dreihunderteinundzwanzig Zeilen von mehreren Seiten.')
开发者ID:edgarskos,项目名称:pywikibot_scripts,代码行数:13,代码来源:i18n_tests.py
示例10: testNumber
def testNumber(self):
"""Use a number."""
self.assertEqual(
i18n.twntranslate('de', 'test-plural', 0) % {'num': 0},
u'Bot: Ändere 0 Seiten.')
self.assertEqual(
i18n.twntranslate('de', 'test-plural', 1) % {'num': 1},
u'Bot: Ändere 1 Seite.')
self.assertEqual(
i18n.twntranslate('de', 'test-plural', 2) % {'num': 2},
u'Bot: Ändere 2 Seiten.')
self.assertEqual(
i18n.twntranslate('de', 'test-plural', 3) % {'num': 3},
u'Bot: Ändere 3 Seiten.')
self.assertEqual(
i18n.twntranslate('en', 'test-plural', 0) % {'num': 'no'},
u'Bot: Changing no pages.')
self.assertEqual(
i18n.twntranslate('en', 'test-plural', 1) % {'num': 'one'},
u'Bot: Changing one page.')
self.assertEqual(
i18n.twntranslate('en', 'test-plural', 2) % {'num': 'two'},
u'Bot: Changing two pages.')
self.assertEqual(
i18n.twntranslate('en', 'test-plural', 3) % {'num': 'three'},
u'Bot: Changing three pages.')
开发者ID:edgarskos,项目名称:pywikibot_scripts,代码行数:26,代码来源:i18n_tests.py
示例11: run
def run(self):
listOfArticles = self.cat.articlesList(recurse=self.recurse)
if self.subCats:
listOfArticles += self.cat.subcategoriesList()
if not self.editSummary:
self.editSummary = i18n.twntranslate(self.site,
'category-listifying',
{'fromcat': self.cat.title(),
'num': len(listOfArticles)})
listString = ""
for article in listOfArticles:
if (not article.isImage() or
self.showImages) and not article.isCategory():
if self.talkPages and not article.isTalkPage():
listString += "*[[%s]] -- [[%s|talk]]\n" \
% (article.title(),
article.toggleTalkPage().title())
else:
listString += "*[[%s]]\n" % article.title()
else:
if self.talkPages and not article.isTalkPage():
listString += "*[[:%s]] -- [[%s|talk]]\n" \
% (article.title(),
article.toggleTalkPage().title())
else:
listString += "*[[:%s]]\n" % article.title()
if self.list.exists() and not self.overwrite:
pywikibot.output(u'Page %s already exists, aborting.'
% self.list.title())
else:
self.list.put(listString, comment=self.editSummary)
开发者ID:Rodehi,项目名称:GFROS,代码行数:32,代码来源:category.py
示例12: __init__
def __init__(self, djvu, index, pages=None, **kwargs):
"""
Constructor.
@param djvu: djvu from where to fetch the text layer
@type djvu: DjVuFile object
@param index: index page in the Index: namespace
@type index: Page object
@param pages: page interval to upload (start, end)
@type pages: tuple
"""
self.availableOptions.update({
'force': False,
'summary': None
})
super(DjVuTextBot, self).__init__(site=index.site, **kwargs)
self._djvu = djvu
self._index = index
self._prefix = self._index.title(withNamespace=False)
if not pages:
self._pages = (1, self._djvu.number_of_images())
else:
self._pages = pages
self.generator = self.gen()
# Get edit summary message if it's empty.
if not self.getOption('summary'):
self.options['summary'] = i18n.twntranslate(
self._index.site, 'djvutext-creating')
开发者ID:xZise,项目名称:pywikibot-core,代码行数:31,代码来源:djvutext.py
示例13: run
def run(self):
"""Start bot."""
setOfArticles = set(self.cat.articles(recurse=self.recurse))
if self.subCats:
setOfArticles = setOfArticles.union(set(self.cat.subcategories()))
if not self.editSummary:
self.editSummary = i18n.twntranslate(
self.site, "category-listifying", {"fromcat": self.cat.title(), "num": len(setOfArticles)}
)
listString = ""
for article in setOfArticles:
if (not article.isImage() or self.showImages) and not article.isCategory():
if self.talkPages and not article.isTalkPage():
listString += "*[[%s]] -- [[%s|talk]]\n" % (article.title(), article.toggleTalkPage().title())
else:
listString += "*[[%s]]\n" % article.title()
else:
if self.talkPages and not article.isTalkPage():
listString += "*[[:%s]] -- [[%s|talk]]\n" % (article.title(), article.toggleTalkPage().title())
else:
listString += "*[[:%s]]\n" % article.title()
if self.list.exists() and not self.overwrite:
pywikibot.output("Page %s already exists, aborting." % self.list.title())
else:
self.list.put(listString, summary=self.editSummary)
开发者ID:emijrp,项目名称:pywikibot-core,代码行数:26,代码来源:category.py
示例14: run
def run(self):
listOfArticles = self.cat.articlesList(recurse = self.recurse)
if self.subCats:
listOfArticles += self.cat.subcategoriesList()
if not self.editSummary:
self.editSummary = i18n.twntranslate(self.site,
'category-listifying',
{'fromcat': self.cat.title(),
'num': len(listOfArticles)})
listString = ""
for article in listOfArticles:
if (not article.isImage() or self.showImages) and not article.isCategory():
if self.talkPages and not article.isTalkPage():
listString = listString + article.title() +'\n'
else:
listString = listString + article.title()+'\n'
else:
if self.talkPages and not article.isTalkPage():
listString = listString + article.title()+'\n'
else:
listString = listString + article.title()+'\n'
if self.list.exists() and not self.overwrite:
return listString
else:
return listString
开发者ID:notconfusing,项目名称:statsFromCategory,代码行数:26,代码来源:category_customized.py
示例15: testAllParametersExist
def testAllParametersExist(self):
with self.assertRaisesRegex(KeyError, repr(u'line')):
# all parameters must be inside twntranslate
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals',
{'line': 1, 'page': 1})
% {'action': u'Ändere'},
u'Bot: Ändere 1 Zeile von einer Seite.')
开发者ID:edgarskos,项目名称:pywikibot_scripts,代码行数:8,代码来源:i18n_tests.py
示例16: test_fallback_lang
def test_fallback_lang(self):
"""
Test that twntranslate uses the translation's language.
twntranslate calls _twtranslate which might return the translation for
a different language and then the plural rules from that language need
to be applied.
"""
# co has fr as altlang but has no plural rules defined (otherwise this
# test might not catch problems) so it's using the plural variant for 0
# although French uses the plural variant for numbers > 1 (so not 0)
assert('co' not in plural.plural_rules)
assert(plural.plural_rules['fr']['plural'](0) is False)
self.assertEqual(
i18n.twntranslate('co', 'test-plural', {'num': 0, 'descr': 'seulement'}),
u'Robot: Changer seulement une page.')
self.assertEqual(
i18n.twntranslate('co', 'test-plural', {'num': 1, 'descr': 'seulement'}),
u'Robot: Changer seulement une page.')
开发者ID:edgarskos,项目名称:pywikibot_scripts,代码行数:19,代码来源:i18n_tests.py
示例17: testMultiple
def testMultiple(self):
"""Test using multiple plural entries."""
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', 1)
% {'action': u'Ändere', 'line': u'eine'},
u'Bot: Ändere eine Zeile von einer Seite.')
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', 2)
% {'action': u'Ändere', 'line': u'zwei'},
u'Bot: Ändere zwei Zeilen von mehreren Seiten.')
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', 3)
% {'action': u'Ändere', 'line': u'drei'},
u'Bot: Ändere drei Zeilen von mehreren Seiten.')
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', (1, 2, 2))
% {'action': u'Ändere', 'line': u'eine'},
u'Bot: Ändere eine Zeile von mehreren Seiten.')
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', [3, 1, 1])
% {'action': u'Ändere', 'line': u'drei'},
u'Bot: Ändere drei Zeilen von einer Seite.')
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', ["3", 1, 1])
% {'action': u'Ändere', 'line': u'drei'},
u'Bot: Ändere drei Zeilen von einer Seite.')
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals', "321")
% {'action': u'Ändere', 'line': u'dreihunderteinundzwanzig'},
u'Bot: Ändere dreihunderteinundzwanzig Zeilen von mehreren Seiten.')
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals',
{'action': u'Ändere', 'line': 1, 'page': 1}),
u'Bot: Ändere 1 Zeile von einer Seite.')
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals',
{'action': u'Ändere', 'line': 1, 'page': 2}),
u'Bot: Ändere 1 Zeile von mehreren Seiten.')
self.assertEqual(
i18n.twntranslate('de', 'test-multiple-plurals',
{'action': u'Ändere', 'line': "11", 'page': 2}),
u'Bot: Ändere 11 Zeilen von mehreren Seiten.')
开发者ID:Tillsa,项目名称:pywikibot_test_wikidata,代码行数:42,代码来源:i18n_tests.py
示例18: run
def run(self):
if not self.page.botMayEdit():
return
whys = self.analyze_page()
mintoarchive = int(self.get_attr('minthreadstoarchive', 2))
if self.archived_threads < mintoarchive:
# We might not want to archive a measly few threads
# (lowers edit frequency)
pywikibot.output(u'Only %d (< %d) threads are old enough. Skipping'
% (self.archived_threads, mintoarchive))
return
if whys:
# Search for the marker template
rx = re.compile(r'\{\{%s\s*?\n.*?\n\}\}'
% (template_title_regex(self.tpl).pattern), re.DOTALL)
if not rx.search(self.page.header):
raise MalformedConfigError(
"Couldn't find the template in the header"
)
pywikibot.output(u'Archiving %d thread(s).' % self.archived_threads)
# Save the archives first (so that bugs don't cause a loss of data)
for a in sorted(self.archives.keys()):
self.comment_params['count'] = self.archives[a].archived_threads
comment = i18n.twntranslate(self.site.code,
'archivebot-archive-summary',
self.comment_params)
self.archives[a].update(comment)
# Save the page itself
self.page.header = rx.sub(self.attr2text(), self.page.header)
self.comment_params['count'] = self.archived_threads
comma = self.site.mediawiki_message('comma-separator')
self.comment_params['archives'] \
= comma.join(a.title(asLink=True)
for a in self.archives.values())
self.comment_params['why'] = comma.join(whys)
comment = i18n.twntranslate(self.site.code,
'archivebot-page-summary',
self.comment_params)
self.page.update(comment)
开发者ID:metakgp,项目名称:batman,代码行数:41,代码来源:archivebot.py
示例19: __init__
def __init__(self, generator, templates, **kwargs):
"""
Constructor.
@param generator: the pages to work on
@type generator: iterable
@param replacements: a dictionary which maps old template names to
their replacements. If remove or subst is True, it maps the
names of the templates that should be removed/resolved to None.
@type replacements: dict
"""
self.availableOptions.update({
'subst': False,
'remove': False,
'summary': None,
'addedCat': None,
})
super(TemplateRobot, self).__init__(**kwargs)
self.generator = generator
self.templates = templates
site = pywikibot.Site()
if self.getOption('addedCat'):
self.options['addedCat'] = pywikibot.Category(site, self.getOption('addedCat'))
comma = site.mediawiki_message('comma-separator')
# get edit summary message if it's empty
if not self.getOption('summary'):
params = {'list': comma.join(self.templates.keys()),
'num': len(self.templates)}
if self.getOption('remove'):
self.options['summary'] = i18n.twntranslate(
site, 'template-removing', params)
elif self.getOption('subst'):
self.options['summary'] = i18n.twntranslate(
site, 'template-substituting', params)
else:
self.options['summary'] = i18n.twntranslate(
site, 'template-changing', params)
开发者ID:Exal117,项目名称:pywikibot-core,代码行数:40,代码来源:template.py
示例20: __init__
def __init__(self, generator, templates, subst = False, remove = False,
editSummary = '', acceptAll = False, addedCat = None):
"""
Arguments:
* generator - A page generator.
* replacements - A dictionary which maps old template names to
their replacements. If remove or subst is True,
it maps the names of the templates that should be
removed/resolved to None.
* remove - True if the template should be removed.
* subst - True if the template should be resolved.
"""
self.generator = generator
self.templates = templates
self.subst = subst
self.remove = remove
self.editSummary = editSummary
self.acceptAll = acceptAll
self.addedCat = addedCat
site = pywikibot.Site()
if self.addedCat:
self.addedCat = pywikibot.Category(
site, u'%s:%s' % (site.namespace(14), self.addedCat))
# get edit summary message if it's empty
if (self.editSummary==''):
Param = {'list': (', ').join(self.templates.keys()),
'num' : len(self.templates)}
if self.remove:
self.editSummary = i18n.twntranslate(
site, 'template-removing', Param)
elif self.subst:
self.editSummary = i18n.twntranslate(
site, 'template-substituting', Param)
else:
self.editSummary = i18n.twntranslate(
site, 'template-changing', Param)
开发者ID:reza1615,项目名称:pywikipedia-rewrite,代码行数:37,代码来源:template.py
注:本文中的pywikibot.i18n.twntranslate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论