Implementation of multi-language support for ThinkPHP

Source: Internet
Author: User
In addition to the multi-language implementation of the project described above, if necessary, ThinkPHP's system prompt language can be internationalized. ThinkPHP system multi-language

In addition to the multi-language implementation of the project described above, if necessary, you can also set ThinkPHP
.

ThinkPHP system simplified Chinese language pack: ThinkPHP system directory/Lang/zh-cn.php ThinkPHP
The system language pack is located in the/Lang/directory of the ThinkPHP system. The Language Pack name is $ _ SERVER ['http _ ACCEPT_LANGUAGE ']
File name. the file extension is php.
.

The following are common language packs:

Zh-cn.php (simplified Chinese language pack)
Traditional Chinese language pack: zh-tw.php
American English language pack: en-us.php
Japanese Language Pack: ja. php
Korean Language Pack: ko. php
German language pack: de. php
French language pack: fr. php

ThinkPHP
By default, only the simplified Chinese language pack zh-cn.php is available. to implement other languages, you can follow the naming rules to form a language pack file and translate the prompt information into the corresponding language text. ThinkPHP
The corresponding language pack is loaded based on your browser language. if your browser supports multiple languages, use the first language. If the corresponding language pack file cannot be found, the default language is used.
Small example

In
ThinkPHP system directory/Lang/directory, edit create en-us.php file, translate the prompt text in the zh-cn.php into the corresponding English. To
_ ERROR_ACTION _ language definition:




  1. Return array (
  2. '_ ERROR_ACTION _' => 'Error Action :',
  3. );
  4. ?>

The language definition is used to prompt incorrect operations. when the browser accesses an existing module but does not exist (for example, Index/lang1), if your browser is in English, then the prompt information is changed from the original:

Invalid lang1 operation

Automatically changed:

Error
Action: lang1

If your browser is a simplified Chinese version and you want to test the English version, add l = en-us to the URL.
Parameter: index. php/Index/lang1/l/en-us.

ThinkPHP
Multi-language automatic detection, automatic loading, can easily achieve the system and project multi-language support effect.
Related Article

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.