2 __author__
= 'jangbi882@gmail.com'
4 ########################################################
5 # Script for TadpoleUI trans by http://www.Transifex.com
13 PROJECT_NAME
= "tadpoleui"
15 DST_DIR
= "" #"c:/OpenGIS/TadpoleDbHub/TransifexL10N"
17 PATH_PATTERN1
= "/?.*/src/"
18 RES_PATTERN1
= "/src/(.*)/(messages).*\\.properties"
19 PATH_PATTERN2
= "/OSGI-INF/l10n"
20 RES_PATTERN2
= "/(\\w+\\.[\\w\\.]+)/.*/(bundle).*\\.properties"
22 LANG_PATTERN
= "_(.*)\\.properties"
24 LANG_LIST
= ["ko", "ep", "id"] # 새로운 언어기 추가되면 이 리스트에 추가
31 python {0} -update: push source and pull translated resources
32 python {0} -init: Initialize configuration for Transifex Client(tx)
33 python {0} -push_source: Push source resource ({1}) to transifex.com
34 python {0} -push_trans: Push translated resource to transifex.com
35 python {0} -pull_trans: Pull translated resource from transifex.com
36 python {0} -help: Show this message
37 """.format(cmd
, DEFAULT_LANG
))
42 rc
= os
.system("tx --version")
46 [ERROR] Transifex Client, tx command is not installed.
47 Please setup Transifex Client first.
48 Refer to the following link.
49 http://docs.transifex.com/developer/client/setup
59 configFolder
= os
.path
.join(pwd
, ".tx")
61 if os
.path
.isdir(configFolder
):
65 [ERROR] Cannot find any .tx directory!
66 Run 'tx init' to initialize your project first!
67 ProjectNotInit: Cannot find any .tx directory!
73 # convert package name to resource name
75 path
= path
.replace("\\", "/")
76 if re
.search(PATH_PATTERN1
, path
):
77 matched
= re
.findall(RES_PATTERN1
, path
)
79 return matched
[0][0].replace("/", "_").replace("com_hangum_tadpole_", "").replace("com_hamgum_tadpole_", "")+"__"+matched
[0][1]
80 elif re
.search(PATH_PATTERN2
, path
):
81 matched
= re
.findall(RES_PATTERN2
, path
)
83 return matched
[0][0].replace(".", "_").replace("com_hangum_tadpole_", "").replace("com_hamgum_tadpole_", "")+"__"+matched
[0][1]
87 def checkFolderPattern(path
):
88 path
= path
.replace("\\", "/")
89 if re
.search(PATH_PATTERN1
, path
) or re
.search(PATH_PATTERN2
, path
):
94 def getLang(filename
):
95 langs
= re
.findall(LANG_PATTERN
, filename
)
103 ### Transifex 설정파일 초기화
104 # [주의] 원본 리소스는 Transifex.com에 미리 등록되어 있어야 한다.
107 for (path
, dir, files
) in os
.walk(SRC_DIR
):
109 if not checkFolderPattern(path
):
113 for filename
in files
:
114 src_path
= os
.path
.join(path
, filename
)
116 # make resource name from path
117 resource_name
= getResName(src_path
)
118 if not resource_name
:
122 lang
= getLang(filename
)
125 if lang
== DEFAULT_LANG
:
126 dst_path
= os
.path
.join(DST_DIR
, "{0}.properties".format(resource_name
))
128 cmd
= "tx set -t PROPERTIES --source -r {0}.{1} -l en {1}.properties".format(PROJECT_NAME
, resource_name
)
130 dst_path
= os
.path
.join(DST_DIR
, "{0}_{1}.properties".format(resource_name
, lang
))
132 cmd
= "tx set -r {2}.{0} -l {1} {0}_{1}.properties".format(resource_name
, lang
, PROJECT_NAME
)
135 flag_need_temp
= True
136 if os
.path
.isfile(dst_path
):
137 flag_need_temp
= False
141 temp_file
= open(dst_path
, 'w')
154 ## 레파지토리에서 복사해 와 Transifex.com에 원본 올리기
157 for (path
, dir, files
) in os
.walk(SRC_DIR
):
159 if not checkFolderPattern(path
):
163 for filename
in files
:
164 src_path
= os
.path
.join(path
, filename
)
166 # make resource name from path
167 resource_name
= getResName(src_path
)
168 if not resource_name
:
172 lang
= getLang(filename
)
173 if lang
!= DEFAULT_LANG
:
176 dst_path
= os
.path
.join(DST_DIR
, "{0}.properties".format(resource_name
))
179 shutil
.copy2(src_path
, dst_path
)
181 cmd
= "tx push -r {0}.{1} -s -f --no-interactive".format(PROJECT_NAME
, resource_name
)
185 print "[WARNING] Fail to register {0}".format(dst_path
)
189 ## Transifex.com에 로컬의 번역 올리기
192 for (path
, dir, files
) in os
.walk(SRC_DIR
):
194 if not checkFolderPattern(path
):
198 for filename
in files
:
199 src_path
= os
.path
.join(path
, filename
)
201 # make resource name from path
202 resource_name
= getResName(src_path
)
203 if not resource_name
:
207 lang
= getLang(filename
)
208 if lang
== DEFAULT_LANG
:
211 dst_path
= os
.path
.join(DST_DIR
, "{0}_{1}.properties".format(resource_name
, lang
))
214 shutil
.copy2(src_path
, dst_path
)
216 cmd
= "tx push -l {1} -r {2}.{0} -t -f --no-interactive".format(resource_name
, lang
, PROJECT_NAME
)
220 print "[WARNING] Fail to register {0}".format(dst_path
)
224 ### transifex.com에서 새 번역 가져오기
227 for (path
, dir, files
) in os
.walk(SRC_DIR
):
229 if not checkFolderPattern(path
):
232 if files
.count("messages.properties") > 0:
233 resource_name
= getResName(os
.path
.join(path
, "messages.properties"))
234 if not resource_name
:
237 for lang
in LANG_LIST
:
238 src_path
= os
.path
.join(path
, "messages_{0}.properties".format(lang
))
239 dst_path
= os
.path
.join(DST_DIR
, "{0}_{1}.properties".format(resource_name
, lang
))
242 if not os
.path
.isfile(src_path
):
246 cmd
= "tx pull -l {1} -r {2}.{0} -f".format(resource_name
, lang
, PROJECT_NAME
)
250 print "[WARNING] Fail to pull {0}".format(dst_path
)
253 print ("copy {0} {1}".format(os
.path
.abspath(dst_path
), os
.path
.abspath(src_path
)))
254 shutil
.copy2(dst_path
, src_path
)
256 elif files
.count("bundle.properties") > 0:
257 resource_name
= getResName(os
.path
.join(path
, "bundle.properties"))
258 if not resource_name
:
261 for lang
in LANG_LIST
:
262 src_path
= os
.path
.join(path
, "bundle_{0}.properties".format(lang
))
263 dst_path
= os
.path
.join(DST_DIR
, "{0}_{1}.properties".format(resource_name
, lang
))
266 if not os
.path
.isfile(src_path
):
270 cmd
= "tx pull -l {1} -r {2}.{0} -f".format(resource_name
, lang
, PROJECT_NAME
)
274 print "[WARNING] Fail to pull {0}".format(dst_path
)
277 print ("copy {0} {1}".format(os
.path
.abspath(dst_path
), os
.path
.abspath(src_path
)))
278 shutil
.copy2(dst_path
, src_path
)
286 cmd
= os
.path
.split(args
[0])[1]
291 option
= args
[1].lower()
296 if not checkTxInit():
299 DST_DIR
= os
.getcwd()
303 elif option
== "-update":
306 elif option
== "-help":
308 elif option
== "-init":
310 elif option
== "-push_source":
312 elif option
== "-push_trans":
314 elif option
== "-pull_trans":
316 elif option
== "-init_all":
324 ### 커맨드로 실행된 경우 main() 실행
325 if __name__
== "__main__":