How to use HTML lang="x" tag at the top of the code to declare the language

Ashish Narnoli asked on May 9, 2014 04:46

Hi,

I am working on Multicultural website and i need to add <HTML lang="x"> tag at the top of the code to declare the current language where "x" may be "en-gb" or "en-us" or something like that.

Any suggestions??

Best Regards! Ashish Narnoli

Recent Answers


Brenden Kehren answered on May 9, 2014 06:25

Out of the box, Kentico does this for you if you are using the Multilingual module/functionality. Documentation can be found here. You can also see a working version of this

1 votesVote for this answer Mark as a Correct answer

Ashish Narnoli answered on May 12, 2014 00:37

Hi Brenden,

Thank you so much for your quick response.

Actually <HTML lang="x"> is required for SEO purpose. Everything is working fine regarding Multilingual functionality.

I want <HTML lang="x"> on rendered code. In Masterpage template i am able to edit <!DOCTYPE html> and add <meta/> tag.

But how can i edit <HTML> tag??

Suggestions are highly appreciated.

Regards! Ashish Narnoli

0 votesVote for this answer Mark as a Correct answer

Ashish Narnoli answered on May 12, 2014 06:40

Hello Guys,

Issue Solved.

I achieved this using document.getElementsByTagName( 'html' )[0].setAttribute( 'lang', cult) and its working fine.

Regards! Ashish Narnoli

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 12, 2014 09:55

Like I mentioned, if you're using the out of the box functionality of Kentico and multi-lingual sites/module then it automatically sets the HTML tag attribute for you.

0 votesVote for this answer Mark as a Correct answer

Cody Backhaus answered on January 27, 2015 00:29

Hi Brenden,

I hate to revive an old thread, but is this something that's only available in Kentico EMS? We're using Ultimate, and I'm not seeing how I'd approach editing the html tag, aside from modifying the PortalTemplate.aspx. This approach seems incorrect if we wanted to publish documents/templates in other languages.

Thanks,
Cody Backhaus

0 votesVote for this answer Mark as a Correct answer

Sandro Jankovic answered on February 3, 2015 11:56

Hello,

The multilingual feature is also available in the ultimate license so you would be able to modify the PortalEngine template and check the culture with:

DocumentContext.CurrentDocumentCulture.CultureCode

Instead of modifying the template, you could add a jQuery script which checks the

0 votesVote for this answer Mark as a Correct answer

Henry Kwan answered on May 4, 2016 02:19

the <HTML lang="x"> is not generated when i using version 9 in multi language site, it only has this

in chinese only have this <!DOCTYPE html "> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="head"><title> sitename - 首页 </title><meta http-equiv="content-type" content="text/html; charset=UTF-8" /> and

<body class="LTR Safari Chrome Safari45 Chrome45 ZHCN ContentBody" >

in eng version <!DOCTYPE html "> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="head"><title> sitename - Home </title><meta http-equiv="content-type" content="text/html; charset=UTF-8" /> and

<body class="LTR Safari Chrome Safari45 Chrome45 ENAU ContentBody" >

how to define lang in Kentico?

0 votesVote for this answer Mark as a Correct answer

Gabriel Fuller answered on July 6, 2016 17:23

I would like to get an update on this as well. I am using "English - US" and "Spanish - Mexico" on my site. But the html tag is not generating the "lang" tag with the html tag. Is it supposed to do this automatically or do I need to set this up within my portal template?

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 18, 2016 20:12 (last edited on August 18, 2016 20:13)

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
    if (CurrentDocument != null)
    {          
        CMS.UIControls.ContentPage page= this.Page as CMS.UIControls.ContentPage;
        if (page != null)
        {
            string lang= CMS.Localization.LocalizationContext.CurrentCulture.CultureCode;
            page.XmlNamespace += " lang=\"" + lang + "\"";
            page.XmlNamespace += " xml:lang=\"" + lang + "\"";
        }
    }
}
</script>
1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.