Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the __'s mean in this context?

Tags:

php

magento

throw new Exception(__('exception'));

What do the __'s do? What are they called? I've seen this in several implementations and is common throughout the Magento codebase.

Thanks

like image 615
john Avatar asked Jul 22 '11 01:07

john


2 Answers

__ is a common name for a localization function. __ is a valid function name like any other.

function __($text) {
    // return localized text
}

How exactly it works depends on the framework in question.

like image 199
deceze Avatar answered Oct 13 '22 01:10

deceze


Usually if you see __() or _() its to pull the value of the string passed into the function from an i18n translation catalog. So the string passed to the function is looked up in the catalog and the appropriate translation is returned.

like image 35
prodigitalson Avatar answered Oct 13 '22 00:10

prodigitalson