示例#1
0
def update_language(doclist):
    """update language"""
    if webnotes.lang != 'en':
        from webnotes.translate import messages
        from webnotes.modules import get_doc_path

        # load languages for each doctype
        from webnotes.translate import get_lang_data
        _messages = {}

        for d in doclist:
            if d.doctype == 'DocType':
                _messages.update(
                    get_lang_data(get_doc_path(d.module, d.doctype, d.name),
                                  webnotes.lang, 'doc'))
                _messages.update(
                    get_lang_data(get_doc_path(d.module, d.doctype, d.name),
                                  webnotes.lang, 'js'))

        doc = doclist[0]

        # attach translations to client
        doc.fields["__messages"] = _messages

        if not webnotes.lang in messages:
            messages[webnotes.lang] = webnotes._dict({})
        messages[webnotes.lang].update(_messages)
示例#2
0
def update_language(doclist):
	"""update language"""
	if webnotes.lang != 'en':
		from webnotes.modules import get_doc_path
		if not hasattr(webnotes.local, 'translations'):
			webnotes.local.translations = {}
		translations = webnotes.local.translations

		# load languages for each doctype
		from webnotes.translate import get_lang_data
		_messages = {}

		for d in doclist:
			if d.doctype=='DocType':
				_messages.update(get_lang_data(get_doc_path(d.module, d.doctype, d.name), 
					webnotes.lang, 'doc'))
				_messages.update(get_lang_data(get_doc_path(d.module, d.doctype, d.name), 
					webnotes.lang, 'js'))

		doc = doclist[0]

		# attach translations to client
		doc.fields["__messages"] = _messages
		
		if not webnotes.lang in translations:
			translations[webnotes.lang] = webnotes._dict({})
		translations[webnotes.lang].update(_messages)
示例#3
0
def load_translations(bootinfo):
	if webnotes.lang != 'en':
		from webnotes.translate import get_lang_data
		# framework
		bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
		# doctype and module names
		bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
		bootinfo["lang"] = webnotes.lang
示例#4
0
def load_translations(bootinfo):
	webnotes.set_user_lang(webnotes.session.user)
	
	if webnotes.lang != 'en':
		from webnotes.translate import get_lang_data
		# framework
		bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
		# doctype and module names
		bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
		bootinfo["lang"] = webnotes.lang
示例#5
0
def load_translations(bootinfo):
	webnotes.set_user_lang(webnotes.session.user)
	
	if webnotes.lang != 'en':
		from webnotes.translate import get_lang_data
		from webnotes.utils import get_path
		# framework
		bootinfo["__messages"] = get_lang_data(get_path("lib","public", "js", "wn"), None, "js")
		# doctype and module names
		bootinfo["__messages"].update(get_lang_data(get_path("app","public", "js"), None, "js"))
		bootinfo["lang"] = webnotes.lang
示例#6
0
def load_translations(bootinfo):
    webnotes.set_user_lang(webnotes.session.user)

    if webnotes.lang != "en":
        from webnotes.translate import get_lang_data

        # framework
        bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
        # doctype and module names
        bootinfo["__messages"].update(get_lang_data("../app/public/js", None, "js"))
        bootinfo["lang"] = webnotes.lang
示例#7
0
文件: boot.py 项目: alvz/wnframework
def load_translations(bootinfo):
	try:
		from startup import lang_list, lang_names
	except ImportError:
		return
		
	user_lang_pref = webnotes.conn.get_value("Profile", webnotes.session.user, "language")
	if user_lang_pref and (user_lang_pref in lang_names):
		webnotes.lang = lang_names[user_lang_pref]
		webnotes.user_lang = True
		
	if webnotes.lang != 'en':
		from webnotes.translate import get_lang_data
		# framework
		bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
		# doctype and module names
		bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
		bootinfo["lang"] = webnotes.lang
示例#8
0
def get_script(report_name):
    report = webnotes.doc("Report", report_name)

    module = webnotes.conn.get_value("DocType", report.ref_doctype, "module")
    module_path = get_module_path(module)
    report_folder = os.path.join(module_path, "report", scrub(report.name))
    script_path = os.path.join(report_folder, scrub(report.name) + ".js")

    script = None
    if os.path.exists(script_path):
        with open(script_path, "r") as script:
            script = script.read()

    if not script and report.is_standard == "No":
        script = webnotes.plugins.read_file(module,
                                            "Report",
                                            report.name,
                                            extn="js",
                                            cache=True)

    if not script and report.javascript:
        script = report.javascript

    if not script:
        script = "wn.query_reports['%s']={}" % report_name

    # load translations
    if webnotes.lang != "en":
        from webnotes.translate import get_lang_data
        if os.path.exists(report_folder):
            messages = get_lang_data(report_folder, webnotes.lang, 'js')
            webnotes.response["__messages"] = messages
        else:
            # TODO check if language files get exported here
            plugins_report_folder = webnotes.plugins.get_path(
                module, "Report", report.name)
            if os.path.exists(plugins_report_folder):
                messages = get_lang_data(plugins_report_folder, webnotes.lang,
                                         'js')
                webnotes.response["__messages"] = messages

    return script
