Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: build.py

Issue 29336281: Issue 2109 - Allow for translation of app independent repositories (Closed)
Patch Set: Addressed Sebastian's feedback and removed unrelated changes Created Feb. 12, 2016, 5:26 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | localeTools.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build.py
diff --git a/build.py b/build.py
index 518577d88904aee6ff9c1502aab400809f54cad1..eb9dd059aa6c98ac5dbfecc628b3becd2c70b7f1 100644
--- a/build.py
+++ b/build.py
@@ -9,7 +9,7 @@ from getopt import getopt, GetoptError
from StringIO import StringIO
from zipfile import ZipFile
-knownTypes = ('gecko', 'chrome', 'opera', 'safari')
+knownTypes = ('gecko', 'chrome', 'opera', 'safari', 'generic')
class Command(object):
name = property(lambda self: self._name)
@@ -236,6 +236,45 @@ def createDevEnv(baseDir, scriptName, opts, args, type):
zip_file.extractall(devenv_dir)
+def readLocaleConfig(baseDir, type, metadata, includeIncomplete=False):
+ if type == 'gecko':
+ import buildtools.packagerGecko as packager
+ basePath = packager.getLocalesDir(baseDir)
+ return {
+ 'base_path': basePath,
+ 'name_format': 'BCP-47',
+ 'file_format': 'gecko-dtd',
+ 'target_platforms': {'gecko'},
+ 'default_locale': packager.defaultLocale,
+ 'locales': {locale: os.path.join(basePath, locale)
+ for locale in packager.getLocales(baseDir, includeIncomplete)}
+ }
+
+ if type == 'chrome' or type == 'opera':
+ import buildtools.packagerChrome as packager
+ localeDir = '_locales'
+ localeConfig = {
+ 'name_format': 'ISO-15897',
+ 'file_format': 'chrome-json',
+ 'target_platforms': {'chrome'},
+ 'default_locale': packager.defaultLocale,
+ }
+ else:
+ localeDir = metadata.get('locales', 'base_path')
+ localeConfig = {
+ 'name_format': metadata.get('locales', 'name_format'),
+ 'file_format': metadata.get('locales', 'file_format'),
+ 'target_platforms': set(metadata.get('locales',
+ 'target_platforms').split()),
+ 'default_locale': metadata.get('locales', 'default_locale')
+ }
+
+ localeConfig['base_path'] = fullBasePath = os.path.join(baseDir, localeDir)
+ localeConfig['locales'] = {locale.replace('_', '-'):
+ os.path.join(fullBasePath, locale)
+ for locale in os.listdir(fullBasePath)}
+ return localeConfig
+
def setupTranslations(baseDir, scriptName, opts, args, type):
if len(args) < 1:
print 'Project key is required to update translation master files.'
@@ -246,18 +285,12 @@ def setupTranslations(baseDir, scriptName, opts, args, type):
from buildtools.packager import readMetadata
metadata = readMetadata(baseDir, type)
- basename = metadata.get('general', 'basename')
- if type == 'chrome' or type == 'opera':
- import buildtools.packagerChrome as packager
- locales = os.listdir(os.path.join(baseDir, '_locales'))
- locales = map(lambda locale: locale.replace('_', '-'), locales)
- else:
- import buildtools.packagerGecko as packager
- locales = packager.getLocales(baseDir, True)
+ basename = metadata.get('general', 'basename')
+ localeConfig = readLocaleConfig(baseDir, type, metadata, True)
import buildtools.localeTools as localeTools
- localeTools.setupTranslations(type, locales, basename, key)
+ localeTools.setupTranslations(basename, localeConfig, key)
def updateTranslationMaster(baseDir, scriptName, opts, args, type):
@@ -270,17 +303,16 @@ def updateTranslationMaster(baseDir, scriptName, opts, args, type):
from buildtools.packager import readMetadata
metadata = readMetadata(baseDir, type)
+
basename = metadata.get('general', 'basename')
+ localeConfig = readLocaleConfig(baseDir, type, metadata)
- if type == 'chrome' or type == 'opera':
- import buildtools.packagerChrome as packager
- defaultLocaleDir = os.path.join(baseDir, '_locales', packager.defaultLocale)
- else:
- import buildtools.packagerGecko as packager
- defaultLocaleDir = os.path.join(packager.getLocalesDir(baseDir), packager.defaultLocale)
+ defaultLocaleDir = os.path.join(localeConfig['base_path'],
+ localeConfig['default_locale'])
import buildtools.localeTools as localeTools
- localeTools.updateTranslationMaster(type, metadata, defaultLocaleDir, basename, key)
+ localeTools.updateTranslationMaster(metadata, defaultLocaleDir, basename,
+ localeConfig, key)
def uploadTranslations(baseDir, scriptName, opts, args, type):
@@ -293,23 +325,15 @@ def uploadTranslations(baseDir, scriptName, opts, args, type):
from buildtools.packager import readMetadata
metadata = readMetadata(baseDir, type)
- basename = metadata.get('general', 'basename')
- if type == 'chrome' or type == 'opera':
- import buildtools.packagerChrome as packager
- localesDir = os.path.join(baseDir, '_locales')
- locales = os.listdir(localesDir)
- locales = map(lambda locale: (locale.replace('_', '-'), os.path.join(localesDir, locale)), locales)
- else:
- import buildtools.packagerGecko as packager
- localesDir = packager.getLocalesDir(baseDir)
- locales = packager.getLocales(baseDir, True)
- locales = map(lambda locale: (locale, os.path.join(localesDir, locale)), locales)
+ basename = metadata.get('general', 'basename')
+ localeConfig = readLocaleConfig(baseDir, type, metadata, True)
import buildtools.localeTools as localeTools
- for locale, localeDir in locales:
- if locale != packager.defaultLocale:
- localeTools.uploadTranslations(type, metadata, localeDir, locale, basename, key)
+ for locale, localeDir in localeConfig['locales'].iteritems():
+ if locale != localeConfig['default_locale']:
+ localeTools.uploadTranslations(metadata, localeDir, locale, basename,
+ localeConfig, key)
def getTranslations(baseDir, scriptName, opts, args, type):
@@ -318,20 +342,16 @@ def getTranslations(baseDir, scriptName, opts, args, type):
usage(scriptName, type, 'translate')
return
+ key = args[0]
+
from buildtools.packager import readMetadata
metadata = readMetadata(baseDir, type)
- basename = metadata.get('general', 'basename')
- key = args[0]
- if type == 'chrome' or type == 'opera':
- import buildtools.packagerChrome as packager
- localesDir = os.path.join(baseDir, '_locales')
- else:
- import buildtools.packagerGecko as packager
- localesDir = packager.getLocalesDir(baseDir)
+ basename = metadata.get('general', 'basename')
+ localeConfig = readLocaleConfig(baseDir, type, metadata)
import buildtools.localeTools as localeTools
- localeTools.getTranslations(type, localesDir, packager.defaultLocale.replace('_', '-'), basename, key)
+ localeTools.getTranslations(localeConfig, basename, key)
def showDescriptions(baseDir, scriptName, opts, args, type):
@@ -459,25 +479,25 @@ 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', 'chrome', 'opera')
+ command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic')
with addCommand(updateTranslationMaster, 'translate') as command:
command.shortDescription = 'Updates translation master files'
command.description = 'Updates the translation master files in the project on crowdin.net.'
command.params = '[options] project-key'
- command.supportedTypes = ('gecko', 'chrome', 'opera')
+ command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic')
with addCommand(uploadTranslations, 'uploadtrans') as command:
command.shortDescription = 'Uploads existing translations'
command.description = 'Uploads already existing translations to the project on crowdin.net.'
command.params = '[options] project-key'
- command.supportedTypes = ('gecko', 'chrome', 'opera')
+ command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic')
with addCommand(getTranslations, 'gettranslations') as command:
command.shortDescription = 'Downloads translation updates'
command.description = 'Downloads updated translations from crowdin.net.'
command.params = '[options] project-key'
- command.supportedTypes = ('gecko', 'chrome', 'opera')
+ command.supportedTypes = ('gecko', 'chrome', 'opera', 'generic')
with addCommand(showDescriptions, 'showdesc') as command:
command.shortDescription = 'Print description strings for all locales'
« no previous file with comments | « no previous file | localeTools.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld