1

It might sound simple question as I am new into Sitecore. I need to add two characters of language code into html tag for site web accessibility.

Working with Sitecore 9.3

Thanks in advance.

1
  • Welcome to SSE. Commented Mar 16, 2023 at 7:26

2 Answers 2

3

You need to add it to the layout file like.

<html lang="@Sitecore.Context.Language.CultureInfo.TwoLetterISOLanguageName">

Refer: https://github.com/Sitecore/Habitat/blob/master/src/Project/Habitat/code/Views/Website/Layouts/Default.cshtml

0

You can use the Sitecore context for this. The context is an object that contains information about the user, culture, language settings, and database settings.

So here is the different kind of language name that you can use like this. For example, if the language is da-DK then you get the following using these properties.

Sitecore.Context.Language.CultureInfo.Name => 'da-DK' 
Sitecore.Context.Language.CultureInfo.TwoLetterISOLanguageName => 'da'
Sitecore.Context.Language.CultureInfo.ThreeLetterISOLanguageName => 'dan'

So in your case, you can use Sitecore.Context.Language.CultureInfo.TwoLetterISOLanguageName

Hope this help.

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.