晚上好,
在我目前正在开发的应用程序中,我有一个处理多语言的类。它通过外部加载关联数组来实现,其中翻译源将被定义如下:
'Source input' => 'Zdroj vstupního'
目前,通过以下方式寻址和使用类,这可以完美地工作:
$lang = new Lang('Czech');
print $lang->_('Source input'); // output: "zdroj vstupního"
但是,我想在一个不依赖于“Lang”类实例的快捷函数中使用它。我已经尝试过使用静态方法,但到目前为止我运气不佳。
我想要实现的伪代码。
$lang = new Lang('Czech');
$lang->setCurrent('contact_us'); // loads the language file for contact_us
<p>
<?php print _('Source input'); ?> // output: "zdroj vstupního"
</p>
在正确的方向上的一点会很棒。谢谢!