def update_from_templates(self, pootle_path=None): """update translation project from templates""" if self.is_template_project: return template_translation_project = self.project.get_template_translationproject() if template_translation_project is None or template_translation_project == self: return monolingual = self.project.is_monolingual() if not monolingual: self.sync() if pootle_path is None: oldstats = self.getquickstats() for store in template_translation_project.stores.iterator(): if self.file_style == "gnu": new_pootle_path, new_path = get_translated_name_gnu(self, store) else: new_pootle_path, new_path = get_translated_name(self, store) if pootle_path is not None and new_pootle_path != pootle_path: continue convert_template(self, store, new_pootle_path, new_path, monolingual) self.scan_files() self.update(conservative=False) if pootle_path is None: newstats = self.getquickstats() post_template_update.send(sender=self, oldstats=oldstats, newstats=newstats)
def update_from_templates(self, pootle_path=None): """update translation project from templates""" if self.is_template_project: return template_translation_project = self.project.get_template_translationproject( ) if template_translation_project is None or template_translation_project == self: return monolingual = self.project.is_monolingual() if not monolingual: self.sync() if pootle_path is None: oldstats = self.getquickstats() for store in template_translation_project.stores.iterator(): if self.file_style == 'gnu': new_pootle_path, new_path = get_translated_name_gnu( self, store) else: new_pootle_path, new_path = get_translated_name(self, store) if pootle_path is not None and new_pootle_path != pootle_path: continue convert_template(self, store, new_pootle_path, new_path, monolingual) self.scan_files() #self.update(conservative=False) if pootle_path is None: newstats = self.getquickstats() post_template_update.send(sender=self, oldstats=oldstats, newstats=newstats)
def update_from_templates(self, pootle_path=None): """Update translation project from templates.""" if self.is_template_project: return template_translation_project = self.project \ .get_template_translationproject() if template_translation_project is None or \ template_translation_project == self: return monolingual = self.project.is_monolingual() if not monolingual: self.sync() if pootle_path is None: oldstats = self.getquickstats() from pootle_app.project_tree import convert_template, \ get_translated_name, get_translated_name_gnu for store in template_translation_project.stores.iterator(): if self.file_style == 'gnu': new_pootle_path, new_path = get_translated_name_gnu( self, store) else: new_pootle_path, new_path = get_translated_name(self, store) if pootle_path is not None and new_pootle_path != pootle_path: continue convert_template(self, store, new_pootle_path, new_path, monolingual) all_files, new_files = self.scan_files() #self.update(conservative=False) from pootle_misc.versioncontrol import hasversioning project_path = self.project.get_real_path() if new_files and hasversioning(project_path): from translate.storage import versioncontrol vcs = versioncontrol.get_versioned_object(project_path) output = vcs.add([s.abs_real_path for s in new_files], "New files added from %s based on templates" % (settings.TITLE)) if pootle_path is None: newstats = self.getquickstats() from pootle_app.models.signals import post_template_update post_template_update.send(sender=self, oldstats=oldstats, newstats=newstats)
def update_against_templates(self, pootle_path=None): """Update translation project from templates.""" if self.is_template_project: return template_translation_project = self.project \ .get_template_translationproject() if (template_translation_project is None or template_translation_project == self): return monolingual = self.project.is_monolingual() if not monolingual: self.sync() if pootle_path is None: oldstats = self.getquickstats() from pootle_app.project_tree import (convert_template, get_translated_name, get_translated_name_gnu) for store in template_translation_project.stores.iterator(): if self.file_style == 'gnu': new_pootle_path, new_path = get_translated_name_gnu(self, store) else: new_pootle_path, new_path = get_translated_name(self, store) if pootle_path is not None and new_pootle_path != pootle_path: continue convert_template(self, store, new_pootle_path, new_path, monolingual) all_files, new_files = self.scan_files(vcs_sync=False) #self.update(conservative=False) from pootle_misc import versioncontrol project_path = self.project.get_real_path() if new_files and versioncontrol.hasversioning(project_path): output = versioncontrol.add_files(project_path, [s.file.name for s in new_files], "New files added from %s based on templates" % (settings.TITLE)) if pootle_path is None: newstats = self.getquickstats() from pootle_app.models.signals import post_template_update post_template_update.send(sender=self, oldstats=oldstats, newstats=newstats)
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
def update_from_templates(self, pootle_path=None): """Update translation project from templates.""" if self.is_template_project: return template_translation_project = self.project.get_template_translationproject() if template_translation_project is None or template_translation_project == self: return monolingual = self.project.is_monolingual() if not monolingual: self.sync() if pootle_path is None: oldstats = self.getquickstats() from pootle_app.project_tree import convert_template, get_translated_name, get_translated_name_gnu for store in template_translation_project.stores.iterator(): if self.file_style == "gnu": new_pootle_path, new_path = get_translated_name_gnu(self, store) else: new_pootle_path, new_path = get_translated_name(self, store) if pootle_path is not None and new_pootle_path != pootle_path: continue convert_template(self, store, new_pootle_path, new_path, monolingual) all_files, new_files = self.scan_files() # self.update(conservative=False) from pootle_misc.versioncontrol import hasversioning project_path = self.project.get_real_path() if new_files and hasversioning(project_path): from translate.storage import versioncontrol vcs = versioncontrol.get_versioned_object(project_path) output = vcs.add( [s.abs_real_path for s in new_files], "New files added from %s based on templates" % (settings.TITLE) ) if pootle_path is None: newstats = self.getquickstats() from pootle_app.models.signals import post_template_update post_template_update.send(sender=self, oldstats=oldstats, newstats=newstats)
def convert_templates(template_translation_project, translation_project): translation_project.sync() oldstats = translation_project.getquickstats() for store in template_translation_project.stores.exclude(file='').iterator(): if translation_project.file_style == 'gnu': new_store_path = get_translated_name_gnu(translation_project, store) else: new_store_path = get_translated_name(translation_project, store) convert_template(store.file.path, new_store_path) scan_translation_project_files(translation_project) translation_project.update(conservative=False) newstats = translation_project.getquickstats() post_template_update.send(sender=translation_project, oldstats=oldstats, newstats=newstats)
def convert_templates(template_translation_project, translation_project): monolingual = translation_project.project.is_monolingual() if not monolingual: translation_project.sync() oldstats = translation_project.getquickstats() for store in template_translation_project.stores.iterator(): if translation_project.file_style == "gnu": new_pootle_path, new_path = get_translated_name_gnu(translation_project, store) else: new_pootle_path, new_path = get_translated_name(translation_project, store) convert_template(translation_project, store, new_pootle_path, new_path, monolingual) scan_translation_project_files(translation_project) translation_project.update(conservative=False) newstats = translation_project.getquickstats() post_template_update.send(sender=translation_project, oldstats=oldstats, newstats=newstats)
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
def update_against_templates(self, pootle_path=None): """Update translation project from templates.""" if self.is_template_project: return template_translation_project = self.project \ .get_template_translationproject() if (template_translation_project is None or template_translation_project == self): return monolingual = self.project.is_monolingual if not monolingual: self.sync() from pootle_app.project_tree import (convert_template, get_translated_name, get_translated_name_gnu) for store in template_translation_project.stores.iterator(): if self.file_style == 'gnu': new_pootle_path, new_path = get_translated_name_gnu(self, store) else: new_pootle_path, new_path = get_translated_name(self, store) if pootle_path is not None and new_pootle_path != pootle_path: continue try: from pootle.scripts import hooks relative_po_path = os.path.relpath(new_path, settings.PODIRECTORY) if not hooks.hook(self.project.code, "pretemplateupdate", relative_po_path): continue except: # Assume hook is not present. pass convert_template(self, store, new_pootle_path, new_path, monolingual) all_files, new_files = self.scan_files(vcs_sync=False) from pootle_misc import versioncontrol project_path = self.project.get_real_path() if new_files and versioncontrol.hasversioning(project_path): from pootle.scripts import hooks siteconfig = load_site_config() message = ("New files added from %s based on templates" % siteconfig.get('TITLE')) filestocommit = [] for new_file in new_files: try: hook_files = hooks.hook(self.project.code, "precommit", new_file.file.name, author=None, message=message) filestocommit.extend(hook_files) except ImportError: # Failed to import the hook - we're going to assume there # just isn't a hook to import. That means we'll commit the # original file. filestocommit.append(new_file.file.name) success = True try: output = versioncontrol.add_files(project_path, filestocommit, message) except Exception: logging.exception(u"Failed to add files") success = False for new_file in new_files: try: hooks.hook(self.project.code, "postcommit", new_file.file.name, success=success) except: #FIXME: We should not hide the exception - makes # development impossible pass if pootle_path is None: from pootle_app.models.signals import post_template_update post_template_update.send(sender=self)
success = False for new_file in new_files: try: hooks.hook(self.project.code, "postcommit", new_file.file.name, success=success) except: #FIXME: We should not hide the exception - makes # development impossible pass if pootle_path is None: newstats = self.getquickstats() from pootle_app.models.signals import post_template_update post_template_update.send(sender=self, oldstats=oldstats, newstats=newstats) def scan_files(self, vcs_sync=True): """Scans the file system and returns a list of translation files. :param vcs_sync: boolean on whether or not to synchronise the PO directory with the VCS checkout. """ projects = [p.strip() for p in self.project.ignoredfiles.split(',')] ignored_files = set(projects) ext = os.extsep + self.project.localfiletype # Scan for pots if template project if self.is_template_project: ext = os.extsep + self.project.get_template_filetype()
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
try: hooks.hook(self.project.code, "postcommit", new_file.file.name, success=success) except: #FIXME: We should not hide the exception - makes # development impossible pass if pootle_path is None: newstats = self.getquickstats() from pootle_app.models.signals import post_template_update post_template_update.send(sender=self, oldstats=oldstats, newstats=newstats) def scan_files(self, vcs_sync=True): """Scans the file system and returns a list of translation files. :param vcs_sync: boolean on whether or not to synchronise the PO directory with the VCS checkout. """ projects = [p.strip() for p in self.project.ignoredfiles.split(',')] ignored_files = set(projects) ext = os.extsep + self.project.localfiletype # Scan for pots if template project if self.is_template_project: ext = os.extsep + self.project.get_template_filetype()
def update_against_templates(self, pootle_path=None): """Update translation project from templates.""" if self.is_template_project: return template_translation_project = self.project \ .get_template_translationproject() if (template_translation_project is None or template_translation_project == self): return monolingual = self.project.is_monolingual() if not monolingual: self.sync() if pootle_path is None: oldstats = self.getquickstats() from pootle_app.project_tree import (convert_template, get_translated_name, get_translated_name_gnu) for store in template_translation_project.stores.iterator(): if self.file_style == 'gnu': new_pootle_path, new_path = get_translated_name_gnu( self, store) else: new_pootle_path, new_path = get_translated_name(self, store) if pootle_path is not None and new_pootle_path != pootle_path: continue relative_po_path = os.path.relpath(new_path, settings.PODIRECTORY) try: from pootle.scripts import hooks if not hooks.hook(self.project.code, "pretemplateupdate", relative_po_path): continue except: # Assume hook is not present. pass convert_template(self, store, new_pootle_path, new_path, monolingual) all_files, new_files = self.scan_files(vcs_sync=False) from pootle_misc import versioncontrol project_path = self.project.get_real_path() if new_files and versioncontrol.hasversioning(project_path): from pootle.scripts import hooks message = "New files added from %s based on templates" % \ (settings.TITLE) filestocommit = [] for new_file in new_files: try: filestocommit.extend( hooks.hook(self.project.code, "precommit", new_file.file.name, author=None, message=message)) except ImportError: # Failed to import the hook - we're going to assume there # just isn't a hook to import. That means we'll commit the # original file. filestocommit.append(new_file.file.name) success = True try: output = versioncontrol.add_files(project_path, filestocommit, message) except Exception as e: logging.error(u"Failed to add files: %s", e) success = False for new_file in new_files: try: hooks.hook(self.project.code, "postcommit", new_file.file.name, success=success) except: #FIXME: We should not hide the exception - makes # development impossible pass if pootle_path is None: newstats = self.getquickstats() from pootle_app.models.signals import post_template_update post_template_update.send(sender=self, oldstats=oldstats, newstats=newstats)
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