Skip to content

Commit

Permalink
加入了多语言支持和英文
Browse files Browse the repository at this point in the history
1. 后台主题设置加入了语言设置
2. inc/helpers.php 加入了几个语言设置和根据语言格式化日期的函数
3. 网站界面内容显示从之前的硬编码改为读取语言翻译文件输出
4. 调整了统计页的一些图表样式
5. 新增 languages/en.php 和 languages/zh.php 英文和中文的翻译文件
  • Loading branch information
changbin1997 committed Jan 9, 2025
1 parent 0e2f1c1 commit a0bff5b
Show file tree
Hide file tree
Showing 23 changed files with 885 additions and 281 deletions.
11 changes: 7 additions & 4 deletions 404.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$GLOBALS['page'] = '404';

// 语言初始化
languageInit($this->options->language);
$this->need('components/header.php');
?>

<div id="main">
<div class="container container-404 main-content">
<h1>404</h1>
<h2 role="alert" class="mb-5">您访问的页面不存在!</h2>
<h2 role="alert" class="mb-5"><?php echo $GLOBALS['t']['page404']['thePageYouAreLookingForDoesNotExist']; ?></h2>
<div class="search-box row">
<div class="col-lg-6 col-md-8 col-sm-10 col-12 offset-lg-3 offset-md-2 offset-sm-1">
<form action="<?php $this->options->siteUrl(); ?>" method="post" role="search">
<div class="input-group">
<input type="search" class="form-control form-control-md" placeholder="搜索" aria-label="搜索" aria-describedby="button-addon2" required="required" name="s">
<input type="search" class="form-control form-control-md" placeholder="<?php echo $GLOBALS['t']['header']['search']; ?>" aria-label="<?php echo $GLOBALS['t']['header']['search']; ?>" aria-describedby="button-addon2" required="required" name="s">
<div class="input-group-append">
<button type="submit" class="search-btn btn btn-md" aria-label="搜索" title="搜索" data-toggle="tooltip" data-placement="top">
<button type="submit" class="search-btn btn btn-md" aria-label="<?php echo $GLOBALS['t']['header']['search']; ?>" title="<?php echo $GLOBALS['t']['header']['search']; ?>" data-toggle="tooltip" data-placement="top">
<span class="icon-search"></span>
</button>
</div>
Expand All @@ -22,7 +25,7 @@
</div>
</div>
<div class="text-center">
<a href="<?php $this->options->siteUrl(); ?>" class="btn to-home-link">回到首页</a>
<a href="<?php $this->options->siteUrl(); ?>" class="btn to-home-link"><?php echo $GLOBALS['t']['page404']['goBackToHomepage']; ?></a>
</div>
</div>
</div>
Expand Down
27 changes: 15 additions & 12 deletions archive.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$GLOBALS['page'] = 'archive';

// 语言初始化
languageInit($this->options->language);
$this->need('components/header.php');
?>

