Home Backend Development PHP Tutorial yii Query Builder (yii Query Builder) Official Guide Translation_PHP Tutorial

yii Query Builder (yii Query Builder) Official Guide Translation_PHP Tutorial

Jul 13, 2016 pm 05:19 PM
builder query yii device official guide Inquire translate

/**** 
Query Builder  
 
translated by php攻城师 
 
http://blog.csdn.net/phpgcs 
 
Preparing Query Builder             准备 Query Builder         
Building Data Retrieval Queries     构建数据查找查询 
Building Data Manipulation Queries  构建数据操作查询 
Building Schema Manipulation Queries构建数据结构操作查询 
 
 
****/  
Yii Query Builder 提供了一个以面向对象的方式写SQL表达式的方法。  
允许开发者用 类的方法和属性来 明确一个SQL表达式中的独立的单元。然后将不同的单元组装成一个合法的SQL表达式,进而让DAO方法调用和执行。  
下面是一个典型的使用Yii Query Builder来建立一个SELECT SQL 语句的例子:  
  
$user = Yii::app()->db->createCommand()  
    ->select('id, username, profile')  
    ->from('tbl_user u')  
    ->join('tbl_profile p', 'u.id=p.user_id')  
    ->where('id=:id', array(':id'=>$id))  
    ->queryRow();  
  
当你需要程序化地组装一个SQL语句时,或者基于一些额外的逻辑在你的应用中时, 用Yii Query Builder是最好不过的了。  
  
主要的好处是:  
  
1,  允许程序化建立一个复杂的SQL表达式  
2, 自动引用表明和列名来 防止跟SQL保留关键字以及特殊字符的冲突  
3, 在可以的情况下引用参数值,使用参数绑定,从而降低了SQL 注入攻击的风险。  
4, 提供一定程度的DB抽象, 从而简化了向不同DB平台迁移的工作。  
  
并不是强制要使用 Query Builder, 事实上, 如果你的查询很简单,还是直接写SQL 语句来的快捷方便。  
  
注意: Query Builder 不可以被用语修改一个已经被定制了的SQL表达式查询。如下代码是不会工作的:  
  
$command = Yii::app()->db->createCommand('SELECT * FROM tbl_user');  
// the following line will NOT append WHERE clause to the above SQL  
$command->where('id=:id', array(':id'=>$id));  
  
换句话说, 不要把 普通SQL 和 Query Builder 混合使用!  
  
  
/***** 
 
1. Preparing Query Builder  
 
translated by php攻城师 
 
http://blog.csdn.net/phpgcs 
 
*****/  
  
Query Builder 是跟 CDbCommand 相关联的, 主 DB 查询类 定义在 DAO 中。  
要开始使用 Query Builder, 我们创建一个 CDbCommand 实例如下:  
  
$command = Yii::app()->db->createCommand();  
  
我们使用 Yii::app()->db 获得 DB connection, 然后用 CDbConnection::createCommand() 来创建实例.  
  
注意:这里我们不是想在DAO 中把一整个SQL语句给了 createCommand() , 而是留空了。  
这是因为我们将在后面使用  Query Builder 的方法来构建 这个SQL 表达式的不同部分。  
  
  
/***** 
 
2. Building Data Retrieval Queries  
 
translated by php攻城师 
 
http://blog.csdn.net/phpgcs 
 
*****/  
  
Data retrieval queries 指的是 SELECT SQL statements.   
  
query builder 提供了一系列方法来建立一个 SELCET 语句的不同部分。  
因为所有这些方法返回了 CDbCommand 实例 ,我们可以通过使用 方法链来调用它们。如下:  
  
select(): specifies the SELECT part of the query  
selectDistinct(): specifies the SELECT part of the query and turns on the DISTINCT flag  
from(): specifies the FROM part of the query  
where(): specifies the WHERE part of the query  
andWhere(): appends condition to the WHERE part of the query with AND operator  
orWhere(): appends condition to the WHERE part of the query with OR operator  
join(): appends an inner join query fragment  
leftJoin(): appends a left outer join query fragment  
rightJoin(): appends a right outer join query fragment  
crossJoin(): appends a cross join query fragment  
naturalJoin(): appends a natural join query fragment  
group(): specifies the GROUP BY part of the query  
having(): specifies the HAVING part of the query  
order(): specifies the ORDER BY part of the query  
limit(): specifies the LIMIT part of the query  
offset(): specifies the OFFSET part of the query  
union(): appends a UNION query fragment  
In the following, we explain how to use these query builder methods. For simplicity, we assume the underlying database is MySQL. Note that if you are using other DBMS, the table/column/value quoting shown in the examples may be different.  
  
