コード例 #1
0
ファイル: smartlingzd.py プロジェクト: OCreaven/TEST
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)
コード例 #2
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)
コード例 #3
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()
コード例 #4
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)
コード例 #5
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")
コード例 #6
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")
コード例 #7
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")
コード例 #8
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")
コード例 #9
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))
コード例 #10
0
 def test_setApproveContent(self):
     ud = UploadData("path", "name", "type")
     ud.setApproveContent("true")
     assert_equal(ud.approveContent, "true")
コード例 #11
0
 def test_setApproveContent(self):
     ud = UploadData("path", "name", "type")
     ud.setApproveContent("true")
     assert_equal(ud.approveContent, "true")
コード例 #12
0
        
        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()