Zend_Translate is required if your project supports multilingual versions. The detailed documentation of Zend_Translate is here, but it is easy to be lazy. in the ViewHelpers document, we will introduce how to use TranslateHelper to easily implement multi-language support. 1. prepare the translation file Zend_Translate to support translation files in multiple formats. For more information about the format, see Zend_Translate. The detailed documentation of Zend_Translate is here. However, if you want to be lazy, it is also very simple. The View Helpers document describes how to use Translate Helper to easily implement multi-language support.
1. prepare the translation file
Zend_Translate supports multiple formats of translation files. For more information about the format, see here. If there are not many entries (less than 5000 entries), you can consider using the most intuitive array format and write it into a php file. Assume that a Chinese version is required. the translation file is named zh_cn.php and placed in the ages folder parallel to the application. The file content is as follows:
Return array (
'Hello _ World' => 'hello! ',
);
2. load the translation file
Edit the html/index. php file and insert the following code before the front-end controller runs:
Require_once 'zend/Registry. php ';
Require_once 'zend/Translate. php ';
$ Adapter = new Zend_Translate ('array', $ rootPath. '/ages/zh_cn.php', 'zh ');
Zend_Registry: set ('zend _ Translate', $ adapter );
The above code loads zh_cn.php and saves it as a global variable. Zend_Registry can be viewed as a global variable container.
Note: When saving to Zend_Registry, the key value must be Zend_Translate. Otherwise, the expected result cannot be obtained.
3. use translation entries in the view
Edit the application/views/scripts/index. phtml file and convert the original "Hello World !" Replace:
Translate ('Hello _ world');?>
4. view the page
In this case, the browser should see "Hello !".