多语言

This commit is contained in:
2025-05-06 17:16:37 +08:00
parent 07d628140e
commit 5ef4d9d754
32 changed files with 1596 additions and 920 deletions
+29 -4
View File
@@ -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]
);
}
}