forked from Smartling/api-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartlingApiExample.py
More file actions
86 lines (68 loc) · 3.08 KB
/
Copy pathSmartlingApiExample.py
File metadata and controls
86 lines (68 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
''' Copyright 2012 Smartling, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this work except in compliance with the License.
* You may obtain a copy of the License in the LICENSE file, or at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
'''
import os, sys
lib_path = os.path.abspath('../')
sys.path.append(lib_path) # allow to import ../smartlingApiSdk/SmartlingFileApi
from smartlingApiSdk.SmartlingFileApi import SmartlingFileApi, SmartlingFileApiFactory
from smartlingApiSdk.UploadData import UploadData
class SmartlingApiExample:
HOST = 'sandbox-api.smartling.com'
MY_API_KEY = "YOUR_API_KEY"
MY_PROJECT_ID = "YOUR_PROJECT_ID"
def __init__(self, useSandbox, uploadData, locale, new_name):
if useSandbox :
self.fapi = SmartlingFileApiFactory().getSmartlingTranslationApi(False, self.MY_API_KEY, self.MY_PROJECT_ID)
else:
self.fapi = SmartlingFileApiFactory().getSmartlingTranslationApiProd(self.MY_API_KEY, self.MY_PROJECT_ID)
self.uploadData = uploadData
self.locale = locale
self.new_name = new_name
def printMarker(self, caption):
print "--" + caption + "-"*40
def test(self):
self.printMarker("file upload")
print self.fapi.upload(uploadData)
self.printMarker("files list")
print self.fapi.list()
self.printMarker("file status")
print self.fapi.status(self.uploadData.name, self.locale)
self.printMarker("file from server goes here")
print self.fapi.get( self.uploadData.name, self.locale)
self.printMarker("renaming file")
print self.fapi.rename(self.uploadData.name, self.new_name)
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()