[Pkg-mozext-commits] [adblock-plus] 265/464: Added command to set up translation languages on crowdin.net
David Prévot
taffit at moszumanska.debian.org
Tue Jul 22 20:44:23 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit f7f1c18802f2e7c7188463adc6a038f4e8c3bd70
Author: Wladimir Palant <trev at adblockplus.org>
Date: Thu Jul 5 11:58:00 2012 +0200
Added command to set up translation languages on crowdin.net
---
build.py | 24 +++++++++++++++++++++++-
localeTools.py | 21 ++++++++++++++++++++-
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/build.py b/build.py
index 98075a1..4b02831 100644
--- a/build.py
+++ b/build.py
@@ -192,6 +192,22 @@ def runAutoInstall(baseDir, scriptName, opts, args, type):
packager.autoInstall(baseDir, host, port, multicompartment=multicompartment)
+def setupTranslations(baseDir, scriptName, opts, args, type):
+ if len(args) < 1:
+ print 'Project key is required to update translation master files.'
+ usage(scriptName, type, 'setuptrans')
+ return
+
+ key = args[0]
+
+ import buildtools.packager as packager
+ locales = packager.getLocales(baseDir, True)
+ basename = packager.readMetadata(baseDir).get('general', 'baseName')
+
+ import buildtools.localeTools as localeTools
+ localeTools.setupTranslations(locales, basename, key)
+
+
def updateTranslationMaster(baseDir, scriptName, opts, args, type):
if len(args) < 1:
print 'Project key is required to update translation master files.'
@@ -318,9 +334,15 @@ with addCommand(runAutoInstall, 'autoinstall') as command:
command.addOption('Create a build for leak testing', short='m', long='multi-compartment')
command.supportedTypes = ('gecko')
+with addCommand(setupTranslations, 'setuptrans') as command:
+ command.shortDescription = 'Sets up translation languages'
+ command.description = 'Sets up translation languages for the project on crowdin.net.'
+ command.params = '[options] project-key'
+ command.supportedTypes = ('gecko')
+
with addCommand(updateTranslationMaster, 'translate') as command:
command.shortDescription = 'Updates translation master files'
- command.description = 'Updates the translation master files on crowdin.net.'
+ command.description = 'Updates the translation master files in the project on crowdin.net.'
command.params = '[options] project-key'
command.supportedTypes = ('gecko')
diff --git a/localeTools.py b/localeTools.py
index 95dd495..6b1d98e 100644
--- a/localeTools.py
+++ b/localeTools.py
@@ -4,7 +4,7 @@
# version 2.0 (the "License"). You can obtain a copy of the License at
# http://mozilla.org/MPL/2.0/.
-import re, os, sys, codecs, json, urllib2
+import re, os, sys, codecs, json, urllib, urllib2
from StringIO import StringIO
from ConfigParser import SafeConfigParser
from xml.parsers.expat import ParserCreate, XML_PARAM_ENTITY_PARSING_ALWAYS
@@ -141,6 +141,25 @@ def toJSON(path):
result[name] = obj
return json.dumps(result, indent=2)
+def setupTranslations(locales, projectName, key):
+ locales = set(locales)
+ firefoxLocales = urllib2.urlopen('http://www.mozilla.org/en-US/firefox/all.html').read()
+ for match in re.finditer(r'&lang=([\w\-]+)"', firefoxLocales):
+ locales.add(match.group(1))
+ langPacks = urllib2.urlopen('https://addons.mozilla.org/en-US/firefox/language-tools/').read()
+ for match in re.finditer(r'<tr>.*?</tr>', langPacks, re.S):
+ if match.group(0).find('Install Language Pack') >= 0:
+ match2 = re.search(r'lang="([\w\-]+)"', match.group(0))
+ if match2:
+ locales.add(match2.group(1))
+
+ locales = list(locales)
+ locales.sort()
+ params = urllib.urlencode([('languages[]', locale) for locale in locales])
+ result = urllib2.urlopen('http://api.crowdin.net/api/project/%s/edit-project?key=%s&%s' % (projectName, key, params)).read()
+ if result.find('<success') < 0:
+ raise Exception('Server indicated that the operation was not successful\n' + result)
+
def updateTranslationMaster(dir, locale, projectName, key):
result = json.load(urllib2.urlopen('http://api.crowdin.net/api/project/%s/info?key=%s&json=1' % (projectName, key)))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list