select()  
function select($columns='*')  
  
这个方法定制了查询的SELECT 部分。  
参数 $columns 定制了将要被选择的列, 既可以是被逗号分隔开的列, 也可以是一个由列名构成的数组。  
列名可以包含表前缀 和(或) 列别名。  
这个方法将自动引用列名,除非某个列 包含了插入语(意味着那个列是由一个DB表达式提供)  
  
看例子:  
  
// SELECT *  
select()  
// SELECT `id`, `username`  
select('id, username')  
// SELECT `tbl_user`.`id`, `username` AS `name`  
select('tbl_user.id, username as name')  
// SELECT `id`, `username`  
select(array('id', 'username'))  
// SELECT `id`, count(*) as num  
select(array('id', 'count(*) as num'))  
  
  
from()  
function from($tables)  
  
看例子:  
// FROM `tbl_user`  
from('tbl_user')  
// FROM `tbl_user` `u`, `public`.`tbl_profile` `p`  
from('tbl_user u, public.tbl_profile p')  
// FROM `tbl_user`, `tbl_profile`  
from(array('tbl_user', 'tbl_profile'))  
// FROM `tbl_user`, (select * from tbl_profile) p  
from(array('tbl_user', '(select * from tbl_profile) p'))  
  
  
where()  
function where($conditions, $params=array())  
  
其中 $conditions 参数既可以是一个 (e.g. id=1) 也可以是一个如下格式的 array:  
  
array(operator, operand1, operand2, ...)  
 operator 有以下几个:  
  
and: array('and', 'id=1', 'id=2') =====> id=1 AND id=2.   
     array('and', 'type=1', array('or', 'id=1', 'id=2')) =====> type=1 AND (id=1 OR id=2).   
    这个方法不会做任何的 quoting 或者 escaping.  
  
or: 类似 and  
  
in:  array('in', 'id', array(1,2,3)) =====> id IN (1,2,3). The method will properly quote the column name and escape values in the range.  
not in:   
  
like: operand 1 ====> a column or DB expression  
        operand 2 ====> a string or an array   
      
    array('like', 'name', '%tester%') =====> name LIKE '%tester%'  
    array('like', 'name', array('%test%', '%sample%')) =====> name LIKE '%test%' AND name LIKE '%sample%'.   
  
The method will properly quote the column name and escape values in the range.  
not like:   
or like:   
or not like:   
  
