def get_user_lang(user=None):
	if not user:
		user = frappe.session.user

	# via cache
	lang = frappe.cache().hget("lang", user)

	if not lang:

		# if defined in user profile
		user_lang = frappe.db.get_value("User", user, "language")
		if user_lang and user_lang!="Loading...":
			lang = get_lang_code(user_lang)
		else:
			default_lang = frappe.db.get_default("lang")
			lang = get_lang_code(default_lang)

		if not lang:
			lang = frappe.local.lang or 'en'

		frappe.cache().hset("lang", user, lang)

	return lang
Set frappe.local.lang from user preferences on session beginning or resumption
dataset/ETHPy150Open frappe/frappe/frappe/translate.py/get_user_lang