def exportByQuery(self, tm_id: int, query: str, target_langs: Union[str, List[str]], *, callback_url=None, **kwargs: dict) -> models.AsynchronousRequest: """Create a translation memory data export asynchronously. :param tm_id: ID of the translation memory. :param query: Text/pattern you are searching for. See Memsource documentation. :param target_langs: The target languages you would like exported. :param callback_url: Memsource will hit this url when finished to create the job. :param kwargs: See Memsource documentation https://wiki.memsource.com/wiki/Translation_Memory_Asynchronous_API_v2 :return: models.AsynchronousRequest """ return models.AsynchronousRequest( self._get( 'transMemory/exportByQuery', dict( kwargs, **{ 'transMemory': tm_id, 'exportTargetLang': target_langs, 'query': query, 'queryLang': target_langs, 'callbackUrl': callback_url, }))['asyncRequest'])
def getAsyncRequest(self, asynchronous_request_id: int) -> models.AsynchronousRequest: asyncRequest = self._post('async/getAsyncRequest', { 'asyncRequest': asynchronous_request_id, }) asyncRequest['asyncResponse'] = models.AsynchronousResponse(asyncRequest['asyncResponse']) return models.AsynchronousRequest(asyncRequest)
def preTranslate(self, job_parts, translation_memory_threshold=0.7, callback_url=None): """ return models.AsynchronousRequest """ return models.AsynchronousRequest(self._post('job/preTranslate', { 'jobPart': job_parts, 'translationMemoryThreshold': translation_memory_threshold, 'callbackUrl': callback_url, })['asyncRequest'])
def createAnalysis( self, job_parts: int, callback_url: str=None, **kwargs) -> models.AsynchronousRequest: """Create analysis asynchronously. :param job_parts: Make analysis for these job_part ids. :param callback_url: Memsource will send a callback when they finish analyzing. :param kwags: Another non required parameters, you can pass. """ res = self._post( 'analyse/create', dict(kwargs, jobPart=job_parts, callbackUrl=callback_url)) return models.AsynchronousRequest(res['asyncRequest']), models.Analysis(res['analyse'])
def preTranslate(self, job_parts: List[int], translation_memory_threshold: float=0.7, callback_url: str=None) -> models.AsynchronousRequest: """Call async pre translate API. :param job_parts: List of job_part id. :param translation_memory_threshold: If matching score is higher than this, it filled. :return: models.AsynchronousRequest """ return models.AsynchronousRequest(self._post('job/preTranslate', { 'jobPart': job_parts, 'translationMemoryThreshold': translation_memory_threshold, 'callbackUrl': callback_url, })['asyncRequest'])
def createJob( self, project_id: int, file_path: str, target_langs: (str, list), *, callback_url=None, **kwargs: dict ) -> Tuple[models.AsynchronousResponse, List[models.JobPart]]: """Create new Job on Memsource asynchronously. :param project_id: Project ID of target project. :param file_path: Absolute path of translation target file. :param target_langs: Translation target languages. :param callback_url: Memsource will hit this url when finished to create the job. :param kwargs: See Memsource official document http://wiki.memsource.com/wiki/Job_Asynchronous_API_v2 :return: models.AsynchronousResponse and list of models.JobPart """ with open(file_path, 'rb') as f: files = { 'file': (os.path.basename(file_path), f), } result = self._post( 'job/create', dict( kwargs, **{ 'project': project_id, 'targetLang': target_langs, 'callbackUrl': callback_url, }), files) # unsupported file count is 0 mean success. unsupported_files = result.get('unsupportedFiles', []) if len(unsupported_files) == 0: return (models.AsynchronousRequest(result['asyncRequest']), [ models.JobPart(job_parts) for job_parts in result['jobParts'] ]) raise exceptions.MemsourceUnsupportedFileException( unsupported_files, file_path, self.last_url, self.last_params)