PHP GetText Use method attach strange bug One

Source: Internet
Author: User
Tags gettext

Whim, suddenly want to study PHP multi-language.

Look at the company's projects and WordPress are used by the GetText () to multi-lingual.

Then open the PHP manual to copy the following paragraph

<?PHP//Set language to Germanputenv(' Lc_all=de_de ');setlocale(Lc_all, ' De_de '); //specify location of translation tablesBindtextdomain ("Myphpapp", "./locale"); //Choose DomainTextdomain ("Myphpapp"); //translation is looking for in./locale/de_de/lc_messages/myphpapp.mo Now//Print a test messageEchoGetText ("Welcome to My PHP application"); //Or Use the alias _ () for GetText ()Echo_ ("A Nice Day");?>

And then I got a poedit on the net to compile Mo files.

The result is a lazy process, which changes the MO file name to test and assigns the Textdomin value in the code to test.

Oh..... It turned out to be tragic.

GetText () function kill translation.

And then all sorts of attempts. The following are unscientific experimental processes (function requirements Textdomain values need to be consistent with Mo filenames)

Textdomain value MO file Name GetText Running Status Comments
He He.mo Normal  
Heh Heh.mo Normal  
Test Test.mo Flutter Street  
Zh_cn Zh_cn.mo Flutter Street  
Zh_cn Zh__cn.mo Normal The middle is two underline
Hehe Hehe.mo Flutter Street  
Heheh Heheh.mo Normal Normal starting from the length of the stored character greater than or equal to 5 o'clock
Hehehehe Hehehehe.mo Normal  
Heheheheh Heheheheh.mo Normal  
Hehehehehe Hehehehehe.mo Normal  
Myphpapp Myphpapp.mo Normal  
Myphpapp Myphpapp.mo Normal  
Translations Translations.mo Normal  

Conclusion: GetText translation function corresponds to the value of Textdomain is equal to 4 characters (or add an underscore), there will be a bug read error (Note: When the Textdomain value and Mo file name does not correspond, the system will try to look in the cache, if there is a cache, The GetText can work properly.

PHP GetText Use method attach strange bug One

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.