def save_source_file(resource, user, content, method, filename=None): """Save new source file. Called by the "edit resource" action. """ fb = FormatsBackend(resource, resource.source_language, user) return fb.import_source(content, filename)
def get_translation_file(request, project_slug, resource_slug, lang_code, **kwargs): """ View to export all translations of a resource for the requested language and give the translation file back to the user. """ resource = get_object_or_404(Resource, project__slug = project_slug, slug = resource_slug) language = get_object_or_404(Language, code=lang_code) try: fb = FormatsBackend(resource, language) template = fb.compile_translation(**kwargs) except Exception, e: messages.error(request, "Error compiling translation file.") logger.error("Error compiling '%s' file for '%s': %s" % (language, resource, str(e))) return HttpResponseRedirect(reverse('resource_detail', args=[resource.project.slug, resource.slug]),)
def get(self, pseudo_type, mode=None): """ Return the requested translation as a file. Returns: The compiled template. Raises: BadRequestError: There was a problem with the request. """ try: fb = FormatsBackend(self.resource, self.language) return fb.compile_translation(pseudo_type, mode=mode) except Exception, e: logger.error(unicode(e), exc_info=True) raise BadRequestError("Error compiling the translation file: %s" %e )
def get_pot_file(request, project_slug, resource_slug): """ View to download the pot file of the resource. """ resource = get_object_or_404(Resource, project__slug=project_slug, slug=resource_slug) try: fb = FormatsBackend(resource, None) template = fb.compile_translation() except Exception, e: messages.error(request, _("Error compiling the pot file.")) logger.error("Error compiling the pot file for %s: %s" % (resource, e)) return HttpResponseRedirect( reverse('resource_detail', args=[resource.project.slug, resource.slug]))
def get(self, pseudo_type, mode=None): """ Return the requested translation as a file. Returns: The compiled template. Raises: BadRequestError: There was a problem with the request. """ try: fb = FormatsBackend(self.resource, self.language) return fb.compile_translation(pseudo_type, mode=mode) except Exception, e: logger.error(unicode(e), exc_info=True) raise BadRequestError("Error compiling the translation file: %s" % e)
def get_pot_file(request, project_slug, resource_slug): """ View to download the pot file of the resource. """ resource = get_object_or_404( Resource, project__slug=project_slug, slug=resource_slug ) try: fb = FormatsBackend(resource, None) template = fb.compile_translation() except Exception, e: messages.error(request, _("Error compiling the pot file.")) logger.error( "Error compiling the pot file for %s: %s" % (resource, e) ) return HttpResponseRedirect(reverse( 'resource_detail', args=[resource.project.slug, resource.slug] ))
def get_translation_file(request, project_slug, resource_slug, lang_code, **kwargs): """ View to export all translations of a resource for the requested language and give the translation file back to the user. """ resource = get_object_or_404(Resource, project__slug=project_slug, slug=resource_slug) language = get_object_or_404(Language, code=lang_code) try: fb = FormatsBackend(resource, language) template = fb.compile_translation(**kwargs) except Exception, e: messages.error(request, "Error compiling translation file.") logger.error("Error compiling '%s' file for '%s': %s" % (language, resource, str(e))) return HttpResponseRedirect( reverse('resource_detail', args=[resource.project.slug, resource.slug]), )
def get(self, start=None, end=None, pseudo_type=None, mode=None): """ Return the requested translation in a json string. If self.language is None, return all translations. Args: start: Start for pagination. end: End for pagination. pseudo_type: The pseudo_type requested. mode: The mode for the compilation. Returns: A dict with the translation(s). Raises: BadRequestError: There was a problem with the request. """ try: fb = FormatsBackend(self.resource, self.language) template = fb.compile_translation(pseudo_type, mode=mode) except Exception, e: logger.error(unicode(e), exc_info=True) raise BadRequestError("Error compiling the translation file: %s" % e)
def get(self, start=None, end=None, pseudo_type=None, mode=None): """ Return the requested translation in a json string. If self.language is None, return all translations. Args: start: Start for pagination. end: End for pagination. pseudo_type: The pseudo_type requested. mode: The mode for the compilation. Returns: A dict with the translation(s). Raises: BadRequestError: There was a problem with the request. """ try: fb = FormatsBackend(self.resource, self.language) template = fb.compile_translation(pseudo_type, mode=mode) except Exception, e: logger.error(unicode(e), exc_info=True) raise BadRequestError( "Error compiling the translation file: %s" % e )
def _save_translation(resource, target_language, user, content): """Save a new translation file for the resource.""" fb = FormatsBackend(resource, target_language, user) return fb.import_translation(content)