Zend Framework Primer (2)-Multi-lingual support

Source: Internet
Author: User
Keywords Zend Framework Primer (2)-Multi-lingual support
Tags zend framework

If your project wants to support multi-lingual versions, then you need to use zend_translate. Zend_translate's detailed documentation is here, but if you want to be lazy, it's also easy, and in the View Helpers documentation, you can easily implement multi-lingual support with Translate Helper.

1. Prepare translation documents

Zend_translate supports translation files in multiple formats. Choose which format to refer to here. If the entries are not many (below 5,000), consider using the most intuitive array format, and you can write to a php file. Suppose, we need a Chinese version of support, the translation file named zh_cn.php, placed in parallel with the application languages folder. The contents of the document are as follows:

Return Array (
' Hello_world ' = ' Hello! ',
);


2. Loading translation files

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. '/languages/zh_cn.php ', ' en ');
Zend_registry::set (' zend_translate ', $adapter);

The purpose of the code above is to load the zh_cn.php and save it as a global variable. Zend_registry can be seen as a global variable container.

Note: When saving to Zend_registry, the key value must be zend_translate, otherwise, the result should not be obtained.


3. Using translation entries in the view

Edit the application/views/scripts/index/index.phtml file to place the original "

Hello world!

"Replace with:

Translate (' Hello_world ');?>


4. View Page

At this point, the browser should see "Hello!" ”。

  • 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.