phpkohana-3

PHP: What does __('Some text') do?


Reading about Kohana templates and saw something I've never seen before:

$this->template->title = __('Welcome To Acme Widgets');

What does __('Text') mean? What is it? What does it do?


Solution

  • In Kohana (version 3) the function is defined in system/base.php and is a convenience function to aid (as the other answers have mentioned) internationalization. You provide a string (with, optionally, some placeholders to substitute values into the finished text) which is then interpreted and, if required, a translation is returned.

    Contrary to assumptions in other answers, this does not use gettext.

    A very basic example would be (this particular string is already translated into English, Spanish and French in Kohana):

    // 1. In your bootstrap.php somewhere below the Kohana::init line
    I18n::lang('fr');
    
    // 2. In a view
    echo __("Hello, world!"); // Bonjour, monde!