def build(): worktree = open_worktree('.', soft=True) # Try using git facilities if not worktree: print "Warning: not using git." # Read configuration for languages config = get_config() source_language = config.get_value('source_language', default='en') target_languages = config.get_value('target_languages') # (1) Initialize the manifest file manifest = [ x for x in get_manifest() if not islink(x) ] manifest.append('MANIFEST') # Find out the version string if worktree: version = make_version() open('version.txt', 'w').write(version) print '* Version:', version manifest.append('version.txt') # (2) Internationalization bad_templates = [] if lfs.exists('locale'): # Build MO files print '* Compile message catalogs:', stdout.flush() for lang in (source_language,) + target_languages: print lang, stdout.flush() call([ 'msgfmt', 'locale/%s.po' % lang, '-o', 'locale/%s.mo' % lang]) # Add to the manifest manifest.append('locale/%s.mo' % lang) print # Load message catalogs message_catalogs = {} for lang in target_languages: path = 'locale/%s.po' % lang handler = ro_database.get_handler(path) message_catalogs[lang] = (handler, lfs.get_mtime(path)) # Build the templates in the target languages good_files = compile('.*\\.x.*ml.%s$' % source_language) exclude = frozenset(['.git', 'build', 'docs', 'dist']) lines = get_files(exclude, filter=lambda x: good_files.match(x)) lines = list(lines) if lines: print '* Build XHTML files', stdout.flush() for path in lines: # Load the handler src_mtime = lfs.get_mtime(path) src = ro_database.get_handler(path, XHTMLFile) done = False # Build the translation n = path.rfind('.') error = False for language in target_languages: po, po_mtime = message_catalogs[language] dst = '%s.%s' % (path[:n], language) # Add to the manifest manifest.append(dst) # Skip the file if it is already up-to-date if lfs.exists(dst): dst_mtime = lfs.get_mtime(dst) if dst_mtime > src_mtime and dst_mtime > po_mtime: continue try: data = src.translate(po) except StandardError: error = True bad_templates.append((path, exc_info())) else: open(dst, 'w').write(data) done = True # Done if error is True: stdout.write('E') elif done is True: stdout.write('*') else: stdout.write('.') stdout.flush() print # (3) Build the manifest file manifest.sort() lines = [ x + '\n' for x in manifest ] open('MANIFEST', 'w').write(''.join(lines)) print '* Build MANIFEST file (list of files to install)' # (4) Show errors if bad_templates: print print '***********************************************************' print 'The following templates could not be translated' print '***********************************************************' for (path, (type, value, traceback)) in bad_templates: print print path print_exception(type, value, traceback)
# Try using git facilities git_available = git.is_available() if not git_available: print "Warning: not using git." # Read configuration for languages config = get_config() source_language = config.get_value('source_language', default='en') target_languages = config.get_value('target_languages') # (1) Initialize the manifest file manifest = [x for x in get_manifest() if not islink(x)] manifest.append('MANIFEST') # Find out the version string if git_available: version = make_version() open('version.txt', 'w').write(version) print '* Version:', version manifest.append('version.txt') # (2) Internationalization bad_templates = [] if lfs.exists('locale'): # Build MO files print '* Compile message catalogs:', stdout.flush() for lang in (source_language, ) + target_languages: print lang, stdout.flush() call( ['msgfmt',
# Try using git facilities git_available = git.is_available() if not git_available: print "Warning: not using git." # Read configuration for languages config = get_config() source_language = config.get_value('source_language', default='en') target_languages = config.get_value('target_languages') # (1) Initialize the manifest file manifest = [ x for x in get_manifest() if not islink(x) ] manifest.append('MANIFEST') # Find out the version string if git_available: version = make_version() open('version.txt', 'w').write(version) print '* Version:', version manifest.append('version.txt') # (2) Internationalization bad_templates = [] if lfs.exists('locale'): # Build MO files print '* Compile message catalogs:', stdout.flush() for lang in (source_language,) + target_languages: print lang, stdout.flush() call([ 'msgfmt', 'locale/%s.po' % lang, '-o', 'locale/%s.mo' % lang])