Using PHP's web framework thinkphp6 to develop multilingual website system tutorial (I), php interface

1 year ago (2024-01-13) Chief Editor
3 minutes
two hundred and thirty-five
zero

In fact, thinkphp6 comes with a multi language logic, but it is too simple to meet the customer's needs in practical application. We need to upgrade on this basis to meet the real market demand.

1、 Implementation of multilingual logic for file variables:

Under the application directory APP, create a new folder lang to place multilingual language packs. Each language corresponds to a language pack file, and each language pack file returns an array of languages, as shown in Figure

Multi language pack

Then, where you need to use the language pack, you can load the corresponding language pack with the load class provided by thinkphp, for example, to load the English language pack:

Lang::load(app()->getRootPath() . app\lang\\en.php );

2、 Multilingual logic implementation of database:

The parameters, introductions and documents of most products are very complex, so we add a new language identification field lang in the product table of the database to identify the language of the modified product, that is, there is a row of independent data in the product table of the database for each product corresponding to each language, and then do a language switching function in the management background to switch to a certain language, Only the product data in this language will be displayed, and only the product data in the changed language will be added, deleted, or queried!

Multilingual lang field of database product table

Manage the language switching logic in the background

3、 Implementation of multilingual logic for front end and back end interaction:

We use cookies to implement the multilingual logic of front end and back end interaction. Because cookies can be read and written at both the client and server, it is the same. A lang field is saved in the cookie to identify and track the user's current language identity in real time. The front and back end use this identity to load the language package and database data. Here, three small logic designs are involved

1. When users switch languages on the website, we update the cookie in real time.

2. A field is designed in the management background to set the default language of the website. That is, when a user visits the website for the first time and there is no lang in the cookie, the default language specified by the management will be automatically loaded.

3. The website's internal page access URL contains a language identifier, that is, when a user directly accesses a multilingual product, it is used to load the language that identifies the product and overwrite the previous language. This is the highest priority, because it is equivalent to the language that the user directly specifies to access

Lang ID saved in the cookie

Administrator specifies default language

The language identifier of the content URL. Pay attention to the en

Well, using PHP's web framework thinkphp6 to develop the multilingual website system tutorial (I), the multilingual implementation logic is OK. If you have any questions or needs, you can leave a message to comment and exchange, or you can directly send a private message to me!

This article is written by: Chief Editor Published on Software Development of Little Turkey , please indicate the source for reprinting: //hongchengtech.cn/blog/3832.html
Kuke_WP editor
author

Related recommendations

1 year ago (2024-02-20)

Multi store system management - store management design, how to do multi store system design scheme

Store management is an important part of the e-commerce platform. The platform administrator manages store information, goods, orders, settlement methods and other contents through the store management function. The author of this paper analyzes the design of store management in multi merchant system management. Let's have a look. 1、 Introduction The store management is an important part of the e-commerce platform. The platform administrator manages the store through
seven hundred and twenty-two
one
1 year ago (2024-02-19)

Sitecore: What major functions does a high-quality and powerful content management system need to have?

An appropriate content management system (CMS) is an urgent task for enterprises to maintain competitiveness through digital upgrading and transformation. Now 90% of enterprise website building and development uses CMS, which can easily create excellent customer experience in all channels, help enterprises attract new customers, retain old customers and turn existing customers into loyal customers, expand market share and increase revenue
three hundred and seventy-eight
zero
1 year ago (2024-02-18)

The combination and application of content management system and marketing technology, and the combination and application of content management system and marketing technology

B2B content marketing hopes to deliver valuable content to customers at their own stage in a timely manner during their purchase journey. Such as brand and solution related content in the cognitive stage, industry cases in the consideration stage and user confidence building stage, in-depth service introduction in the purchase stage, etc. These contents include images, videos, web pages, white papers
three hundred and seventeen
zero
1 year ago (2024-02-18)

In the second quarter, 648 websites were interviewed by the national network information system according to law, 56 websites were suspended from updating, and the spirit of the national network information work conference was ppt

According to the data released by "Cybertrust China", in the second quarter, the national Cybertrust system continued to strengthen administrative law enforcement, standardize administrative law enforcement, and investigate and deal with all kinds of illegal cases according to law. Original title: In the second quarter, 648 websites were interviewed by the national online trust system in accordance with the law, 56 websites were suspended from updating, and the TechWeb news on July 30 was released according to "online trust China"
three hundred and eleven
zero
1 year ago (2024-02-17)

Introduction and recommendation of ten free cms website building systems, and ten free defective software

It is particularly important to choose a easy-to-use cms website building system for website management and maintenance. We will choose different website building systems according to different website types, but the load, security, ease of use, versatility and subsequent development of the program are all basic criteria for everyone to choose a website building system. According to the webmaster station ranking and aleax ranking, the top 1
three hundred and seventy-six
zero
1 year ago (2024-02-17)

What are the advantages of Shanghai cms website?, How to build a website for cms

Original title: What are the benefits of building a website by Shanghai cms? Before the advent of cms, we usually found a website production company to carry out customized development. It can also be said that in fact, these website production companies also have their own formed website construction system, but it is not available for users to download. What we are talking about now is a website construction system that can be downloaded to build websites
three hundred and twenty-two
one

comment

0 people have participated in the review

Scan code to add WeChat

contact us

WeChat: Kuzhuti
Online consultation: