How to get language selected in print preview

Hi all,

I want to get selected language in print preview as the example below to use it in custom print format HTML field. How can I get it?

Code Example

{% if selected_language == "en" %}							
	{{ write something }}
{% else %}						
	{{ write something else }}
{% endif %}

Thanks

3 Likes

Hi,

could you find a solution to this? I am currently having the same problem and can’t find a way to access the selected language. As the selected language is used within the template for the translation, it must be available in this scope, right?

Okay, I was able to help myself. frappe.form_dict._lang does the trick!

6 Likes

This works. Thanks you.

One problem I found is with the PDF sent via email. Seems like the backend is not aware of this item when creating the PDF. Any ideas how to workaround that?

@jdepoix @moe01325 @Rene_Mailloux can you explain this with an example

i have tried , but it’s not worked for me

{% set lang = frappe.form_dict._lang %}
{% if lang == 'English' %}
   <label>{{_("Customer Name")}}</label>
{% else %}
   <label>{{_(Customer Arabic Name)}}</label>
{% endif %} 

i am not getting value from frappe.form_dict._lang . and getting error as below
VM4218:1 Uncaught TypeError: Cannot read property ‘_lang’ of undefined

please help?

1 Like

@abrarpv97
try this one:
{% set language = frappe[“form_dict”][‘_lang’] %}

could it be that you have to use the language code? e.g. “en”?

1 Like