How to implement the multi-language design of PHP involving database content? -Php Tutorial

Source: Internet
Author: User
How to implement the multi-language design of PHP involving database content? Has anyone done this? (Similar to the multi-language switching of content on APPLE's official website) can you help me? thank you.


Reply to discussion (solution)

How do we achieve this? Use a field? Switch database? Switch table? Or something else?

How many fields are added in the table? Statement.
For example:
SC _title, en_title, tc_title

Multi-language interface or multi-language content?

How many fields are added in the table? Statement.
For example:
SC _title, en_title, tc_title



This method is very unreliable. do you need to add fields to add languages?

How to change the database without changing the language
Table: res (id ,...)
Table: res_lang (id, res_id, language, content ...)

Do you want to add a table to add a language?
Isn't adding a table modifying the database?

How to change the database without changing the language
Table: res (id ,...)
Table: res_lang (id, res_id, language, content ...)

Do you want to add a table to add a language?
Isn't adding a table modifying the database?


How to change the database without changing the language
Table: res (id ,...)
Table: res_lang (id, res_id, language, content ...)



You do not need to add tables in this usage.

You do not need to add fields or values.
I did this before:

CREATE TABLE `article` (  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  `albumID` int(11) DEFAULT NULL,  `category` mediumint(8) unsigned NOT NULL DEFAULT '0',  `title` varchar(120) NOT NULL,  `uid` int(10) unsigned NOT NULL DEFAULT '0',   `description` mediumtext NOT NULL,  `content` text NOT NULL,   `puttime` int(10) unsigned NOT NULL DEFAULT '0',   `listorder` int(10) unsigned NOT NULL DEFAULT '999',   `lang` varchar(20) NOT NULL DEFAULT 'zh_cn',  PRIMARY KEY (`id`),  KEY `category` (`category`),  KEY `lang` (`lang`) ) ENGINE=MyISAM AUTO_INCREMENT=5961 DEFAULT CHARSET=utf8



The lang field is used to identify different languages. all languages are saved to this table.

By adding fields or tables, you can easily associate the content of different languages.
If you think that the records are cleverly saved, the results only increase the access overhead in vain.

By adding fields or tables, you can easily associate the content of different languages.
If you think that the records are cleverly saved, the results only increase the access overhead in vain.



99% of this type of data needs to be stored in the cache. how much overhead does this query increase?

Do you only mean that the interface is multilingual?
Who will read a Japanese article on the German interface?


By adding fields or tables, you can easily associate the content of different languages.
If you think that the records are cleverly saved, the results only increase the access overhead in vain.



99% of this type of data needs to be stored in the cache. how much overhead does this query increase?

Do you only mean that the interface is multilingual?
Who will read a Japanese article on the German interface?



By adding fields or tables, you can easily associate the content of different languages.
If you think that the records are cleverly saved, the results only increase the access overhead in vain.



99% of this type of data needs to be stored in the cache. how much overhead does this query increase?



Strange, the article cannot be cached?

The specific solution depends on the product requirements.
Reuse public data as much as possible
For example, if you only need titles and content in multiple languages and images are shared, split the fields.
If the news published in different languages are completely different, they are independently recorded.
If the models are different, consider table sharding.

Yes, I have replied here. thank you for your help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.