PHP:__('Some text')有什么作用? [英] PHP: What does __('Some text') do?

查看:139
本文介绍了PHP:__('Some text')有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读 Kohana模板,并看到了我的一些东西从未见过:

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

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

__('Text')是什么意思?它是什么?它是做什么的?

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

推荐答案

在Kohana(版本3)中,该函数在

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.

与其他答案中的假设相反,它不使用 gettext .

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

一个非常基本的示例是(该特殊字符串已经在Kohana中翻译为英语,西班牙语和法语):

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!

这篇关于PHP:__('Some text')有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