예제 #1
0
    def _importTranslationFile(self, path, fileName, uriPath, locale, directives=None, overwrite=False):
        smartlingLocale = self._getSmartlingLocale(locale)

        # Test if English source exists
        try:
            self.api.getStatus(uriPath + fileName, smartlingLocale)
        except IOError:
            logging.error("Failed to import translation as English source has not been uploaded: %s", uriPath + fileName)
            raise ValueError("No English source: {0}".format(uriPath + fileName))

        absFile = os.path.join(path, fileName)
        if self.args.run:
            logging.debug("Importing translation (%s): %s", smartlingLocale, absFile)
            if not path.endswith(os.path.sep):
                path += os.path.sep
            uploadData = UploadData(path, fileName, self._getFileType(fileName), uriPath)
            uploadData.uri = uriPath + fileName
            if directives:
                for directive, value in directives:
                    uploadData.addDirective(SmartlingDirective(directive, value))
            stats = self.api.importFile(uploadData, smartlingLocale, overwrite)
            logging.info("Imported translation (%s): %s -> %s (Word count = %s)",
                         smartlingLocale,
                         absFile,
                         uriPath + fileName,
                         stats.wordCount)
        else:
            logging.info("Import translation (noop): %s -> %s", absFile, uriPath + fileName)
예제 #2
0
def ascii_test():
    #test simple file
    uploadDataASCII = UploadData(FILE_PATH, FILE_NAME, FILE_TYPE)
    uploadDataASCII.addDirective(SmartlingDirective("placeholder_format_custom", "\[.+?\]"))
    useSandbox = False
    example = SmartlingApiExample(useSandbox, uploadDataASCII, "it-IT", FILE_NAME_RENAMED)
    example.test()
예제 #3
0
def import_test():
    #example for import and last_modified commands
    uploadDataImport = UploadData(FILE_PATH, FILE_NAME_IMPORT, FILE_TYPE_IMPORT)
    uploadDataImport.addDirective(SmartlingDirective("placeholder_format_custom", "\[.+?\]"))
    useSandbox = False
    example = SmartlingApiExample(useSandbox, uploadDataImport, "it-IT", FILE_NAME_RENAMED)
    example.test_import(FILE_NAME_TO_IMPORT)
def upload_smartling_file(filepath, filename, locale='de-DE', file_type='json'):
    uploadDataUtf16 = UploadData(filepath, filename, file_type)
    uploadDataUtf16.setApproveContent("true")
    uploadDataUtf16.setCallbackUrl(settings.SMARTLING_CALLBACK_URL)
    useSandbox = False
    example = SmartlingApi(useSandbox, uploadDataUtf16, locale, filename)
    example.fapi.upload(example.uploadData)
예제 #5
0
def utf16_test():
    #add charset and approveContent parameters
    uploadDataUtf16 = UploadData(FILE_PATH, FILE_NAME_UTF16, FILE_TYPE)
    uploadDataUtf16.setApproveContent("true")
    uploadDataUtf16.setCallbackUrl(CALLBACK_URL)
    useSandbox = False
    example = SmartlingApiExample(useSandbox, uploadDataUtf16, "it-IT", FILE_NAME_RENAMED)
    example.test()
예제 #6
0
 def testImport(self):
     uploadData = UploadData(self.FILE_PATH, self.FILE_NAME, self.FILE_TYPE)
     uploadData.uri = self.uri
     uploadData.name = self.FILE_NAME_IMPORT
     resp, status = self.fapi.import_call(uploadData, self.locale, translationState="PUBLISHED")
     assert_equal(resp.code, self.CODE_SUCCESS_TOKEN)
     assert_equal(resp.data.wordCount, 2)
     assert_equal(resp.data.stringCount, 2)
     assert_equal(resp.data.translationImportErrors, [])
예제 #7
0
 def testImport(self):
     uploadData = UploadData(self.FILE_PATH, self.FILE_NAME, self.FILE_TYPE)
     uploadData.uri = self.uri
     uploadData.name = self.FILE_NAME_IMPORT
     resp, status = self.fapi.import_call(uploadData, self.locale, translationState="PUBLISHED")
     assert_equal(resp.code, self.CODE_SUCCESS_TOKEN)
     assert_equal(resp.data.wordCount, 2)
     assert_equal(resp.data.stringCount, 2)
     assert_equal(resp.data.translationImportErrors, [])
    def test_addDirective(self):
        ud = UploadData("path", "name", "type")
        assert_equal(len(ud.directives), 0)

        ud.addDirective(SmartlingDirective("name", "value"))
        assert_equal(len(ud.directives), 1)
        assert_equal(ud.directives[0].name, "name")

        ud.addDirective(SmartlingDirective("name2", "value2"))
        assert_equal(len(ud.directives), 2)
        assert_equal(ud.directives[1].value, "value2")
    def test_commandUpload_Callback_Approved(self):
        ud = UploadData("path", "name", "type")
        ud.setApproveContent("true")
        ud.setCallbackUrl("smartling.com")

        api = FileApiBase("host", "apiKey", "projectId")
        api.uploadMultipart = self.mock_uploadMultipart
        params = api.commandUpload(ud)

        assert_equal(len(params), 5)
        assert_equal(params[Params.APPROVED], "true")
        assert_equal(params[Params.CALLBACK_URL], "smartling.com")
