gpt4 book ai didi

PHP:__ ('Some text' ) 做什么?

转载 作者:IT老高 更新时间:2023-10-28 12:00:53 25 4
gpt4 key购买 nike

阅读 Kohana templates并看到了我从未见过的东西:

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

__('Text') 是什么意思?它是什么?它有什么作用?

最佳答案

在 Kohana(版本 3)中,函数在 system/base.php 中定义。并且是帮助(正如其他答案所提到的)国际化的便利功能。您提供一个字符串(可选地,带有一些占位符以将值替换为完成的文本),然后对其进行解释,如果需要,返回翻译。

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

一个非常基本的例子是(这个特定的字符串已经在 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' ) 做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2427204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com