Пример #1
0
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)
Пример #2
0
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')
Пример #3
0
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)
Пример #4
0
def translate_spans_with_only_text_children(spans, lang):
	for span in spans:
		if len(span.childNodes) == 1:
			child = span.childNodes[0]
			if child.nodeType == 3: # FIXME: Magic number
						# maybe means Text
						# node?
				# First, decode any &#; thing
				xml_data = child.data
				unicode_data = un_entities(xml_data)
				utf8_data = unicode_data.encode('utf-8')
				child.data = convert.extremely_slow_translation_function(utf8_data, lang)
Пример #5
0
def translate_spans_with_only_text_children(spans, lang):
	for span in spans:
		if len(span.childNodes) == 1:
			child = span.childNodes[0]
			if child.nodeType == 3: # FIXME: Magic number
						# maybe means Text
						# node?
				# First, decode any &#; thing
				xml_data = child.data
				unicode_data = un_entities(xml_data)
				utf8_data = unicode_data.encode('utf-8')
				child.data = convert.extremely_slow_translation_function(utf8_data, lang)
Пример #6
0
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')
Пример #7
0
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')