Exemplo n.º 1
0
def update_translations_for_source(source=None, translation_dict=None):
	if not (source and translation_dict):
		return

	translation_dict = json.loads(translation_dict)

	if is_html(source):
		source = strip_html_tags(source)

	# for existing records
	translation_records = frappe.db.get_values('Translation', {
		'source_text': source
	}, ['name', 'language'],  as_dict=1)
	for d in translation_records:
		if translation_dict.get(d.language, None):
			doc = frappe.get_doc('Translation', d.name)
			doc.translated_text = translation_dict.get(d.language)
			doc.save()
			# done with this lang value
			translation_dict.pop(d.language)
		else:
			frappe.delete_doc('Translation', d.name)

	# remaining values are to be inserted
	for lang, translated_text in translation_dict.items():
		doc = frappe.new_doc('Translation')
		doc.language = lang
		doc.source_text = source
		doc.translated_text = translated_text
		doc.save()

	return translation_records
Exemplo n.º 2
0
def get_translations(source_name):
    if is_html(source_name):
        source_name = strip_html_tags(source_name)

    return frappe.db.get_list(
        'Translation',
        fields=['name', 'language', 'target_name as translation'],
        filters={'source_name': source_name})
Exemplo n.º 3
0
def get_translations(source_text):
    if is_html(source_text):
        source_text = strip_html_tags(source_text)

    return frappe.db.get_list(
        'Translation',
        fields=['name', 'language', 'translated_text as translation'],
        filters={'source_text': source_text})
Exemplo n.º 4
0
def get_translations(source_text):
    if is_html(source_text):
        source_text = strip_html_tags(source_text)

    return frappe.db.get_list(
        "Translation",
        fields=["name", "language", "translated_text as translation"],
        filters={"source_text": source_text},
    )
Exemplo n.º 5
0
def get_translations(source_name):
	if is_html(source_name):
		source_name = strip_html_tags(source_name)

	return frappe.db.get_list('Translation',
		fields = ['name', 'language', 'target_name as translation'],
		filters = {
			'source_name': source_name
		}
	)
Exemplo n.º 6
0
    def load_standard_properties(self, context):
        '''load templates and run get_context'''
        module = get_doc_module(self.module, self.doctype, self.name)
        if module:
            if hasattr(module, 'get_context'):
                out = module.get_context(context)
                if out: context.update(out)

        self.message = self.get_template()

        if not is_html(self.message):
            self.message = frappe.utils.md_to_html(self.message)
Exemplo n.º 7
0
	def load_standard_properties(self, context):
		'''load templates and run get_context'''
		module = get_doc_module(self.module, self.doctype, self.name)
		if module:
			if hasattr(module, 'get_context'):
				out = module.get_context(context)
				if out: context.update(out)

		self.message = self.get_template()

		if not is_html(self.message):
			self.message = markdown(self.message)
Exemplo n.º 8
0
def _(msg, lang=None):
	"""Returns translated string in current lang, if exists."""
	from frappe.translate import get_full_dict
	from frappe.utils import strip_html_tags, is_html

	if not hasattr(local, 'lang'):
		local.lang = lang or 'en'

	if not lang:
		lang = local.lang

	non_translated_msg = msg

	if is_html(msg):
		msg = strip_html_tags(msg)

	# msg should always be unicode
	msg = as_unicode(msg).strip()

	# return lang_full_dict according to lang passed parameter
	return get_full_dict(lang).get(msg) or non_translated_msg
Exemplo n.º 9
0
def _(msg, lang=None):
	"""Returns translated string in current lang, if exists."""
	from frappe.translate import get_full_dict
	from frappe.utils import strip_html_tags, is_html

	if not hasattr(local, 'lang'):
		local.lang = lang or 'en'

	if not lang:
		lang = local.lang

	non_translated_msg = msg

	if is_html(msg):
		msg = strip_html_tags(msg)

	# msg should always be unicode
	msg = as_unicode(msg).strip()

	# return lang_full_dict according to lang passed parameter
	return get_full_dict(lang).get(msg) or non_translated_msg
Exemplo n.º 10
0
 def validate(self):
     if is_html(self.source_text):
         self.remove_html_from_source()
Exemplo n.º 11
0
	def validate(self):
		if is_html(self.source_name):
			self.remove_html_from_source()