def main(): languages = sorted([ s.split(os.path.sep)[-2] for s in glob.glob("license_xsl/i18n/i18n_po/*/cc_org.po") ]) # noqa: E501 translate_all_of_me = findall(open("template.html").read()) translate_all_of_me.update(findall(open("js/cc-license.js").read())) translate_all_of_me = list(translate_all_of_me) # Plus, translate all the jurisdiction names translate_all_of_me.append("Unported") translate_all_of_me.extend([ convert.country_id2name(k, "en") for k in gen_template_js.grab_license_ids() ]) # noqa: E501 print "This is what we will translate:", translate_all_of_me for lang in languages: translation_table = dict() for english in translate_all_of_me: translation_table[ english] = convert.extremely_slow_translation_function( english, lang) fn_body = translation_table_to_js_function_body(translation_table) fn = "function cc_js_t(s) {\n{}\n}".format(fn_body) fd = open("cc-translations.js.{}".format(lang), "w") fd.write(fn.encode("utf-8")) fd.close() # Whew. Generated some JS files. Now should also make some .var # file for those who can't use these. gen_template_js.create_var_file(my_variants=None, languages=languages, base_filename="cc-translations.js")
def gen_templated_js(language, my_variants): jurisdiction_names = grab_license_ids() jurisdictions = [] # First, handle generic generic_value = 'generic' generic_element_id = 'cc_js_jurisdiction_choice_' + generic_value generic_name = convert.extremely_slow_translation_function('Unported', language) jurisdictions.append(dict(id=generic_element_id, value=generic_value, name=generic_name)) # Now jam everyone else in, too. for juri in jurisdiction_names: value = juri element_id = 'cc_js_jurisdiction_choice_' + value name = convert.country_id2name(value, language) jurisdictions.append(dict(id=element_id, value=value, name=name)) expanded = expand_template_with_jurisdictions('template.html', jurisdictions) expanded_dom = parseString(expanded) # translate the spans, then pull out the changed text translate_spans_with_only_text_children(expanded_dom.getElementsByTagName('span'), language) apply_variants(my_variants, expanded_dom) my_string = expanded_dom.toxml(encoding='utf-8') if my_variants: my_suffix = '.'.join(my_variants) my_filename_base = 'template.' + my_suffix + '.js' else: my_filename_base = 'template.js' my_filename = (my_filename_base + '.%s') % language write_string_to(jsify(my_string), my_filename)
def main(): languages = sorted([ s.split(os.path.sep)[-2] for s in glob.glob('license_xsl/i18n/i18n_po/*/cc_org.po')]) translate_all_of_me = findall(open('template.html').read()) translate_all_of_me.update(findall(open('js/cc-license.js').read())) translate_all_of_me = list(translate_all_of_me) # Plus, translate all the jurisdiction names translate_all_of_me.append('Unported') translate_all_of_me.extend([convert.country_id2name(k, 'en') for k in gen_template_js.grab_license_ids()]) print 'This is what we will translate:', translate_all_of_me for lang in languages: translation_table = {} for english in translate_all_of_me: translation_table[english] = convert.extremely_slow_translation_function(english, lang) fn_body = translation_table_to_js_function_body(translation_table) fn = '''function cc_js_t(s) { %s }''' % fn_body fd = open('cc-translations.js.%s' % lang, 'w') fd.write(fn.encode('utf-8')) fd.close() # Whew. Generated some JS files. Now should also make some .var # file for those who can't use these. gen_template_js.create_var_file(my_variants = None, languages=languages, base_filename='cc-translations.js')
def gen_templated_js(language): jurisdiction_names = grab_license_ids() jurisdictions = [] # First, handle generic generic_value = 'generic' generic_element_id = 'cc_js_jurisdiction_choice_' + generic_value generic_name = convert.extremely_slow_translation_function('Unported', language) jurisdictions.append(dict(id=generic_element_id, value=generic_value, name=generic_name)) # Now jam everyone else in, too. for juri in jurisdiction_names: value = juri element_id = 'cc_js_jurisdiction_choice_' + value name = convert.country_id2name(value, language) jurisdictions.append(dict(id=element_id, value=value, name=name)) from xml.dom.minidom import parse, parseString expanded = expand_template_with_jurisdictions('template.html', jurisdictions) expanded_dom = parseString(expanded) # translate the spans, then pull out the changed text translate_spans_with_only_text_children(expanded_dom.getElementsByTagName('span'), language) translated_expanded = expanded_dom.toxml(encoding='utf-8') out = open('template.%s.js.tmp' % language, 'w') for line in translated_expanded.split('\n'): escaped_line = escape_single_quote(line.strip()) print >> out, "document.write('%s');" % escaped_line out.close() os.rename('template.%s.js.tmp' % language, 'template.js.%s' % language)
def gen_jurisdiction_info(): soup = BeautifulSoup.BeautifulStoneSoup(open('license_xsl/licenses.xml')) result = {} for j_i in soup('jurisdiction-info'): this_one = {} this_ones_id = str(j_i['id']) if this_ones_id: if j_i['launched'] != 'true': continue # next jurisdiction if this one isn't ready #this_one['url'] = get_contents(j_i, 'uri') available_versions = license_versions_for_jurisdiction(license_type='standard', soup=soup, in_juri=this_ones_id) sampling_versions = license_versions_for_jurisdiction(license_type='sampling', soup=soup, in_juri=this_ones_id) if available_versions: this_one['version'] = str(max(available_versions.values())) if sampling_versions: this_one['sampling'] = str(max(sampling_versions.values())) if this_ones_id == '-': this_ones_id = 'generic' this_one['generic'] = True if this_ones_id == 'generic': name = 'Unported' else: name = convert.country_id2name(country_id=this_ones_id, language='en_US').encode("ascii") this_one['name'] = name result[this_ones_id] = this_one ret = json.write(result) # Validate JSON generation assert (json.read(ret) == result) # this includes a type check return ret
def gen_templated_js(language, my_variants): jurisdiction_names = grab_license_ids() jurisdictions = list() # First, handle generic generic_value = "generic" generic_element_id = "cc_js_jurisdiction_choice_{}".format(generic_value) generic_name = convert.extremely_slow_translation_function( "Unported", language) jurisdictions.append( dict(id=generic_element_id, value=generic_value, name=generic_name)) # Now jam everyone else in, too. for juri in jurisdiction_names: value = juri element_id = "cc_js_jurisdiction_choice_{}".format(value) name = convert.country_id2name(value, language) jurisdictions.append(dict(id=element_id, value=value, name=name)) expanded = expand_template_with_jurisdictions("template.html", jurisdictions) expanded_dom = ElementTree.fromstring(expanded) # translate the spans, then pull out the changed text translate_spans_with_only_text_children(expanded_dom.findall("span"), language) apply_variants(my_variants, expanded_dom) my_string = ElementTree.tostring(expanded_dom, encoding="utf-8", method="xml") if my_variants: my_suffix = ".".join(my_variants) my_filename_base = "template.{}.js".format(my_suffix) else: my_filename_base = "template.js" my_filename = ("{}.{}".format(my_filename_base, language)) write_string_to(jsify(my_string), my_filename)
def main(): languages = [ k for k in os.listdir('license_xsl/i18n/i18n_po/') if '.po' in k ] languages = [re.split(r'[-.]', k)[1] for k in languages] translate_all_of_me = list(findall(open('template.html').read())) print translate_all_of_me # Plus, translate all the jurisdiction names translate_all_of_me.append('Unported') translate_all_of_me.extend([ convert.country_id2name(k, 'en') for k in gen_template_js.grab_license_ids() ]) for lang in languages: translation_table = {} for english in translate_all_of_me: translation_table[ english] = convert.extremely_slow_translation_function( english, lang) fn_body = translation_table_to_js_function_body(translation_table) fn = '''function cc_js_t(s) { %s }''' % fn_body fd = open('cc-translations.js.%s' % lang, 'w') fd.write(fn.encode('utf-8')) fd.close() # Whew. Generated some JS files. Now should also make some .var # file for those who can't use these. gen_template_js.create_var_file(my_variants=None, languages=languages, base_filename='cc-translations.js')
def gen_jurisdiction_info(): soup = BeautifulSoup.BeautifulStoneSoup(open('license_xsl/licenses.xml')) result = {} for j_i in soup('jurisdiction-info'): this_one = {} this_ones_id = str(j_i['id']) if this_ones_id: if j_i['launched'] != 'true': continue # next jurisdiction if this one isn't ready #this_one['url'] = get_contents(j_i, 'uri') available_versions = license_versions_for_jurisdiction( license_type='standard', soup=soup, in_juri=this_ones_id) sampling_versions = license_versions_for_jurisdiction( license_type='sampling', soup=soup, in_juri=this_ones_id) if available_versions: this_one['version'] = str(max(available_versions.values())) if sampling_versions: this_one['sampling'] = str(max(sampling_versions.values())) if this_ones_id == '-': this_ones_id = 'generic' this_one['generic'] = True if this_ones_id == 'generic': name = 'Unported' else: name = convert.country_id2name( country_id=this_ones_id, language='en_US').encode("ascii") this_one['name'] = name result[this_ones_id] = this_one ret = json.write(result) # Validate JSON generation assert (json.read(ret) == result) # this includes a type check return ret
def main(): languages = [k for k in os.listdir('license_xsl/i18n/i18n_po/') if '.po' in k] languages = [re.split(r'[-.]', k)[1] for k in languages] translate_all_of_me = list(findall(open('template.html').read())) print translate_all_of_me # Plus, translate all the jurisdiction names translate_all_of_me.append('Unported') translate_all_of_me.extend([convert.country_id2name(k, 'en') for k in gen_template_js.grab_license_ids()]) for lang in languages: translation_table = {} for english in translate_all_of_me: translation_table[english] = convert.extremely_slow_translation_function(english, lang) fn_body = translation_table_to_js_function_body(translation_table) fn = '''function cc_js_t(s) { %s }''' % fn_body fd = open('cc-translations.js.%s' % lang, 'w') fd.write(fn.encode('utf-8')) fd.close() # Whew. Generated some JS files. Now should also make some .var # file for those who can't use these. gen_template_js.create_var_file(my_variants = None, languages=languages, base_filename='cc-translations.js')
def gen_jurisdiction_info(): soup = BeautifulSoup.BeautifulStoneSoup(open("license_xsl/licenses.xml")) result = dict() for j_i in soup("jurisdiction-info"): this_one = dict() this_ones_id = str(j_i["id"]) if this_ones_id: if j_i["launched"] != "true": continue # next jurisdiction if this one isn"t ready # this_one["url"] = get_contents(j_i, "uri") available_versions = license_versions_for_jurisdiction( license_type="standard", soup=soup, in_juri=this_ones_id) sampling_versions = license_versions_for_jurisdiction( license_type="sampling", soup=soup, in_juri=this_ones_id) if available_versions: this_one["version"] = str(max(available_versions.values())) if sampling_versions: this_one["sampling"] = str(max(sampling_versions.values())) if this_ones_id == "-": this_ones_id = "generic" this_one["generic"] = True if this_ones_id == "generic": name = "Unported" else: name = convert.country_id2name(country_id=this_ones_id, language="en_US").encode("ascii") # noqa: E501 this_one["name"] = name result[this_ones_id] = this_one ret = json.dumps(result) # Validate JSON generation assert (json.loads(ret) == result) # this includes a type check return ret
def main(): languages = sorted([ s.split(os.path.sep)[-2] for s in glob.glob('license_xsl/i18n/i18n_po/*/cc_org.po') ]) translate_all_of_me = findall(open('template.html').read()) translate_all_of_me.update(findall(open('js/cc-license.js').read())) translate_all_of_me = list(translate_all_of_me) # Plus, translate all the jurisdiction names translate_all_of_me.append('Unported') translate_all_of_me.extend([ convert.country_id2name(k, 'en') for k in gen_template_js.grab_license_ids() ]) print 'This is what we will translate:', translate_all_of_me for lang in languages: translation_table = {} for english in translate_all_of_me: translation_table[ english] = convert.extremely_slow_translation_function( english, lang) fn_body = translation_table_to_js_function_body(translation_table) fn = '''function cc_js_t(s) { %s }''' % fn_body fd = open('cc-translations.js.%s' % lang, 'w') fd.write(fn.encode('utf-8')) fd.close() # Whew. Generated some JS files. Now should also make some .var # file for those who can't use these. gen_template_js.create_var_file(my_variants=None, languages=languages, base_filename='cc-translations.js')
def nice_juri2name(s): if not s: return 'Unported' return convert.country_id2name(s, 'en_US')