Detect current language in client side

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 anni tempo fa
Since I had to change number formats to local, I wrot a javaScript function and add it to public.common.js to replace English formatted numbers with local format.

But I neead to detect current language and do the replacement in case of local language selected.

How can I detect it with java script?
If I done the mission wrong and gone to chasing the goose any recommendation appreciated.
8 anni tempo fa
Not sure if it works because i've never tried to be honest :)

You have WorkContext always available to your razor views, so you can use it to access its methods. (only accessible to your razor views, so don't put WorkContext in .js files.

Why it's accessible to only razor view?

Open Nop.Web/views/web.config you'll see the line

 <pages pageBaseType="Nop.Web.Framework.ViewEngines.Razor.WebViewPage">
so go track the WebViewPage in Nop.Web.Framework/Viewengines/razor => bingo

So say: your abc.cshtml

<script>
var langName= '@(WorkContext.WorkingLanguage.Name)'; .
</script>
8 anni tempo fa
unfortunately it didnt work.
8 anni tempo fa
<script>
var langName= '@(WorkContext.WorkingLanguage.Name)';
alert(langName); >> work for me
</script>

Could you input all your work here ?
8 anni tempo fa
It worked brother. thanks a million. I was trying to use it in a non razor view!
4 anni tempo fa
It worked for me too. Thanks!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.