In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
ThinkPhp how to achieve multilingual, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
1. Multilingual implementation in the background
Using the frame is v5.1.38 LTS
When you go to the configuration file config/app.php, you can see that there are only two parameters for the configuration information about the language.
The parameter lang_switch_on is the browser language for automatic listening.
Default_lang about this parameter is to directly default the Chinese configuration file before switching to other languages. After knowing that, we need to create a lang directory in the required module and configure the language pack for the corresponding language.
Here Kaka is only configured in English and Chinese. if you need other languages, you can add it yourself. At this point you will find that there is no parameter from beginning to end that is the parameter of the configuration language list. The configuration file was not found either.
But you can see this line of code in the document. Let's take a look at the source code.
You can see clearly in the source code that the name value of the cookie of the language is also fixed, and the validity period of cookie is 3600, which need to be adjusted according to your own project.
The most important thing is to look at the list of allowed languages. As we continue to trace this variable, at the end of the file thinkphp/library/think/Lang.php, we can see a method, which is also a method given in the document, because we need to use multiple languages in the whole background, so we need to configure it in common.
II. View switching language
Call the languageChange method directly in the view template. In the view, there is a variable $languageName, which is taken directly from the configuration file by Kaka and will be adjusted to the database later.
Then write the method changeLanguage in the controller, which is used to handle the cookie change after the language switch. At this time, our background page looks like this.
III. Testing
After the above operation, we can switch the language according to the language pack we set up.
In the template, we need to use the lang template tag to obtain the data, this is the English status, this is the Chinese status, and then the multilingual implementation is complete.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.