GNU GetText--Simple or graceful

Source: Internet
Author: User
Tags gettext
Developed under Windows, accustomed to the loadstring () function to record text from the resource, so as to achieve multi-language support. But in PHP. and under Linux. Also, not everyone uses loadstring () to load text, but writes its own function, reading text from XML or even from a database.

The principle of loading the text resources is nothing more than the Key+value mode, that is, to each string is numbered, and then by number to find the corresponding value. But the problem with this is that numbering is often difficult, especially in English. Also, the program is written with key, and value is stored elsewhere. It is not intuitive to have placeholder escape characters such as%s and so on in the text. Also, if the first time if not according to Key+value Way to write code, the back to support, there is a lot of work.

I always thought that there was no better way to do it, until yesterday I discovered the GNU GetText Library because of the multilingual support for studying PHP applications. This thing is really a perfect solution, because her approach is too beautiful, too concise. As long as the existing string, packaging a GetText ("original text") on it (in PHP, even with _ () can be). Do not establish any key alone, the text inside is key. Then with a tool, you can automatically extract all the text to form a PO file. Then as long as the PO file for editing and translation, and finally compiled into Mo file can be. I was also worried that every time you generate a PO file to be fully translated, the results found that there is no need, people have already considered the function of merging.

Multi-language support, it turns out to be so simple.

http://www.gnu.org/software/gettext/

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.