2011-10-24 17:06:22 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
# Copyright (c) 2010 norbert.nagold@gmail.com
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation; either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
# This script updates the master file(s) for crowdin.net
|
|
|
|
# There seems to a bug in the upload of translation files; it's therefore deactivated
|
|
|
|
|
|
|
|
import pycurl
|
|
|
|
import StringIO
|
|
|
|
import sys
|
2012-07-16 13:50:29 +02:00
|
|
|
import string
|
|
|
|
import os
|
2011-10-24 17:06:22 +02:00
|
|
|
|
2011-10-24 17:17:02 +02:00
|
|
|
CROWDIN_KEY = ''
|
2011-10-24 17:06:22 +02:00
|
|
|
PROJECT_IDENTIFIER = 'ankidroid'
|
|
|
|
|
2015-01-20 05:41:11 +01:00
|
|
|
path = '../AnkiDroid/src/main/res/values/'
|
2011-10-24 17:06:22 +02:00
|
|
|
|
2015-03-31 11:41:37 +02:00
|
|
|
files = ['01-core', '02-strings', '03-dialogs', '04-network', '05-feedback', '06-statistics', '07-cardbrowser', '08-widget', '09-backup', '10-preferences', '11-arrays', '14-marketdescription', '16-multimedia-editor']
|
2012-10-07 11:37:49 +02:00
|
|
|
alllang = ['ar', 'ca', 'cs', 'de', 'el', 'es-AR', 'es-ES', 'fa', 'fi', 'fr', 'hu', 'id', 'it', 'ja', 'ko', 'nl', 'pl', 'pt-PT', 'pt-BR', 'ro', 'ru', 'sr', 'sv-SE', 'th', 'tr', 'vi', 'zh-CN', 'zh-TW']
|
2011-10-29 21:48:00 +02:00
|
|
|
|
2011-10-24 17:06:22 +02:00
|
|
|
|
|
|
|
def uploadtranslation(language, filename, sourcefile):
|
2012-02-24 17:45:15 +01:00
|
|
|
if len(language) > 2:
|
2012-02-29 14:08:12 +01:00
|
|
|
pathlan = string.replace(language, '-', '-r')
|
2012-07-16 13:50:29 +02:00
|
|
|
if not os.path.exists('../res/values-' + pathlan):
|
|
|
|
pathlan = pathlan[:2]
|
2012-02-29 11:45:44 +01:00
|
|
|
else:
|
|
|
|
pathlan = language
|
2011-10-24 17:06:22 +02:00
|
|
|
path = '../res/values-' + pathlan + '/'
|
|
|
|
filename = filename + '.xml'
|
|
|
|
# if selu == 's':
|
|
|
|
# filename = 'strings.xml'
|
|
|
|
# elif selu == 'a':
|
|
|
|
# filename = 'arrays.xml'
|
|
|
|
# else:
|
|
|
|
# filename = ''
|
|
|
|
# print "nothing to do"
|
|
|
|
print 'Update of Translation '+language+' for '+filename
|
|
|
|
if filename:
|
|
|
|
if language:
|
|
|
|
c = pycurl.Curl()
|
2012-07-16 13:17:32 +02:00
|
|
|
fields = [('files['+filename+']', (c.FORM_FILE, path + sourcefile + '.xml')), ('language', language), ('auto_approve_imported','0'), ('import_eq_suggestions','0')]
|
2014-09-17 06:05:29 +02:00
|
|
|
c.setopt(pycurl.URL, 'https://api.crowdin.com/api/project/' + PROJECT_IDENTIFIER + '/upload-translation?key=' + CROWDIN_KEY)
|
2011-10-24 17:06:22 +02:00
|
|
|
c.setopt(pycurl.HTTPPOST, fields)
|
|
|
|
b = StringIO.StringIO()
|
|
|
|
c.setopt(pycurl.WRITEFUNCTION, b.write)
|
|
|
|
c.perform()
|
|
|
|
c.close()
|
|
|
|
print b.getvalue()
|
|
|
|
else:
|
|
|
|
print 'no language code entered'
|
|
|
|
|
2015-01-20 05:41:11 +01:00
|
|
|
def updateMasterFile(fn):
|
|
|
|
if fn == '14-marketdescription':
|
2011-10-30 10:58:56 +01:00
|
|
|
targetName = '14-marketdescription.txt'
|
2012-05-15 09:53:00 +02:00
|
|
|
sourceName = '../docs/marketing/localized_description/marketdescription.txt'
|
2011-10-24 17:06:22 +02:00
|
|
|
else:
|
2015-01-20 05:41:11 +01:00
|
|
|
targetName = fn + '.xml'
|
2011-10-29 23:35:51 +02:00
|
|
|
sourceName = path + targetName
|
|
|
|
if targetName:
|
|
|
|
print 'Update of Master File ' + targetName
|
2011-10-24 17:06:22 +02:00
|
|
|
c = pycurl.Curl()
|
2011-10-29 23:35:51 +02:00
|
|
|
fields = [('files['+targetName+']', (c.FORM_FILE, sourceName))]
|
2014-09-16 06:17:40 +02:00
|
|
|
c.setopt(pycurl.URL, 'https://api.crowdin.com/api/project/' + PROJECT_IDENTIFIER + '/update-file?key=' + CROWDIN_KEY)
|
2011-10-24 17:06:22 +02:00
|
|
|
c.setopt(pycurl.HTTPPOST, fields)
|
|
|
|
b = StringIO.StringIO()
|
|
|
|
c.setopt(pycurl.WRITEFUNCTION, b.write)
|
|
|
|
c.perform()
|
|
|
|
c.close()
|
|
|
|
print b.getvalue()
|
|
|
|
|
2011-10-27 16:04:08 +02:00
|
|
|
|
2011-10-24 17:17:02 +02:00
|
|
|
try:
|
|
|
|
c = open("crowdin_key.txt","r+")
|
|
|
|
CROWDIN_KEY = c.readline();
|
|
|
|
c.close()
|
|
|
|
except IOError as e:
|
|
|
|
CROWDIN_KEY = raw_input("please enter your crowdin key or create \'crowdin_key.txt\': ")
|
2011-10-24 17:06:22 +02:00
|
|
|
|
|
|
|
sel = raw_input("update (m)aster file, update (t)ranslation or (r)efresh builds? ")
|
|
|
|
|
|
|
|
if sel == 'm':
|
|
|
|
# Update Master Files:
|
2015-01-20 05:41:11 +01:00
|
|
|
fn = raw_input("update " + ', '.join([str(x) for x in files]) + ", (all)?")
|
|
|
|
if fn == 'all':
|
|
|
|
for n in range(0, len(files)):
|
|
|
|
updateMasterFile(files[n])
|
2011-10-24 17:06:22 +02:00
|
|
|
else:
|
2015-01-20 05:41:11 +01:00
|
|
|
updateMasterFile(fn)
|
2011-10-24 17:06:22 +02:00
|
|
|
|
|
|
|
elif sel == 't':
|
|
|
|
# Update Translations:
|
|
|
|
print 'still problems with crowding here'
|
|
|
|
language = raw_input("enter language code: ")
|
2011-10-26 01:44:01 +02:00
|
|
|
selu = raw_input("update 0(1)-core, 0(2)-strings, 0(3)-dialogs, 0(4)-network, 0(5)-feedback, 0(6)-statistics, 0(7)-cardbrowser, 0(8)-widget, 0(9)-backup, (10)-preferences, (11)-arrays, (13)-newfeatures? ")
|
2011-10-30 10:58:56 +01:00
|
|
|
if selu == '12' or selu == '14':
|
2011-10-27 16:04:08 +02:00
|
|
|
print "translations of this file cannot be uploaded"
|
2011-10-26 01:44:01 +02:00
|
|
|
elif selu != 'all':
|
2011-10-24 17:06:22 +02:00
|
|
|
defaultSource = files[int(selu)-1]
|
|
|
|
sourcefile = raw_input("enter source file (default: " + defaultSource + "): ")
|
|
|
|
if sourcefile == "":
|
|
|
|
sourcefile = defaultSource
|
2011-10-27 16:09:03 +02:00
|
|
|
if language == 'all':
|
2011-10-24 17:06:22 +02:00
|
|
|
for language in alllang:
|
|
|
|
if selu == 'all':
|
|
|
|
for s in files:
|
2011-10-26 01:44:01 +02:00
|
|
|
uploadtranslation(language, s, s)
|
2011-10-24 17:06:22 +02:00
|
|
|
else:
|
2012-07-16 13:50:29 +02:00
|
|
|
uploadtranslation(language, files[int(selu)-1], sourcefile)
|
2011-10-24 17:06:22 +02:00
|
|
|
elif selu == 'all':
|
|
|
|
for s in files:
|
|
|
|
uploadtranslation(language, s, s)
|
|
|
|
else:
|
|
|
|
uploadtranslation(language, files[int(selu)-1], sourcefile)
|
|
|
|
|
|
|
|
elif sel == 'r':
|
|
|
|
# Update Translations:
|
|
|
|
print "Force translation export"
|
|
|
|
c = pycurl.Curl()
|
2014-09-16 06:36:13 +02:00
|
|
|
c.setopt(pycurl.URL, 'https://api.crowdin.com/api/project/' + PROJECT_IDENTIFIER + '/export?&key=' + CROWDIN_KEY)
|
2011-10-24 17:06:22 +02:00
|
|
|
b = StringIO.StringIO()
|
|
|
|
c.setopt(pycurl.WRITEFUNCTION, b.write)
|
|
|
|
c.perform()
|
|
|
|
c.close()
|
|
|
|
print b.getvalue()
|
|
|
|
else:
|
|
|
|
print "nothing to do"
|