示例#9
0
def load_translations(bootinfo):
    try:
        from startup import lang_list, lang_names
    except ImportError:
        return

    user_lang_pref = webnotes.conn.get_value("Profile", webnotes.session.user,
                                             "language")
    if user_lang_pref and (user_lang_pref in lang_names):
        webnotes.lang = lang_names[user_lang_pref]
        webnotes.user_lang = True

    if webnotes.lang != 'en':
        from webnotes.translate import get_lang_data
        # framework
        bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None,
                                               "js")
        # doctype and module names
        bootinfo["__messages"].update(
            get_lang_data('../app/public/js', None, "js"))
        bootinfo["lang"] = webnotes.lang
示例#10
0
def update_language(doclist):
	"""update language"""
	if webnotes.lang != 'en':
		from webnotes import _
		from webnotes.modules import get_doc_path

		# load languages for each doctype
		from webnotes.translate import get_lang_data, update_lang_js
		_messages = {}

		for d in doclist:
			if d.doctype=='DocType':
				_messages.update(get_lang_data(get_doc_path(d.module, d.doctype, d.name), 
					webnotes.lang, 'doc'))
				_messages.update(get_lang_data(get_doc_path(d.module, d.doctype, d.name), 
					webnotes.lang, 'js'))

		doc = doclist[0]

		# attach translations to client
		doc.fields["__messages"] = _messages
示例#11
0
def get_script(report_name):
	report = webnotes.doc("Report", report_name)
	
	module = webnotes.conn.get_value("DocType", report.ref_doctype, "module")
	module_path = get_module_path(module)
	report_folder = os.path.join(module_path, "report", scrub(report.name))
	script_path = os.path.join(report_folder, scrub(report.name) + ".js")
	
	script = None
	if os.path.exists(script_path):
		with open(script_path, "r") as script:
			script = script.read()
	
	if not script and report.is_standard == "No":
		script = webnotes.plugins.read_file(module, "Report", report.name, extn="js", cache=True)

	if not script and report.javascript:
		script = report.javascript
	
	if not script:
		script = "wn.query_reports['%s']={}" % report_name
		
	# load translations
	if webnotes.lang != "en":
		from webnotes.translate import get_lang_data
		if os.path.exists(report_folder):
			messages = get_lang_data(report_folder, webnotes.lang, 'js')
			webnotes.response["__messages"] = messages
		else:
			# TODO check if language files get exported here
			plugins_report_folder = webnotes.plugins.get_path(module, "Report", report.name)
			if os.path.exists(plugins_report_folder):
				messages = get_lang_data(plugins_report_folder, webnotes.lang, 'js')
				webnotes.response["__messages"] = messages
		
	return script
示例#12
0
def update_language(doclist):
    """update language"""
    if webnotes.lang != "en":
        from webnotes.translate import messages
        from webnotes.modules import get_doc_path

        # load languages for each doctype
        from webnotes.translate import get_lang_data

        _messages = {}

        for d in doclist:
            if d.doctype == "DocType":
                _messages.update(get_lang_data(get_doc_path(d.module, d.doctype, d.name), webnotes.lang, "doc"))
                _messages.update(get_lang_data(get_doc_path(d.module, d.doctype, d.name), webnotes.lang, "js"))

        doc = doclist[0]

        # attach translations to client
        doc.fields["__messages"] = _messages

        if not webnotes.lang in messages:
            messages[webnotes.lang] = webnotes._dict({})
        messages[webnotes.lang].update(_messages)
示例#13
0
def getpage():
    """
	   Load the page from `webnotes.form` and send it via `webnotes.response`
	"""
    page = webnotes.form_dict.get("name")
    doclist = get(page)

    if has_permission(doclist):
        # load translations
        if webnotes.lang != "en":
            from webnotes.modules import get_doc_path
            from webnotes.translate import get_lang_data

            d = doclist[0]
            messages = get_lang_data(get_doc_path(d.module, d.doctype, d.name), webnotes.lang, "js")
            webnotes.response["__messages"] = messages

        webnotes.response["docs"] = doclist
    else:
        webnotes.response["403"] = 1
        raise webnotes.PermissionError, "No read permission for Page %s" % (doclist[0].title or page,)
示例#14
0
def getpage():
    """
	   Load the page from `webnotes.form` and send it via `webnotes.response`
	"""
    page = webnotes.form_dict.get('name')
    doclist = get(page)

    if has_permission(doclist):
        # load translations
        if webnotes.lang != "en":
            from webnotes.modules import get_doc_path
            from webnotes.translate import get_lang_data
            d = doclist[0]
            messages = get_lang_data(get_doc_path(d.module, d.doctype, d.name),
                                     webnotes.lang, 'js')
            webnotes.response["__messages"] = messages

        webnotes.response['docs'] = doclist
    else:
        webnotes.response['403'] = 1
        raise webnotes.PermissionError, 'No read permission for Page %s' % \
         (doclist[0].title or page, )