0

How to get the English (region) - English (region) language code from Sitecore? I want to display the language code (EN for example) on some of the pages inside the <div> tag for example

<div>
  <p>The language you are using</p>
  <p>[Display language code - EN here]</p>
</div> 

I know I can just type myself the EN in the <p> tag, but I want to do it dynamically to just show this <p> tag when user is on English (region) - English (region) version of the site

2 Answers 2

2

You can use Sitecore.Context.Language to get the context language of the website.

In your case, you can use something like this:

<div>
  <p>The language you are using</p>
  <p>@Sitecore.Context.Language</p>
</div> 
1
  • Thank you for respone, but I have a question. What is this going to give me the language code or? I want EN to display on the page
    – Samke11
    Commented Mar 8, 2022 at 11:42
1

You can get the language code from the below code in a view :

Context language is: @Sitecore.Context.Language

Output :

Context language is: en

Kindly have a look at the DefaultLanguage in Sitecore.config file.

<setting name="DefaultLanguage" value="en" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.