[英]change language on main index.html with reactjs
I'm working on a website and i'm trying to make the site multilanguage.我在一个网站上工作,我正在努力使该网站支持多语言。 on my index.html I have two title, one in english and another in portuguese.
在我的 index.html 上,我有两个标题,一个是英语,另一个是葡萄牙语。
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title > EN </title>
<title lang = "pt-PT"> PT </title>
</head>
So in default language is english and I want to change it to portuguese if the language of the browser becomes portuguese.所以默认语言是英语,如果浏览器的语言变成葡萄牙语,我想把它改成葡萄牙语。 I already changed the browser in poruguese, but the language is still in english
我已经用葡萄牙语更改了浏览器,但语言仍然是英语
I'm still new on this and I just wanna know if theres some code or something that can help me resolve this code.我对此还是个新手,我只想知道是否有一些代码或可以帮助我解决此代码的东西。
You can use react-helmet , which helps you put content in the <head>
by using react code.您可以使用react-helmet ,它可以帮助您使用反应代码将内容放入
<head>
中。 Put this in your root component.把它放在你的根组件中。
import { Helmet } from "react-helmet"
const siteLanguage = 'pt-PT'
In your render在你的渲染中
return (
...
<Helmet htmlAttributes={{
lang: siteLanguage,
}}
><title lang={siteLanguage}>PT</title>
</ Helmet>
...
)
Portuguese language code can be 'pt', 'pt-BR' or 'pt-PT'葡萄牙语语言代码可以是“pt”、“pt-BR”或“pt-PT”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.