예제 #10
0
    def test_commandUpload_Directives(self):
        ud = UploadData("path", "name", "type")
        ud.setApproveContent("true")
        ud.setCallbackUrl("smartling.com")
        ud.addDirective(
            SmartlingDirective("placeholder_format_custom", "\[.+?\]"))
        ud.addDirective(SmartlingDirective("placeholder_format", "IOS"))

        api = FileApiBase("host", "apiKey", "projectId")
        api.uploadMultipart = self.mock_uploadMultipart
        params = api.commandUpload(ud)

        assert_equal(len(params), 7)
        assert_equal(params["smartling.placeholder_format_custom"], "\[.+?\]")
        assert_equal(params["smartling.placeholder_format"], "IOS")
예제 #11
0
 def test_init(self):
     ud = UploadData("path", "name", "type")
     assert_equal(ud.path, "path")
     assert_equal(ud.name, "name")
     assert_equal(ud.type, "type")
     assert_equal(ud.type, "type")
     assert_equal(ud.approveContent, "false")
     assert_equal(ud.callbackUrl, "")
예제 #12
0
    def test_commandUpload_Directives(self):
        ud = UploadData("path", "name", "type")
        ud.setApproveContent("true")
        ud.setCallbackUrl("smartling.com")
        ud.addDirective(SmartlingDirective("placeholder_format_custom", "\[.+?\]"))
        ud.addDirective(SmartlingDirective("placeholder_format", "IOS"))

        api = FileApiBase("host", "apiKey", "projectId")
        api.uploadMultipart = self.mock_uploadMultipart
        params = api.commandUpload(ud)

        assert_equal(len(params), 7)
        assert_equal(params["smartling.placeholder_format_custom"], "\[.+?\]")
        assert_equal(params["smartling.placeholder_format"], "IOS")
예제 #13
0
    def test_commandUpload(self):
        ud = UploadData("path", "name", "type")

        api = FileApiBase("host", "apiKey", "projectId")
        api.uploadMultipart = self.mock_uploadMultipart
        params = api.commandUpload(ud)

        assert_equal(len(params), 4)
        assert_equal(params[Params.FILE_URI], "name")
        assert_equal(params[Params.FILE_TYPE], "type")
        assert_equal(params[Params.FILE_PATH], "pathname")
        assert_equal(params[Params.APPROVED], "false")
예제 #14
0
    def _uploadSourceFile(self, path, fileName, uriPath, directives=None):
        absFile = os.path.join(path, fileName)
        logging.debug("Uploading: %s", absFile)

        if not path.endswith(os.path.sep):
            path += os.path.sep

        if self.args.run:
            uploadData = UploadData(path, fileName, self._getFileType(fileName), uriPath)

            if directives:
                for directive, value in directives:
                    uploadData.addDirective(SmartlingDirective(directive, value))

            stats = self.api.uploadFile(uploadData)
            logging.info("Uploaded: %s -> %s (Word count = %s  New source = %s)",
                         absFile,
                         uriPath + fileName,
                         stats.wordCount,
                         "No" if stats.overWritten else "Yes")
        else:
            logging.info("Upload (noop): %s -> %s", os.path.join(path, fileName), uriPath + fileName)
예제 #15
0
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))
예제 #16
0
def upload_smartling_file(filepath,
                          filename,
                          locale='de-DE',
                          file_type='json'):
    uploadDataUtf16 = UploadData(filepath, filename, file_type)
    uploadDataUtf16.setApproveContent("true")
    uploadDataUtf16.setCallbackUrl(settings.SMARTLING_CALLBACK_URL)
    useSandbox = False
    example = SmartlingApi(useSandbox, uploadDataUtf16, locale, filename)
    example.fapi.upload(example.uploadData)
예제 #17
0
    def test_addDirective(self):
        ud = UploadData("path", "name", "type")
        assert_equal(len(ud.directives), 0)

        ud.addDirective(SmartlingDirective("name", "value"))
        assert_equal(len(ud.directives), 1)
        assert_equal(ud.directives[0].name, "name")

        ud.addDirective(SmartlingDirective("name2", "value2"))
        assert_equal(len(ud.directives), 2)
        assert_equal(ud.directives[1].value, "value2")
