多语言
This commit is contained in:
@@ -31,8 +31,33 @@ class Rule extends Base
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取翻译后的标题
|
||||
* @param string $lang 语言代码
|
||||
* @return string
|
||||
*/
|
||||
public function getTranslatedTitle($lang = null)
|
||||
{
|
||||
if (!$lang) {
|
||||
$lang = session('lang', 'zh-cn');
|
||||
}
|
||||
|
||||
$translatedTitle = RuleTranslation::getTranslatedTitle($this->id, $lang);
|
||||
return $translatedTitle ?: $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置翻译标题
|
||||
* @param string $lang 语言代码
|
||||
* @param string $title 翻译标题
|
||||
* @return bool
|
||||
*/
|
||||
public function setTranslatedTitle($lang, $title)
|
||||
{
|
||||
return RuleTranslation::updateOrCreate(
|
||||
['rule_id' => $this->id, 'lang' => $lang],
|
||||
['title' => $title]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user