translations = result_obj if translations is None or literals is None: logger.error("Failed to parse strings from " + LINT) raise Exception translations = frozenset(translations) untranslated = set(literals) - translations all_translations.update(translations) all_untranslated.update(untranslated) # For each translation, keep track of all the files it was found in for src in translations: locations.setdefault(src, []).append(filename) else: logger.error("%s returned %d" % (LINT, p.returncode)) returncode = p.returncode finally: if fd: os.close(fd) localization.save_to_file(TRANSLATIONS_FILENAME, all_translations, locations) # Finally, write all the untranslated strings to a text file, for sanity checking with open(UNTRANSLATED_FILENAME, 'w+') as filep: for each in all_untranslated: filep.write(each + "\n") sys.exit(returncode)
out_filename = script_relative(template_path.replace(".tmpl", "")) logger.info("Writing " + out_filename) with open(out_filename, 'w') as f: f.write(template_str) else: logger.warning(template_path + " doesn't contain '.tmpl' -- ignoring.") # Set up the Jinja environment loader = RelativeFileSystemLoader(SCRIPT_DIR) translations = DynamicTranslations() env = Environment(loader=loader, extensions=["jinja2.ext.i18n"]) env.install_gettext_translations(translations) for each in HTML_SOURCES: translations.set_source(each) template = env.get_template(each) # Find the path to the common JS dir from this template's dir # We want this path to always use slash as a separator, not backslash jsDir = os.path.relpath(COMMON_JS_PATH, os.path.dirname(each)) jsDir = jsDir.replace(os.path.sep, "/") result = template.render(nls_class=NLS_CLASS, common_js_dir=jsDir) save_as_html(each, result) # Write all the translations to a file in JSON format localization.save_to_file(TRANSLATIONS_FILENAME, sources, locations)