看例子:  
// WHERE id=1 or id=2  
where('id=1 or id=2')  
// WHERE id=:id1 or id=:id2  
where('id=:id1 or id=:id2', array(':id1'=>1, ':id2'=>2))  
// WHERE id=1 OR id=2  
  
  
where(array('or', 'id=1', 'id=2'))  
// WHERE id=1 AND (type=2 OR type=3)  
where(array('and', 'id=1', array('or', 'type=2', 'type=3')))  
// WHERE `id` IN (1, 2)  
where(array('in', 'id', array(1, 2))  
// WHERE `id` NOT IN (1, 2)  
where(array('not in', 'id', array(1,2)))  
// WHERE `name` LIKE '%Qiang%'  
where(array('like', 'name', '%Qiang%'))  
// WHERE `name` LIKE '%Qiang' AND `name` LIKE '%Xue'  
where(array('like', 'name', array('%Qiang', '%Xue')))  
// WHERE `name` LIKE '%Qiang' OR `name` LIKE '%Xue'  
where(array('or like', 'name', array('%Qiang', '%Xue')))  
// WHERE `name` NOT LIKE '%Qiang%'  
where(array('not like', 'name', '%Qiang%'))  
// WHERE `name` NOT LIKE '%Qiang%' OR `name` NOT LIKE '%Xue%'  
where(array('or not like', 'name', array('%Qiang%', '%Xue%')))  
  
  
当有like 时, 我们需要确定  % and _ .   
如果来自用户的输入,我们还应该 使用如下的代码 来 过滤掉特殊字符 防止它们被当作通配符(wildcards)  
  
$keyword=$_GET['q'];  
// escape % and _ characters  
$keyword=strtr($keyword, array('%'=>'\%', '_'=>'\_'));  
$command->where(array('like', 'title', '%'.$keyword.'%'));  
  
  
andWhere()  
function andWhere($conditions, $params=array())  
  
orWhere()  
function orWhere($conditions, $params=array())  
  
order()  
function order($columns)  
  
看例子:  
  
// ORDER BY `name`, `id` DESC  
order('name, id desc')  
// ORDER BY `tbl_profile`.`name`, `id` DESC  
order(array('tbl_profile.name', 'id desc'))  
  
limit() and offset()  
function limit($limit, $offset=null)  
function offset($offset)  
注意,一些 DBMS 不支持 LIMIT and OFFSET , 但是我们的 the Query Builder 将会重写整个SQL 语句来模拟 limit and offset.的功能。  
  
看例子:  
  
// LIMIT 10  
limit(10)  
// LIMIT 10 OFFSET 20  
limit(10, 20)  
// OFFSET 20  
offset(20)  
  
join() and its variants  
function join($table, $conditions, $params=array())  
function leftJoin($table, $conditions, $params=array())  
function rightJoin($table, $conditions, $params=array())  
function crossJoin($table)  
function naturalJoin($table)  
  
注意:不像其他的 query builder 方法, 每次调用 join 将会被添加到 之前的join。  
  
看例子:  
  
// JOIN `tbl_profile` ON user_id=id  
join('tbl_profile', 'user_id=id')  
// LEFT JOIN `pub`.`tbl_profile` `p` ON p.user_id=id AND type=1  
leftJoin('pub.tbl_profile p', 'p.user_id=id AND type=:type', array(':type'=>1))  
  
  
group()  
function group($columns)  
  
看例子:  
  
// GROUP BY `name`, `id`  
group('name, id')  
// GROUP BY `tbl_profile`.`name`, `id`  
group(array('tbl_profile.name', 'id'))  
  
  
having()  
function having($conditions, $params=array())  
  
看例子:  
  
// HAVING id=1 or id=2  
having('id=1 or id=2')  
// HAVING id=1 OR id=2  
having(array('or', 'id=1', 'id=2'))  
  
  
union()  
function union($sql)  
  
看例子:  
  
// UNION (select * from tbl_profile)  
union('select * from tbl_profile')  
  
  
/***** 
Executing Queries  执行查询 
****/  
  
通过调用上面的 query builder 方法来构造 查询, 我们就可以用 DAO 方法来执行这个查询了。  
例如:  
$users = Yii::app()->db->createCommand()  
    ->select('*')  
    ->from('tbl_user')  
    ->queryAll();  
  
/**** 
复原 SQLs 
****/  
 CDbCommand::getText().  
  
$sql = Yii::app()->db->createCommand()  
    ->select('*')  
    ->from('tbl_user')  
    ->text;  
  
如果绑定有参数,我们也可以通过 CDbCommand::params property 来获得参数。  
  
其他语法 Building Queries  
  
有时候通过方法链来构建查询并不是最佳选择。   
举例来说,下面的两个表达是等价的, 假设 $command 代表了一个CDbCommand 对象:  
  
$command->select(array('id', 'username'));  
$command->select = array('id', 'username');  
  
进一步 CDbConnection::createCommand() 方法可以把 array 作为参数.   
  
如下:  
  
$row = Yii::app()->db->createCommand(array(  
    'select' => array('id', 'username'),  
    'from' => 'tbl_user',  
    'where' => 'id=:id',  
    'params' => array(':id'=>1),  
))->queryRow();  
  
  
  
Building Multiple Queries 构建多查询  
  
一个 CDbCommand 实例可以被用多次来构建几个查询。  
在构建新查询之前, 要使用 reset() 方法来清楚之前的设置。  
  
$command = Yii::app()->db->createCommand();  
$users = $command->select('*')->from('tbl_users')->queryAll();  
$command->reset();  // clean up the previous query  
$posts = $command->select('*')->from('tbl_posts')->queryAll();  
  
/****** 
 
3. Building Data Manipulation Queries  
translated by php攻城师 
 
http://blog.csdn.net/phpgcs 
 
*****/  
数据操作 指的是 在一个 DB 表中 inserting, updating and deleting 数据。  
  
insert(): inserts a row into a table  
update(): updates the data in a table  
delete(): deletes the data from a table  
  
insert()  
function insert($table, $columns)  
  
看例子:  
  
// build and execute the following SQL:  
// INSERT INTO `tbl_user` (`name`, `email`) VALUES (:name, :email)  
$command->insert('tbl_user', array(  
    'name'=>'Tester',  
    'email'=>'tester@example.com',  
));  
  
  
update()  
function update($table, $columns, $conditions='', $params=array())  
  
看例子:  
  
  
// build and execute the following SQL:  
// UPDATE `tbl_user` SET `name`=:name WHERE id=:id  
$command->update('tbl_user', array(  
    'name'=>'Tester',  
), 'id=:id', array(':id'=>1));  
  
  
delete()  
function delete($table, $conditions='', $params=array())  
  
看例子:  
  
  
// build and execute the following SQL:  
// DELETE FROM `tbl_user` WHERE id=:id  
$command->delete('tbl_user', 'id=:id', array(':id'=>1));  
  
  
/******* 
 
4. Building Schema Manipulation Queries  
 
translated by php攻城师 
 
http://blog.csdn.net/phpgcs 
 
******/  
  
除了常规的查找查询和操作查询, 还有一系列的方法 来构建和执行 可以 操作 数据库结构的 SQL 查询。  
  
  
createTable(): creates a table  
renameTable(): renames a table  
dropTable(): drops a table  
truncateTable(): truncates a table  
addColumn(): adds a table column  
renameColumn(): renames a table column  
alterColumn(): alters a table column  
addForeignKey(): adds a foreign key (available since 1.1.6)  
dropForeignKey(): drops a foreign key (available since 1.1.6)  
dropColumn(): drops a table column  
createIndex(): creates an index  
dropIndex(): drops an index  
  
  
Abstract Data Types  抽象数据类型  
  
实质上就是为了兼容不同的DBMS 而构建的数据类型, 一个通用的接口。  
  
  
pk: a generic primary key type, will be converted into int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY for MySQL;  
string: string type, will be converted into varchar(255) for MySQL;  
text: text type (long string), will be converted into text for MySQL;  
integer: integer type, will be converted into int(11) for MySQL;  
float: floating number type, will be converted into float for MySQL;  
decimal: decimal number type, will be converted into decimal for MySQL;  
datetime: datetime type, will be converted into datetime for MySQL;  
timestamp: timestamp type, will be converted into timestamp for MySQL;  
time: time type, will be converted into time for MySQL;  
date: date type, will be converted into date for MySQL;  
binary: binary data type, will be converted into blob for MySQL;  
boolean: boolean type, will be converted into tinyint(1) for MySQL;  
money: money/currency type, will be converted into decimal(19,4) for MySQL. This type has been available since version 1.1.8.  
  
  
createTable()  
function createTable($table, $columns, $options=null)  
  
// CREATE TABLE `tbl_user` (  
//     `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,  
//     `username` varchar(255) NOT NULL,  
//     `location` point  
// ) ENGINE=InnoDB  
createTable('tbl_user', array(  
    'id' => 'pk',  
    'username' => 'string NOT NULL',  
    'location' => 'point',  
), 'ENGINE=InnoDB')  
  
  
renameTable()  
function renameTable($table, $newName)  
  
// RENAME TABLE `tbl_users` TO `tbl_user`  
renameTable('tbl_users', 'tbl_user')  
  
  
dropTable()  
function dropTable($table)  
  
// DROP TABLE `tbl_user`  
dropTable('tbl_user')  
  
  
truncateTable()  
function truncateTable($table)  
  
// TRUNCATE TABLE `tbl_user`  
truncateTable('tbl_user')  
  
  
addColumn()  
function addColumn($table, $column, $type)  
  
// ALTER TABLE `tbl_user` ADD `email` varchar(255) NOT NULL  
addColumn('tbl_user', 'email', 'string NOT NULL')  
  
  
dropColumn()  
function dropColumn($table, $column)  
  
// ALTER TABLE `tbl_user` DROP COLUMN `location`  
dropColumn('tbl_user', 'location')  
  
  
renameColumn()  
function renameColumn($table, $name, $newName)  
  
// ALTER TABLE `tbl_users` CHANGE `name` `username` varchar(255) NOT NULL  
renameColumn('tbl_user', 'name', 'username')  
  
  
alterColumn()  
  
// ALTER TABLE `tbl_user` CHANGE `username` `username` varchar(255) NOT NULL  
alterColumn('tbl_user', 'username', 'string NOT NULL')  
  
  
addForeignKey()  
function addForeignKey($name, $table, $columns,  
    $refTable, $refColumns, $delete=null, $update=null)  
  
// ALTER TABLE `tbl_profile` ADD CONSTRAINT `fk_profile_user_id`  
// FOREIGN KEY (`user_id`) REFERENCES `tbl_user` (`id`)  
// ON DELETE CASCADE ON UPDATE CASCADE  
addForeignKey('fk_profile_user_id', 'tbl_profile', 'user_id',  
    'tbl_user', 'id', 'CASCADE', 'CASCADE')  
  
  
dropForeignKey()  
function dropForeignKey($name, $table)  
// ALTER TABLE `tbl_profile` DROP FOREIGN KEY `fk_profile_user_id`  
dropForeignKey('fk_profile_user_id', 'tbl_profile')  
  
  
createIndex()  
function createIndex($name, $table, $column, $unique=false)  
// CREATE INDEX `idx_username` ON `tbl_user` (`username`)  
createIndex('idx_username', 'tbl_user', 'username')  
  
  
dropIndex()  
function dropIndex($name, $table)  
// DROP INDEX `idx_username` ON `tbl_user`  
dropIndex('idx_username', 'tbl_user')  
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532694.htmlTechArticle/**** Query Builder translated by php siege division http://blog.csdn.net/phpgcs Preparing Query Builder Preparing Query Builder Building Data Retrieval Queries Building data search queries Bui...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if the translation web page that comes with the Edge browser is missing? What should I do if the translation web page that comes with the Edge browser is missing? Mar 14, 2024 pm 08:50 PM

The edge browser comes with a translation function that allows users to translate anytime and anywhere, which brings great convenience to users. However, many users say that the built-in translation webpage is missing. Then the edge browser automatically What should I do if the translation page I brought is missing? Let this site introduce how to restore the translated web page that comes with the Edge browser if it is missing. How to restore the translation webpage that comes with the Edge browser is missing 1. Check whether the translation function is enabled: In the Edge browser, click the three dots icon in the upper right corner, and then select the "Settings" option. On the left side of the settings page, select the Language option. Make sure "Translate&rd"

Guide to turning off VBS in Windows 11 Guide to turning off VBS in Windows 11 Mar 08, 2024 pm 01:03 PM

With the launch of Windows 11, Microsoft has introduced some new features and updates, including a security feature called VBS (Virtualization-basedSecurity). VBS utilizes virtualization technology to protect the operating system and sensitive data, thereby improving system security. However, for some users, VBS is not a necessary feature and may even affect system performance. Therefore, this article will introduce how to turn off VBS in Windows 11 to help

Setting up Chinese with VSCode: The Complete Guide Setting up Chinese with VSCode: The Complete Guide Mar 25, 2024 am 11:18 AM

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

Don't worry about watching movies without subtitles! Xiaomi announces the launch of Xiaoai Translation real-time subtitles for Japanese and Korean translation Don't worry about watching movies without subtitles! Xiaomi announces the launch of Xiaoai Translation real-time subtitles for Japanese and Korean translation Jul 22, 2024 pm 02:11 PM

According to news on July 22, today, the official Weibo of Xiaomi ThePaper OS announced that Xiaoai Translation has been upgraded. Real-time subtitles have been added to Japanese and Korean translations, and subtitle-free videos and live conferences can be transcribed and translated in real time. Face-to-face simultaneous interpretation supports translation into 12 languages, including Chinese, English, Japanese, Korean, Russian, Portuguese, Spanish, Italian, French, German, Indonesian, and Hindi. The above functions currently only support the following three new phones: Xiaomi MIX Fold 4 Xiaomi MIX Flip Redmi K70 Extreme Edition It is reported that in 2021, Xiao Ai’s AI subtitles will be added to Japanese and Korean translations. AI subtitles use Xiaomi’s self-developed simultaneous interpretation technology to provide a faster, more stable and accurate subtitle reading experience. 1. According to the official statement, Xiaoai Translator can not only be used in audio and video venues

12306 How to check historical ticket purchase records How to check historical ticket purchase records 12306 How to check historical ticket purchase records How to check historical ticket purchase records Mar 28, 2024 pm 03:11 PM

Download the latest version of 12306 ticket booking app. It is a travel ticket purchasing software that everyone is very satisfied with. It is very convenient to go wherever you want. There are many ticket sources provided in the software. You only need to pass real-name authentication to purchase tickets online. All users You can easily buy travel tickets and air tickets and enjoy different discounts. You can also start booking reservations in advance to grab tickets. You can book hotels or special car transfers. With it, you can go where you want to go and buy tickets with one click. Traveling is simpler and more convenient, making everyone's travel experience more comfortable. Now the editor details it online Provides 12306 users with a way to view historical ticket purchase records. 1. Open Railway 12306, click My in the lower right corner, and click My Order 2. Click Paid on the order page. 3. On the paid page

How to check your academic qualifications on Xuexin.com How to check your academic qualifications on Xuexin.com Mar 28, 2024 pm 04:31 PM

How to check my academic qualifications on Xuexin.com? You can check your academic qualifications on Xuexin.com, but many users don’t know how to check their academic qualifications on Xuexin.com. Next, the editor brings you a graphic tutorial on how to check your academic qualifications on Xuexin.com. Interested users come and take a look! Xuexin.com usage tutorial: How to check your academic qualifications on Xuexin.com 1. Xuexin.com entrance: https://www.chsi.com.cn/ 2. Website query: Step 1: Click on the Xuexin.com address above to enter the homepage Click [Education Query]; Step 2: On the latest webpage, click [Query] as shown by the arrow in the figure below; Step 3: Then click [Login Academic Credit File] on the new page; Step 4: On the login page Enter the information and click [Login];

How to solve the problem that Google Chrome's built-in translation fails? How to solve the problem that Google Chrome's built-in translation fails? Mar 13, 2024 pm 08:46 PM

Browsers generally have built-in translation functions, so you don’t have to worry about not being able to understand when browsing foreign language websites! Google Chrome is no exception, but some users find that when they open the translation function of Google Chrome, there is no response or failure. What should they do? You can try the latest solution I found. Operation tutorial: Click the three dots in the upper right corner and click Settings. Click Add Language, add English and Chinese, and make the following settings for them. The English setting asks whether to translate web pages in this language. The Chinese setting displays web pages in this language, and Chinese must be moved to the top before it can be set as the default language. If you open the webpage and no translation option pops up, right-click and select Translate Chinese, OK.

Why can't Google Chrome translate Chinese? Why can't Google Chrome translate Chinese? Mar 11, 2024 pm 04:04 PM

Why can't Google Chrome translate Chinese? As we all know, Google Chrome is one of the browsers with built-in translation. When you browse pages written in other countries in this browser, the browser will automatically translate the page into Chinese. Recently, some users have said that they Chinese translation cannot be performed. At this time, we need to fix it in the settings. Next, the editor will bring you the solution to the problem that Google Chrome cannot translate into Chinese. Friends who are interested should come and take a look. Google Chrome cannot translate Chinese solutions 1. Modify the local hosts file. Hosts is a system file without an extension. It can be opened with tools such as Notepad. Its main function is to define the mapping relationship between IP addresses and host names. It is a mapping IP address

See all articles