修改 Chevereto 网站标题并让标题支持翻译

教程分享评论3962字数 2049阅读模式

Chevereto 是一个非常不错的图床托管程序,利用它我们可以轻松实现图片托管。默认情况下,Chevereto 的标题是不支持翻译的,如果我们想实现标题翻译,例如,在简体中文环境下,首页标题展示为 “夏日阳光 - 免费图片上传, 专业图片外链, 免费公共图床”,可以通过修改程序源码的方式来实现。

修改 Chevereto 网站标题并让标题支持翻译-图片1

一、首页

标题可以在仪表盘中自定义,如果想支持翻译,修改方法如下:

1、标题自定义

在 仪表盘/设置/网站 中自定义标题,将网站名称设置为 Pieruo,将网站标题设置为 “Pieruo image hosting”。

修改 Chevereto 网站标题并让标题支持翻译-图片2

2、让标题支持翻译

修改 head.php 文件,位置:/chevereto/app/routes/route.index.php,在末尾找到:

$handler::setVar('doctitle', CHV\Settings::get('website_doctitle'));
$handler::setVar('pre_doctitle', CHV\Settings::get('website_name'));

修改为:

$handler::setVar('doctitle', _s(CHV\Settings::get('website_doctitle')));
$handler::setVar('pre_doctitle', _s(CHV\Settings::get('website_name')));

这样,标题就支持翻译了。

3、添加翻译内容

修改 zh-CN.po.cache.php 文件,位置:/chevereto/app/content/languages/cache/zh-CN.po.cache.php,以简体中文环境为例,在 $translation_table 中添加下述翻译内容:

"Pieruo" => [
    0 => "夏日阳光",
],
"Pieruo image hosting" => [ 
    0 => "免费图片上传, 专业图片外链, 免费公共图床", 
],

其他语言环境类似,可根据实际情况自行添加翻译内容。

4、效果预览

通过以上三步,就可以实现标题自定义并支持翻译,默认显示 “Pieruo - Pieruo image hosting”,在简体中文环境下会翻译为 “夏日阳光 - 免费图片上传, 专业图片外链, 免费公共图床”。

修改 Chevereto 网站标题并让标题支持翻译-图片3

二、其他页面

按上述步骤操作后,发现只对首页有效果,首页除外的其他页面标题还是不支持翻译,可按下述方法修改:

1、修改方法

编辑 web.php 文件,位置:/chevereto/app/web.php,全局搜索:

getSetting('website_name')

统一替换为:

_s(getSetting('website_name'))

即可。

2、预览效果

以注册页面为例,预览效果如下:

修改 Chevereto 网站标题并让标题支持翻译-图片4

 

三、自定义页面

按上述步骤操作后,其他页面都 OK 了,但是自定义页面比较特殊,标题名称还是不支持翻译,比如 privacy 页面,如下图所示:

修改 Chevereto 网站标题并让标题支持翻译-图片5

让标题支持翻译,可按下述方法进行修改:

1、修改方法

编辑 route.page.php 文件,位置:/chevereto/app/routes/route.page.php,在末尾处找到:

$page_metas = [
    'pre_doctitle' => $page['title'],
    'meta_description' => htmlspecialchars($page['description']),
    'meta_keywords' => htmlspecialchars($page['keywords'])
];

修改为:

$page_metas = [
    'pre_doctitle' => _s($page['title']),
    'meta_description' => htmlspecialchars($page['description']),
    'meta_keywords' => htmlspecialchars($page['keywords'])
];

2、效果预览

修改后的预览效果如下:

修改 Chevereto 网站标题并让标题支持翻译-图片6

四、右上角独立页面菜单

右上角独立页面下拉菜单,可按下述方法进行修改:

1、修改方法

编辑 class.page.php 文件,位置:/chevereto/app/lib/classes/class.page.php,找到:

$page['title_html'] = '<span class="btn-icon ' . $page['icon'] . '"></span> ' . $page['title_html'];

修改为:

$page['title_html'] = '<span class="btn-icon ' . $page['icon'] . '"></span> ' . _s($page['title_html']);

2、效果预览

修改后的预览效果如下:

修改 Chevereto 网站标题并让标题支持翻译-图片7

结束语

本文简单整理了一下通过 Chevereto 程序搭建图床后,修改默认标题以及让标题支持翻译的方法,如果你也使用 Chevereto 图床程序托管图片,而且喜欢折腾的话,可以参考本文的方法进行修改。如果有任何意见或建议,欢迎在下方评论处留言。

本文已通过「原本」原创作品认证,转载请注明文章出处及链接。

夏日阳光
  • 本文由 夏日阳光 发表于 2022年4月28日
  • 本文为夏日阳光原创文章,转载请务必保留本文链接:https://www.pieruo.com/211.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证