<div id="main">
<div class="container main-content">
<?php if ($this->options->breadcrumb == 'on'): ?>
<nav aria-label="路径" class="breadcrumb-nav">
<nav aria-label="<?php echo $GLOBALS['t']['breadcrumb']; ?>" class="breadcrumb-nav">
<ol class="breadcrumb m-0 p-0">
<li class="breadcrumb-item">
<a href="<?php $this->options->siteUrl(); ?>">首页</a>
<a href="<?php $this->options->siteUrl(); ?>"><?php echo $GLOBALS['t']['header']['home']; ?></a>
</li>
<li tabindex="0" class="breadcrumb-item active" aria-current="page"><?php $this->archiveTitle(' &raquo; ','',''); ?></li>
</ol>
Expand All @@ -21,10 +24,10 @@
<header class="page-header mwordstar-block">
<h1 class="archive-title">
<?php $this->archiveTitle(array(
'category' => _t('分类 %s 下的文章'),
'search' => _t('包含关键字 %s 的文章'),
'tag' => _t('标签 %s 下的文章'),
'author' => _t('%s 发布的文章')
'category' => $GLOBALS['t']['archive']['postsUnderTheCategory'],
'search' => $GLOBALS['t']['archive']['postsContainingTheKeyword'],
'tag' => $GLOBALS['t']['archive']['postsTagged'],
'author' => $GLOBALS['t']['archive']['postsByAuthor']
), '', ''); ?>
</h1>
<span><?php echo $this->getDescription(); ?></span>
Expand All @@ -33,17 +36,17 @@
<?php $this->need('components/post-list.php'); ?>
<?php else: ?>
<article class="post no-post mwordstar-block">
<h4 class="post-title" role="alert">无法查找到包含 <b><?php $this->archiveTitle(array('search' => '%s'), '', ''); ?></b> 的文章!</h4 >
<p class="ml-4">您可以尝试:</p>
<h4 class="post-title" role="alert"><?php printf($GLOBALS['t']['archive']['noPostsFoundContaining'], '<b>' . $this->archiveTitle . '</b>') ?></h4 >
<p class="ml-4"><?php echo $GLOBALS['t']['archive']['youCanTryTheFollowing']; ?></p>
<ol class="ml-1 mb-4">
<li>更换关键字重新搜索</li>
<li>在右侧或下方的文章分类区域选择分类查找</li>
<li>在右侧或下方的标签云区域选择标签查找</li>
<li><?php echo $GLOBALS['t']['archive']['trySearchingWithDifferentKeywords']; ?></li>
<li><?php echo $GLOBALS['t']['archive']['browsePostsByCategoryInTheSectionToTheRightOrBelow']; ?></li>
<li><?php echo $GLOBALS['t']['archive']['browsePostsByTagsInTheTagCloudSectionToTheRightOrBelow']; ?></li>
</ol>
</article>
<?php endif; ?>
</div>
<nav aria-label="分页导航区" class="pagination-nav">
<nav aria-label="<?php echo $GLOBALS['t']['pagination']['pagination']; ?>" class="pagination-nav">
<?php $this->pageNav('<i class="icon-chevron-left"></i>', '<i class="icon-chevron-right"></i>', 1, '...', array('wrapTag' => 'ul', 'wrapClass' => 'pagination justify-content-center', 'itemTag' => 'li', 'textTag' => 'a', 'currentClass' => 'active', 'prevClass' => 'prev', 'nextClass' => 'next')); ?>
</nav>
</div>
Expand Down
68 changes: 36 additions & 32 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ $(function () {
id="directory-btn"
class="btn rounded-circle d-block d-sm-block d-md-block d-lg-none d-xl-none"
aria-expanded="false"
aria-label="目录" title="目录"
aria-label="${window.t.tableOfContents}" title="${window.t.tableOfContents}"
>
<i class="icon-list-ol"></i>
</button>
Expand Down Expand Up @@ -546,15 +546,16 @@ $(function () {

// 文章是否有密码
if ($('.post-content .protected').length) {
$('.protected .word').attr('role', 'alert'); // 让读屏软件朗读输入密码的提示
$('.protected .text').attr('placeholder', '请在此处输入文章密码');
$('.protected .text').get(0).select(); // 让密码输入表单获取交点
$('input[name="protectPassword"]').attr('placeholder', window.t.enterYourPassword);
$('input[name="protectPassword"]').focus();
$('.protected .submit').val(window.t.submit);
$('.protected .word').html(window.t.enterThePasswordToViewIt);
}

// 给文章信息的分类链接添加 title
if ($('.article-info .icon-folder-open').length) {
$('.article-info .icon-folder-open').nextAll().attr({
'title': '分类',
'title': window.t.category,
'data-toggle': 'tooltip',
'data-placement': 'top'
});
Expand All @@ -564,7 +565,7 @@ $(function () {
// 给文章信息的标签链接添加 title
if ($('.tags a').length) {
$('.tags a').attr({
'title': '标签',
'title': window.t.tag,
'data-toggle': 'tooltip',
'data-placement': 'top'
});
Expand All @@ -582,7 +583,7 @@ $(function () {
const authorName = $(this).closest('.comment-box').find('.author a').text() ||
$(this).closest('.comment-box').find('.author').text();
$(this).find('a').attr({
title: `回复 ${authorName}`,
title: `${window.t.replyTo} ${authorName}`,
'data-toggle': 'tooltip',
'data-placement': 'top'
});
Expand Down Expand Up @@ -610,6 +611,9 @@ $(function () {
}
});

// 设置取消回复链接的链接名称
$('#cancel-comment-reply-link').html(window.t.cancelReply);

// 把父评论的姓名加入到子评论中
if ($('#comments .parent').length) {
for (let i = 0; i < $('#comments .parent').length; i++) {
Expand All @@ -629,7 +633,7 @@ $(function () {

// 给评论区的作者链接加入用于屏幕阅读器的描述
$('.author-tag').each(function() {
$(this).closest('.comment-info').find('.author a').attr('title', '作者');
$(this).closest('.comment-info').find('.author a').attr('title', window.t.author);
});
}

Expand Down Expand Up @@ -713,7 +717,7 @@ $(function () {
// 设置类型标题
$('#emoji-title').html($(ev.target).attr('title'));
// 设置用于屏幕阅读器的表情列表标题
$('#emoji-list').attr('aria-label', `${$(ev.target).attr('title')}(按回车可以把表情添加到评论内容输入框)`);
$('#emoji-list').attr('aria-label', `${$(ev.target).attr('title')} ${window.t.pressEnterToAddTheEmojiToTheCommentInputField}`);
});

// Emoji 表情点击
Expand Down Expand Up @@ -770,7 +774,7 @@ $(function () {
const re = /\d/;
if (re.test(data)) {
$('#agree-btn .agree-num').html(data);
$('.post-page').append('<span id="agree-p" role="alert"> + 1</span>');
$('.post-page').append(`<span id="agree-p" role="alert">${window.t.like} + 1</span>`);
$('#agree-p').css({
top: $('#agree-btn').offset().top - 25,
left: $('#agree-btn').offset().left + $('#agree-btn').outerWidth() / 2 - $('#agree-p').outerWidth() / 2
Expand Down Expand Up @@ -864,14 +868,14 @@ $(function () {
$('.pagination-nav ul li a').addClass('page-link');
// 给上一页和下一页加入文字提示
$('.pagination-nav .prev a').attr({
'aria-label': '上一页',
'title': '上一页(左光标键)',
'aria-label': window.t.previousPage,
'title': window.t.previousPage,
'data-toggle': 'tooltip',
'data-placement': 'top'
});
$('.pagination-nav .next a').attr({
'aria-label': '下一页',
'title': '下一页(右光标键)',
'aria-label': window.t.nextPage,
'title': window.t.nextPage,
'data-toggle': 'tooltip',
'data-placement': 'top'
});
Expand Down Expand Up @@ -934,20 +938,20 @@ $(function () {
<div class="mask-layer"></div>
<img src="" alt="" class="shadow-lg">
<p id="img-info" class="text-light text-center"></p>
<div class="btn-group" role="group" aria-label="图片工具栏" id="img-control">
<button type="button" class="btn big" title="放大" aria-label="放大">
<div class="btn-group" role="group" id="img-control">
<button type="button" class="btn big" title="${window.t.zoomIn}" aria-label="${window.t.zoomIn}">
<i class="icon-zoom-in"></i>
</button>
<button type="button" class="btn small" title="缩小" aria-label="缩小">
<button type="button" class="btn small" title="${window.t.zoomOut}" aria-label="${window.t.zoomOut}">
<i class="icon-zoom-out"></i>
</button>
<button type="button" class="btn spin-left" title="左旋转90度" aria-label="左旋转90度">
<button type="button" class="btn spin-left" title="${window.t.rotateLeft}" aria-label="${window.t.rotateLeft}">
<i class="icon-undo"></i>
</button>
<button type="button" class="btn spin-right" title="右旋转90度" aria-label="右旋转90度">
<button type="button" class="btn spin-right" title="${window.t.rotateRight}" aria-label="${window.t.rotateRight}">
<i class="icon-redo"></i>
</button>
<button type="button" class="btn hide-img" title="关闭大图(ESC)" aria-label="关闭大图(ESC)">
<button type="button" class="btn hide-img" title="${window.t.closeImage}" aria-label="${window.t.closeImage}">
<i class="icon-cancel-circle"></i>
</button>
</div>
Expand Down Expand Up @@ -1188,8 +1192,8 @@ $(function () {
btnEl.setAttribute('type', 'button');
btnEl.innerHTML = '<i class="icon-copy"></i>';
btnEl.setAttribute('data-clipboard-target', `#code-${i}`);
btnEl.setAttribute('title', '拷贝代码');
btnEl.setAttribute('aria-label', '拷贝代码');
btnEl.setAttribute('title', window.t.copyCode);
btnEl.setAttribute('aria-label', window.t.copyCode);
btnEl.setAttribute('data-toggle', 'tooltip');
btnEl.setAttribute('data-placement', 'left');
btnEl.setAttribute('id', `copy-btn-${i}`);
Expand All @@ -1202,25 +1206,25 @@ $(function () {
// 拷贝成功
clipboard.on('success', function(ev) {
// 把工具提示更改为拷贝成功
$(ev.trigger).attr('title', '拷贝成功');
$(ev.trigger).attr('data-original-title', '拷贝成功');
$(ev.trigger).attr('title', window.t.copySuccess);
$(ev.trigger).attr('data-original-title', window.t.copySuccess);
$(ev.trigger).tooltip('update');
$(ev.trigger).tooltip('show');
// 延迟 1 秒后把工具提示更改为拷贝代码
setTimeout(() => {
$(ev.trigger).attr('title', '拷贝代码');
$(ev.trigger).attr('data-original-title', '拷贝代码');
$(ev.trigger).attr('title', window.t.copyCode);
$(ev.trigger).attr('data-original-title', window.t.copyCode);
}, 1000);
});
// 拷贝出错
clipboard.on('error', ev => {
$(ev.trigger).attr('title', '拷贝失败');
$(ev.trigger).attr('data-original-title', '拷贝失败');
$(ev.trigger).attr('title', window.t.copyError);
$(ev.trigger).attr('data-original-title', window.t.copyError);
$(ev.trigger).tooltip('hide');
$(ev.trigger).tooltip('show');
setTimeout(function() {
$(ev.trigger).attr('title', '拷贝代码');
$(ev.trigger).attr('data-original-title', '拷贝代码');
$(ev.trigger).attr('title', window.t.copyCode);
$(ev.trigger).attr('data-original-title', window.t.copyCode);
}, 1000);
});
}
Expand All @@ -1244,11 +1248,11 @@ $(function () {
if ($('.dark-color').length) {
$('#change-color-btn i').removeClass('icon-sun');
$('#change-color-btn i').addClass('icon-moon');
$('#change-color-btn').attr('title', '当前为深色模式,点击可切换为浅色模式');
$('#change-color-btn').attr('title', window.t.switchToLightMode);
}else {
$('#change-color-btn i').removeClass('icon-moon');
$('#change-color-btn i').addClass('icon-sun');
$('#change-color-btn').attr('title', '当前为浅色模式,点击可切换为深色模式');
$('#change-color-btn').attr('title', window.t.switchToDarkMode);
}
$('#change-color-btn').attr('data-original-title', $('#change-color-btn').attr('title'));
$('#change-color-btn').tooltip('update');
Expand Down
2 changes: 1 addition & 1 deletion assets/js/chart.js

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions assets/js/options-panel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.addEventListener('load', () => {
const title = [
'外观', '站点信息', '辅助功能', '链接调转',
'语言', '外观', '站点信息', '辅助功能', '链接调转',
'侧边栏', '文章列表', '文章头图', '文章内容区域',
'评论区', '导航', '友情链接', 'PJAX', '开发者'
];
Expand Down Expand Up @@ -31,19 +31,20 @@ window.addEventListener('load', () => {
});

// 插入分组标题
optionForm.insertBefore(titleEl[0], optionUl[0]); // 外观
optionForm.insertBefore(titleEl[1], optionUl[4]); // 站点信息
optionForm.insertBefore(titleEl[2], optionUl[7]); // 辅助功能
optionForm.insertBefore(titleEl[3], optionUl[8]); // 链接跳转
optionForm.insertBefore(titleEl[4], optionUl[11]); // 侧边栏
optionForm.insertBefore(titleEl[5], optionUl[25]); // 文章列表
optionForm.insertBefore(titleEl[6], optionUl[27]); // 文章头图
optionForm.insertBefore(titleEl[7], optionUl[31]); // 文章内容相关
optionForm.insertBefore(titleEl[8], optionUl[39]); // 评论区
optionForm.insertBefore(titleEl[9], optionUl[44]); // 导航栏
optionForm.insertBefore(titleEl[10], optionUl[49]); // 友情链接
optionForm.insertBefore(titleEl[11], optionUl[52]); // PJAX
optionForm.insertBefore(titleEl[12], optionUl[56]); // 开发者
optionForm.insertBefore(titleEl[0], optionUl[0]); // 语言
optionForm.insertBefore(titleEl[1], optionUl[1]); // 外观
optionForm.insertBefore(titleEl[2], optionUl[5]); // 站点信息
optionForm.insertBefore(titleEl[3], optionUl[8]); // 辅助功能
optionForm.insertBefore(titleEl[4], optionUl[9]); // 链接跳转
optionForm.insertBefore(titleEl[5], optionUl[12]); // 侧边栏
optionForm.insertBefore(titleEl[6], optionUl[26]); // 文章列表
optionForm.insertBefore(titleEl[7], optionUl[28]); // 文章头图
optionForm.insertBefore(titleEl[8], optionUl[32]); // 文章内容相关
optionForm.insertBefore(titleEl[9], optionUl[40]); // 评论区
optionForm.insertBefore(titleEl[10], optionUl[45]); // 导航栏
optionForm.insertBefore(titleEl[11], optionUl[50]); // 友情链接
optionForm.insertBefore(titleEl[12], optionUl[53]); // PJAX
optionForm.insertBefore(titleEl[13], optionUl[57]); // 开发者

// 插入分隔线
titleEl.forEach(el => {
Expand Down
Loading

0 comments on commit a0bff5b

Please sign in to comment.