Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

kohana-3

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?

like image 748
Svish Avatar asked Mar 11 '10 17:03

Svish


1 Answers

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! 
like image 61
salathe Avatar answered Sep 23 '22 00:09

salathe