更改语言环境时更改html lang属性 [英] Change html lang attribute when locale changes
本文介绍了更改语言环境时更改html lang属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在用户切换语言(=切换语言环境)时更改html lang属性。
我有一个运行PHP / Symfony2的多语言网站。 / p>
实现此目的的最佳方法是什么?
PS:我的最终目标是能够切换字体对于不同的语言(中文看起来与我选择的英文字体太糟糕了)。我正在考虑使用CSS:lang()伪选择器: html:lang(zh)
解决方法
假设您使用html5和树枝作为模板引擎:
<!doctype html>
< html lang ={{app.request.locale}}>
...
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)
解决方案
Asuming you are using html5 and twig as template engine:
<!doctype html>
<html lang="{{ app.request.locale }}">
...
这篇关于更改语言环境时更改html lang属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文