[英]Kohana i18n using database
I'm new to kohana and trying to modify i18n from file based to database based. 我是kohana的新手,正在尝试将i18n从基于文件的数据库修改为基于数据库的数据库。 Based on this tutorial I did following: Created new class
i18n
in application/classes
directory to override default __()
function. 基于本教程,我做了以下工作:在
application/classes
目录中创建新的类i18n
以覆盖默认的__()
函数。
<?php
class I18n extends Kohana_I18n
{
function __($token, $lang = 'en')
{
$query = ORM::factory('Dictionary')->where('token', '=', $token)->find();
return $query->{"txt_" . $lang};
}
}
I have dictionary model which looks like that 我有看起来像这样的字典模型
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Dictionary extends ORM {
protected $_table_name = 'Dictionary';
}
Got error message: 得到错误消息:
http://screencast.com/t/r84oL1A1 http://screencast.com/t/r84oL1A1
What am I doing wrong? 我究竟做错了什么? Any suggestion?
有什么建议吗? Maybe class doesn't autoload?
也许类不会自动加载?
In this realisation you need to use in your View: 在这种实现中,您需要在View中使用:
I18n::__($message_to_translate);
not 不
__($message_to_translate);
And you must declare __()
function as static : 并且必须将
__()
函数声明为static :
<?php defined('SYSPATH') or die('No direct script access.');
class I18n extends Kohana_I18n
{
public static function __($token, $lang = 'en')
{
$query = ORM::factory('Dictionary')->where('token', '=', $token)->find();
return $query->{"txt_" . $lang};
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.