本文整理汇总了Python中pootle_project.models.Project.source_language方法的典型用法代码示例。如果您正苦于以下问题:Python Project.source_language方法的具体用法?Python Project.source_language怎么用?Python Project.source_language使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pootle_project.models.Project
的用法示例。
在下文中一共展示了Project.source_language方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _source_to_pootle_project
# 需要导入模块: from pootle_project.models import Project [as 别名]
# 或者: from pootle_project.models.Project import source_language [as 别名]
def _source_to_pootle_project(article):
import logging
from django.utils.encoding import smart_str
from pootle_app.models.signals import post_template_update
# Fetch the source_language
sl_set = Language.objects.filter(code=article.language)
if len(sl_set) < 1:
return False
source_language = sl_set[0]
# Construct the project
project = Project()
project.fullname = u"%s:%s" % (article.language, article.title)
project.code = project.fullname.replace(" ", "_").replace(":", "_")
# PO filetype
#project.localfiletype = "po" # filetype_choices[0]
project.source_language = source_language
# Save the project
project.save()
templates_language = Language.objects.filter(code='templates')[0]
project.add_language(templates_language)
project.save()
#code copied for wr_articles
logging.debug ( "project saved")
# Export the article to .po and store in the templates "translation project". This will be used to generate translation requests for other languages.
templatesProject = project.get_template_translationproject()
po = article.sentences_to_po()
poFilePath = "%s/article.pot" % (templatesProject.abs_real_path)
oldstats = templatesProject.getquickstats()
# Write the file
with open(poFilePath, 'w') as f:
f.write(smart_str(po.__str__()))
# Force the project to scan for changes.
templatesProject.scan_files()
templatesProject.update(conservative=False)
# Log the changes
newstats = templatesProject.getquickstats()
post_template_update.send(sender=templatesProject, oldstats=oldstats, newstats=newstats)
return project
示例2: notusedsource_to_pootle_project
# 需要导入模块: from pootle_project.models import Project [as 别名]
# 或者: from pootle_project.models.Project import source_language [as 别名]
def notusedsource_to_pootle_project(self):
"""
Constructs a Pootle project from the article, if a project doesn't already exist.
"""
logging.debug ( "source_to_pootle_project" )
from pootle_app.models.signals import post_template_update
if self.pootle_project_exists():
raise Exception("Project %s already exists!" % self.get_project_name())
# Fetch the source_language
sl_set = Language.objects.filter(code = self.language)
if len(sl_set) < 1:
raise Exception("Language code %s does not exist!" % self.language)
source_language = sl_set[0]
logging.debug ( "source language" + source_language )
# Construct the project
project = Project()
project.fullname = self.get_project_name()
project.code = self.get_project_code()
project.source_language = source_language
# Save the project
project.save()
logging.debug ( "project saved")
# Export the article to .po and store in the templates "translation project". This will be used to generate translation requests for other languages.
templatesProject = project.get_template_translationproject()
po = self.sentences_to_po()
poFilePath = "%s/article.pot" % (templatesProject.abs_real_path)
oldstats = templatesProject.getquickstats()
# Write the file
with open(poFilePath, 'w') as f:
f.write(po.__str__())
# Force the project to scan for changes.
templatesProject.scan_files()
templatesProject.update(conservative=False)
# Log the changes
newstats = templatesProject.getquickstats()
post_template_update.send(sender=templatesProject, oldstats=oldstats, newstats=newstats)
return project
示例3: _source_to_pootle_project
# 需要导入模块: from pootle_project.models import Project [as 别名]
# 或者: from pootle_project.models.Project import source_language [as 别名]
def _source_to_pootle_project(article):
# Fetch the source_language
sl_set = Language.objects.filter(code=article.language)
if len(sl_set) < 1:
return false
source_language = sl_set[0]
# Construct the project
project = Project()
project.fullname = u"%s:%s" % (article.language, article.title)
project.code = project.fullname.replace(" ", "_").replace(":", "_")
# PO filetype
# project.localfiletype = "po" # filetype_choices[0]
project.source_language = source_language
# Save the project
project.save()
return project
示例4: create_pootle_project
# 需要导入模块: from pootle_project.models import Project [as 别名]
# 或者: from pootle_project.models.Project import source_language [as 别名]
def create_pootle_project(self):
'''
Creates a project to be used in Pootle. A templates language is created and a .pot
template is generated from the SourceSentences in the article.
'''
import logging
from django.utils.encoding import smart_str
from pootle_app.models.signals import post_template_update
# Fetch the source_language
sl_set = Language.objects.filter(code = self.language.code)
if len(sl_set) < 1:
return False
source_language = sl_set[0]
# 1. Construct the project
project = Project()
project.fullname = u"%s:%s" % (self.language.code, self.title)
project.code = project.fullname.replace(" ", "_").replace(":", "_")
# PO filetype
#project.localfiletype = "po" # filetype_choices[0]
project.source_language = source_language
# Save the project
project.save()
templates_language = Language.objects.get_by_natural_key('templates')
# Check to see if the templates language exists. If not, add it.
#if not project.language_exists(templates_language):
if len(project.translationproject_set.filter(language=templates_language)) == 0:
project.add_language(templates_language)
project.save()
#code copied for wt_articles
logging.debug ( "project saved")
# 2. Export the article to .po and store in the templates "translation project". This will be used to generate translation requests for other languages.
templatesProject = project.get_template_translationproject()
po = self.sentences_to_po()
poFilePath = "%s/article.pot" % (templatesProject.abs_real_path)
oldstats = templatesProject.getquickstats()
# Write the file
with open(poFilePath, 'w') as f:
f.write(smart_str(po.__str__()))
# Force the project to scan for changes.
templatesProject.scan_files()
templatesProject.update(conservative=False)
# Log the changes
newstats = templatesProject.getquickstats()
post_template_update.send(sender=templatesProject, oldstats=oldstats, newstats=newstats)
# Add a reference to the project in the SourceArticle
self.pootle_project = project
self.save()
return project