For example, I have a login page with two Labels and two Textboxes. The page is named Login.aspx, and the controls are named lbl_UserName, lbl_Password, txt_UserName, txt_Password.
First, you can create a new App_LocalResources folder on the website, and then create a new resource file named Login.aspx.resx
The name needs to be the same as the matching page name. Then create another resource file named Login.aspx.zh-Cn.resx
Login.aspx.resx is the default, and Login.aspx.zh-Cn.resx is when the browser default language is set to Chinese. when called.
Open the Login.aspx.resx file:
name value
LabelResource1.Text Username
LabelResource2.Text Password
opens the Login.aspx.zh-Cn.resx file:
LabelResource1.Text username
LabelResource2.Text Password
Then, put <asp:Label ID="lbl_UserName" runat="server"></asp:Label> in our page code
<asp:Label ID="lbl_Password" runat="server"></asp:Label>
Change to <asp:Label ID="lbl_UserName" runat="server" Text="<%$ Resources:LabelResource1.Text %>"></asp:Label>
<asp:Label ID="lbl_Password" runat="server" Text="<%$ Resources:LabelResource2.Text %>"></asp:Label>
Finally, add Culture="auto to the Page attribute of the page :zh-Cn" UICulture="auto:zh-Cn" , set to Chinese by default.
You can see the effect after compiling. When the default language of the browser is English, you can see that the two Labels are displayed as Username and Password.
When the default language of the browser is Chinese, you can see that the two Labels are displayed as user name and password.