Cakephp中怎么实现i18n
Cakephp中如何实现i18n?
好像网上一直没有比较详细的中文资料来讲述如何使用cakephp来实现i18n。正好昨天被逼无奈的将代码中的提示中文化了一把,略有心得,简而志之。
中文化cakephp有如下几步:
1,在代码中使用__()函数。
在需要进行中文化的地方使用__()函数,如下所示:
__('This is the string i need to translate', true);
将第2个参数置为ture,这样如果有相对应的翻译词条的话那么翻译过的词条将输出,否则会输出未翻译的词条。
2,执行i18n task
如果你的代码中存在__()函数的话,你就可以执行i18n task来进行代码扫描了。
i18n task的作用是扫描源码中所有__()函数,为__()中的string建立翻译索引并将这些索引保存在.pot文件中。
那么如何执行i18n task呢?
命令行进入你项目的app目录
如果是windows平台,请确保环境变量的PATH中包含php的bin路径,并确保你cake目录下的cake\console也存在于环境变量的PATH中
执行命令 cake i18n,这时候应该会出现如下所示的提示,选择E既可
---------------------------------------I18n Shell---------------------------------------[E]xtract POT file from sources[I]nitialize i18n database table[H]elp[Q]uitWhat would you like to do? (E/I/H/Q)>
i18n task执行完毕后应该\app\locale目录下生成名为default.pot的文件,将这个文件拷贝至\app\locale\chs\LC_MESSAGES目录下
使用pot文件的编辑工具翻译词条。推荐使用Poedit
在\app\config\core.php中加上如下代码:
Configure::write('Config.language', 'chs');
好了,这样就完成简单的项目中文化了。
其中很多细节由于篇幅原因就不做完整介绍了。有疑问的话请参考cakephp的帮助文档。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Recently, many Win11 users have reported that when shutting down, they are prompted that the taskhostwindow task host is executing the shutdown task. So what is going on? Users can enter the Desktop folder under the local registry editor, and then select AutoEndTasks in the right window to set it. Let this site carefully introduce to users the solution to this problem when shutting down. Windows 11 shutdown prompts that the taskhostwindow task host is executing the shutdown task. Solution 1. Use the key combination win key + r key, enter "regedit" and press Enter, as shown in the figure below. 2. Search for [HKEY

How to get real-name authentication on Jingdong Mall APP? Jingdong Mall is an online shopping platform that many friends often use. Before shopping, it is best for everyone to conduct real-name authentication so that they can enjoy complete services and get a better shopping experience. The following is the real-name authentication method for JD.com, I hope it will be helpful to netizens. 1. Install and open JD.com, and then log in to your personal account; 2. Then click [My] at the bottom of the page to enter the personal center page; 3. Then click the small [Settings] icon in the upper right corner to go to the setting function interface; 4. Select [Account and Security] to go to the account settings page; 5. Finally, click the [Real-name Authentication] option to fill in the real-name information; 6. The installation system requires you to fill in your real personal information and complete the real-name authentication

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Apple's products and services have always been loved by users around the world. Registering a Hong Kong Apple ID will bring more convenience and privileges to users. Let’s take a look at the steps to register a Hong Kong Apple ID and what you need to pay attention to. How to register a Hong Kong Apple ID When using Apple devices, many applications and functions require using Apple ID to log in. If you want to download applications from Hong Kong or enjoy the preferential content of the Hong Kong AppStore, it is very necessary to register a Hong Kong Apple ID. This article will detail the steps on how to register a Hong Kong Apple ID and what you need to pay attention to. Steps: Select language and region: Find the "Settings" option on your Apple device and enter

In this chapter, we are going to learn the following topics related to routing ?

The China Unicom app can easily meet everyone's needs. It has various functions to solve your needs. If you want to handle various services, you can easily do it here. If you don't need it, you can unsubscribe in time here. It is effective. To avoid subsequent losses, many people sometimes feel that the data is not enough when using mobile phones, so they buy additional data packages. However, they don’t want it next month and want to unsubscribe immediately. Here, the editor explains We provide a method to unsubscribe, so that friends who need it can come and use it! In the China Unicom app, find the "My" option in the lower right corner and click on it. In the My interface, slide the My Services column and click the "I have ordered" option
