def upload_source_file_to_smartling(path, file_name, file_type, fields_to_translate, approve, slapi): """ Upload a source file of type file_type to Smartling. """ path = path + '/' # sdk requires TODO check this upload_data = UploadData(path, file_name, file_type, file_name) upload_data.setUri(file_name) if approve: upload_data.setApproveContent('true') else: upload_data.setApproveContent('false') upload_data.addDirective(SmartlingDirective('translate_paths', ','.join(fields_to_translate))) upload_data.addDirective(SmartlingDirective('string_format_paths', 'html:body')) upload_data.addDirective(SmartlingDirective('source_key_paths', 'title')) response, http_response_code = slapi.upload(upload_data) if http_response_code == 200: response_data = response.data logging.debug('Uploaded to Smartling: %s', file_name) logging.debug('Overwritten: %s, String count: %s, Word count: %s', response_data.overWritten, response_data.stringCount, response_data.wordCount) else: raise SmartlingError('Error in Smartling API upload call', http_response_code, response)
def upload_file(fapi, file_name, conf): """ Uploads a file to smartling """ if not conf.has_key('file-type'): raise SmarterlingError("%s doesn't have a file-type" % file_name) print("Uploading %s to smartling" % file_name) data = UploadData( os.path.dirname(file_name)+os.sep, os.path.basename(file_name), conf.get('file-type')) data.setUri(file_uri(file_name, conf)) if conf.has_key('approve-content'): data.setApproveContent("true" if conf.get('approve-content', True) else "false") if conf.has_key('callback-url'): data.setCallbackUrl(conf.get('callback-url')) for name, value in conf.get('directives', {}).items(): data.addDirective(SmartlingDirective(name, value)) (response, code) = fapi.upload(data) if code!=200: print(repr(response)) raise SmarterlingError("Error uploading file: %s" % file_name) else: print("Uploaded %s, wordCount: %s, stringCount: %s" % (file_name, response.data.wordCount, response.data.stringCount))
def doUpload(self, name, uri): #ensure file is uploaded which is necessary for all tests uploadData = UploadData(self.FILE_PATH, name, self.FILE_TYPE) uploadData.setUri(uri) uploadData.setCallbackUrl(self.CALLBACK_URL) return self.fapi.upload(uploadData)