Search code examples
htmlsymfonyinternationalizationsymfony-2.1lang

Change html lang attribute when locale changes


I have a multilangual website running with PHP/Symfony2.

I would like to change the html lang attribute when the user switches language (= switching locale).

What is the best way to achieve this?

PS: my ultimate goal is to be able to switch font for different languages (chinese looks just too bad with the font I chose for english). I am thinking of using the CSS :lang() pseudo selector: html:lang(zh)


Solution

  • Asuming you are using html5 and twig as template engine:

    <!doctype html>
    
    <html lang="{{ app.request.locale }}">
    
    ...