[Pkg-mozext-commits] [adblock-plus] 312/464: Made build.py setuptrans work for Chrome extensions
David Prévot
taffit at moszumanska.debian.org
Tue Jul 22 20:44:28 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 d48a3fe909d8947aeb81c3975a8c003286a5991d
Author: Wladimir Palant <trev at adblockplus.org>
Date: Thu Oct 18 15:33:44 2012 +0200
Made build.py setuptrans work for Chrome extensions
---
build.py | 16 +++++++---
localeTools.py | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 98 insertions(+), 17 deletions(-)
diff --git a/build.py b/build.py
index b970c8e..3603dfd 100644
--- a/build.py
+++ b/build.py
@@ -222,12 +222,18 @@ def setupTranslations(baseDir, scriptName, opts, args, type):
key = args[0]
- import buildtools.packagerGecko as packager
- locales = packager.getLocales(baseDir, True)
- basename = packager.readMetadata(baseDir).get('general', 'baseName')
+ if type == 'chrome':
+ import buildtools.packagerChrome as packager
+ locales = os.listdir(os.path.join(baseDir, '_locales'))
+ locales = map(lambda locale: locale.replace('_', '-'), locales)
+ basename = packager.readMetadata(baseDir).get('general', 'baseName')
+ else:
+ import buildtools.packagerGecko as packager
+ locales = packager.getLocales(baseDir, True)
+ basename = packager.readMetadata(baseDir).get('general', 'baseName')
import buildtools.localeTools as localeTools
- localeTools.setupTranslations(locales, basename, key)
+ localeTools.setupTranslations(type, locales, basename, key)
def updateTranslationMaster(baseDir, scriptName, opts, args, type):
@@ -391,7 +397,7 @@ 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')
+ command.supportedTypes = ('gecko', 'chrome')
with addCommand(updateTranslationMaster, 'translate') as command:
command.shortDescription = 'Updates translation master files'
diff --git a/localeTools.py b/localeTools.py
index 7378bb5..63a380c 100644
--- a/localeTools.py
+++ b/localeTools.py
@@ -10,11 +10,75 @@ from ConfigParser import SafeConfigParser
from zipfile import ZipFile
from xml.parsers.expat import ParserCreate, XML_PARAM_ENTITY_PARSING_ALWAYS
-langMapping = {
+langMappingGecko = {
'dsb': 'dsb-DE',
'hsb': 'hsb-DE',
}
+langMappingChrome = {
+ 'es-419': 'es-AR',
+ 'es': 'es-ES',
+ 'sv': 'sv-SE',
+ 'ml': 'ml-IN',
+ 'nb': 'no',
+}
+
+chromeLocales = [
+ "am",
+ "ar",
+ "bg",
+ "bn",
+ "ca",
+ "cs",
+ "da",
+ "de",
+ "el",
+ "en-GB",
+ "en-US",
+ "es-419",
+ "es",
+ "et",
+ "fa",
+ "fi",
+ "fil",
+ "fr",
+ "gu",
+ "he",
+ "hi",
+ "hr",
+ "hu",
+ "id",
+ "it",
+ "ja",
+ "kn",
+ "ko",
+ "lt",
+ "lv",
+ "ml",
+ "mr",
+ "ms",
+ "nb",
+ "nl",
+ "pl",
+ "pt-BR",
+ "pt-PT",
+ "ro",
+ "ru",
+ "sk",
+ "sl",
+ "sr",
+ "sv",
+ "sw",
+ "ta",
+ "te",
+ "th",
+ "tr",
+ "uk",
+ "vi",
+ "zh-CN",
+ "zh-TW",
+]
+
class OrderedDict(dict):
def __init__(self):
self.__order = []
@@ -162,17 +226,28 @@ def fromJSON(path, data):
file.write(generateStringEntry(key, value['message'], path))
file.close()
-def setupTranslations(locales, projectName, key):
+def setupTranslations(type, locales, projectName, key):
+ # Copy locales list, we don't want to change the parameter
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(langMapping.get(match.group(1), 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(langMapping.get(match2.group(1), match2.group(1)))
+
+ # Fill up with locales that we don't have but the browser supports
+ if type == 'chrome':
+ for locale in chromeLocales:
+ locales.add(locale)
+ else:
+ firefoxLocales = urllib2.urlopen('http://www.mozilla.org/en-US/firefox/all.html').read()
+ for match in re.finditer(r'&lang=([\w\-]+)"', firefoxLocales):
+ locales.add(langMappingGecko.get(match.group(1), 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(langMappingGecko.get(match2.group(1), match2.group(1)))
+
+ # Convert locale codes to the ones that Crowdin will understand
+ mapping = langMappingChrome if type == 'chrome' else langMappingGecko
+ locales = set(map(lambda locale: mapping[locale] if locale in mapping else locale, locales))
allowed = set()
allowedLocales = urllib2.urlopen('http://crowdin.net/page/language-codes').read()
@@ -250,7 +325,7 @@ def getTranslations(localesDir, defaultLocale, projectName, key):
if not re.match(r'^[\w\-]+$', dir) or dir == defaultLocale:
continue
- for key, value in langMapping.iteritems():
+ for key, value in langMappingGecko.iteritems():
if value == dir:
dir = 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