예제 #18
0
    def test_commandUpload_Callback_Approved(self):
        ud = UploadData("path", "name", "type")
        ud.setApproveContent("true")
        ud.setCallbackUrl("smartling.com")

        api = FileApiBase("host", "apiKey", "projectId")
        api.uploadMultipart = self.mock_uploadMultipart
        params = api.commandUpload(ud)

        assert_equal(len(params), 5)
        assert_equal(params[Params.APPROVED], "true")
        assert_equal(params[Params.CALLBACK_URL], "smartling.com")
예제 #19
0
 def doUpload(self):
     #ensure file is uploaded which is necessary for all tests
     uploadData = UploadData(self.FILE_PATH, self.FILE_NAME, self.FILE_TYPE)
     uploadData.setCallbackUrl(self.CALLBACK_URL)
     return self.fapi.upload(uploadData)
예제 #20
0
 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)
예제 #21
0
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'))
    upload_data.addDirective(SmartlingDirective('smartling.namespace', 'zendesk'))

    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)
        
        self.printMarker("delete from server goes here")
        print self.fapi.delete(self.new_name)
        
        self.printMarker("doing list again to see if it's deleted")
        print self.fapi.list()
        


FILE_NAME      = "java.properties"
FILE_NAME_UTF16= "javaUTF16.properties"
FILE_TYPE      = "javaProperties"        
FILE_PATH      = "../resources/"
FILE_NAME_RENAMED = "java.properties.renamed"
CALLBACK_URL      = "http://yourdomain.com/callback"

#test simple file
uploadDataASCII = UploadData(FILE_PATH, FILE_NAME, FILE_TYPE)
uploadDataASCII.addDirective(SmartlingDirective("placeholder_format_custom","\[.+?\]"))
useSandbox = False
example = SmartlingApiExample (useSandbox, uploadDataASCII, "ru-RU", FILE_NAME_RENAMED)
example.test()

#add charset and approveContent parameters
uploadDataUtf16 = UploadData(FILE_PATH, FILE_NAME_UTF16, FILE_TYPE)
uploadDataUtf16.setApproveContent("true")
uploadDataUtf16.setCallbackUrl(CALLBACK_URL)
useSandbox = True
example = SmartlingApiExample (useSandbox, uploadDataUtf16, "ru-RU", FILE_NAME_RENAMED)
example.test()
예제 #23
0
 def test_setApproveContent(self):
     ud = UploadData("path", "name", "type")
     ud.setApproveContent("true")
     assert_equal(ud.approveContent, "true")
예제 #24
0
 def test_setCallbackUrl(self):
     ud = UploadData("path", "name", "type")
     ud.setCallbackUrl("smartling.com")
     assert_equal(ud.callbackUrl, "smartling.com")
        
        self.printMarker("delete from server goes here")
        print self.fapi.delete(self.new_name)
        
        self.printMarker("doing list again to see if it's deleted")
        print self.fapi.list()
        


FILE_NAME      = "java.properties"
FILE_NAME_UTF16= "javaUTF16.properties"
FILE_TYPE      = "javaProperties"        
FILE_PATH      = "../resources/"
FILE_NAME_RENAMED = "java.properties.renamed"
CALLBACK_URL      = "http://yourdomain.com/callback"

#test simple file
uploadData = UploadData(FILE_PATH, FILE_NAME, FILE_TYPE)
useSandbox = False
uploadData.setCallbackUrl(CALLBACK_URL)
example = SmartlingApiExample (useSandbox, uploadData, "ru-RU", FILE_NAME_RENAMED)
example.test()

#add charset and approveContent parameters
uploadDataUtf16 = UploadData(FILE_PATH, FILE_NAME_UTF16, FILE_TYPE)
uploadDataUtf16.setCharset("UTF-16")
uploadDataUtf16.setApproveContent("true")
uploadData.setCallbackUrl(CALLBACK_URL)
useSandbox = True
example = SmartlingApiExample (useSandbox, uploadDataUtf16, "ru-RU", FILE_NAME_RENAMED)
example.test()
예제 #26
0
 def test_setApproveContent(self):
     ud = UploadData("path", "name", "type")
     ud.setApproveContent("true")
     assert_equal(ud.approveContent, "true")
예제 #27
0
 def test_setCallbackUrl(self):
     ud = UploadData("path", "name", "type")
     ud.setCallbackUrl("smartling.com")
     assert_equal(ud.callbackUrl, "smartling.com")