diff --git a/application/common.php b/application/common.php
index 562f85de..41339c9c 100644
--- a/application/common.php
+++ b/application/common.php
@@ -42,33 +42,30 @@ function format_size($size, $array = false)
/**
* 格式化友好时间戳
*
- * @param $unixTime
* @return false|string
*/
-function format_time($unixTime)
+function format_time($remote, $local = null)
{
- $showTime = date('Y', $unixTime) . "年" . date('n', $unixTime) . "月" . date('j', $unixTime) . "日";
- if (date('Y', $unixTime) == date('Y')) {
- $showTime = date('n', $unixTime) . "月" . date('j', $unixTime) . "日 " . date('H:i', $unixTime);
- if (date('n.j', $unixTime) == date('n.j')) {
- $timeDifference = time() - $unixTime + 1;
- if ($timeDifference < 30) {
- return "刚刚";
- }
- if ($timeDifference >= 30 && $timeDifference < 60) {
- return $timeDifference . "秒前";
- }
- if ($timeDifference >= 60 && $timeDifference < 3600) {
- return floor($timeDifference / 60) . "分钟前";
- }
- return date('H:i', $unixTime);
- }
- if (date('n.j', ($unixTime + 86400)) == date('n.j')) {
- return "昨天 " . date('H:i', $unixTime);
+ $timediff = (is_null($local) || $local ? time() : $local) - $remote;
+ $chunks = array(
+ array(60 * 60 * 24 * 365, 'year'),
+ array(60 * 60 * 24 * 30, 'month'),
+ array(60 * 60 * 24 * 7, 'week'),
+ array(60 * 60 * 24, 'day'),
+ array(60 * 60, 'hour'),
+ array(60, 'minute'),
+ array(1, 'second')
+ );
+ $name = $count ='';
+ for ($i = 0, $j = count($chunks); $i < $j; $i++) {
+ $seconds = $chunks[$i][0];
+ $name = $chunks[$i][1];
+ if (($count = floor($timediff / $seconds)) != 0) {
+ break;
}
}
- return $showTime;
+ return lang("%s {$name}%s ago", [$count, ($count > 1 ? 's' : '')]);
}
/**
diff --git a/application/index/controller/Base.php b/application/index/controller/Base.php
index 97d84b55..f0ecd6c7 100644
--- a/application/index/controller/Base.php
+++ b/application/index/controller/Base.php
@@ -15,6 +15,8 @@ use PHPMailer\PHPMailer\PHPMailer;
use think\Controller;
use think\Exception;
use think\facade\Config;
+use think\facade\Cookie;
+use think\facade\Lang;
use think\facade\Session;
use think\facade\Env;
@@ -33,10 +35,16 @@ class Base extends Controller
$this->user = request()->user;
+ if ($this->request->has('lang')) {
+ Cookie::set('think_var', $this->request->get('lang'));
+ }
+
$this->assign([
'config' => $this->getConfig(),
'user' => $this->user,
- 'uri' => strtolower($this->request->controller() . '/' . $this->request->action())
+ 'uri' => strtolower($this->request->controller() . '/' . $this->request->action()),
+ 'lang' => Lang::range(),
+ 'languages' => json_encode(Lang::get()),
]);
}
diff --git a/application/index/view/admin/group/index.html b/application/index/view/admin/group/index.html
index aaf4a3fa..43c283c8 100644
--- a/application/index/view/admin/group/index.html
+++ b/application/index/view/admin/group/index.html
@@ -1,6 +1,6 @@
{extend name="common:base" /}
-{block name="title"}角色组 - {$config.site_name}{/block}
+{block name="title"}{:lang('Role group')} - {$config.site_name}{/block}
{block name="main"}
@@ -8,7 +8,7 @@
- 不同的角色组下的用户,上传图片将使用不同的储存策略。
至少有一个默认角色组,新注册用户和访客将会使用默认的角色组。
角色组删除后,该组下面的用户将重置默认角色组。
+ {:lang('Role group tips')}
@@ -17,10 +17,10 @@
- | 使用策略 |
- 名称 |
- 注册默认 |
- 操作 |
+ {:lang('Strategy used')} |
+ {:lang('Name')} |
+ {:lang('Register default')} |
+ {:lang('Operation')} |
@@ -42,8 +42,8 @@
-
-
+
+
|
@@ -56,13 +56,13 @@
@@ -86,13 +86,13 @@
@@ -128,9 +128,9 @@
var editDialog = new mdui.Dialog('#edit-dialog');
var methods = {
delete: function (id, batch, callback) {
- var msg = '确认删除该角色组吗?';
+ var msg = lang('Are you sure to delete this role group?');
if (batch) {
- msg = '确认删除选中项角色组吗?';
+ msg = lang('Are you sure to delete the selected item role group?');
}
mdui.confirm(msg, function () {
app.request("{:url('admin/group/del')}", {id: id}, function () {
@@ -138,7 +138,7 @@
});
}, function () {
- }, {confirmText: '确定', cancelText: '取消'});
+ }, {confirmText: lang('Confirm'), cancelText: lang('Cancel')});
},
};
// 编辑提交
diff --git a/application/index/view/admin/images/index.html b/application/index/view/admin/images/index.html
index e1d1044e..77830622 100644
--- a/application/index/view/admin/images/index.html
+++ b/application/index/view/admin/images/index.html
@@ -1,6 +1,6 @@
{extend name="common:base" /}
-{block name="title"}图片管理 - {$config.site_name}{/block}
+{block name="title"}{:lang('Picture management')} - {$config.site_name}{/block}
{block name="css"}
@@ -11,22 +11,22 @@
-
共有 {$images->total()} 张图片
+
{:lang('There are %s pictures in total', [''.$images->total().''])}
diff --git a/application/index/view/admin/system/console.html b/application/index/view/admin/system/console.html
index f38fc671..331e052b 100644
--- a/application/index/view/admin/system/console.html
+++ b/application/index/view/admin/system/console.html
@@ -1,6 +1,6 @@
{extend name="common:base" /}
-{block name="title"}控制台 - {$config.site_name}{/block}
+{block name="title"}{:lang('Console')} - {$config.site_name}{/block}
{block name="main"}
@@ -10,7 +10,7 @@
-
占用储存
+
{:lang('Occupied storage')}
{$storage[0]}
{if $storage[0]}{$storage[1]}{else/}Kb{/if}
@@ -18,44 +18,44 @@
-
图片数量
-
{$images_num} 张
+
{:lang('Number of pictures')}
+
{$images_num} {:lang('Zhang')}
-
可疑图片
-
{$suspicious_images_num} 张
+
{:lang('Suspicious picture')}
+
{$suspicious_images_num} {:lang('Zhang')}
-
用户数量
-
{$users_num} 个
+
{:lang('Number of users')}
+
{$users_num} {:lang('Ge')}
-
今日上传
-
{$today} 张
+
{:lang('Upload today')}
+
{$today} {:lang('Zhang')}
-
昨日上传
-
{$yesterday} 张
+
{:lang('Uploaded yesterday')}
+
{$yesterday} {:lang('Zhang')}
-
本月上传
-
{$month} 张
+
{:lang('Upload this month')}
+
{$month} {:lang('Zhang')}
-
游客上传
-
{$tourists} 张
+
{:lang('Visitor upload')}
+
{$tourists} {:lang('Zhang')}
@@ -64,22 +64,22 @@
- | 系统配置 |
+ {:lang('System configuration')} |
- | 操作系统: |
+ {:lang('Operating system')}: |
{:php_uname('s')} |
- 服务器 IP: |
+ {:lang('Server IP:')} |
{:GetHostByName($Think.server.http_host)} |
- 网站域名: |
+ {:lang('Website domain name:')} |
{$Think.server.http_host} |
- | 运行环境: |
+ {:lang('Operating environment:')} |
{$Think.server.server_software} |
- PHP 版本: |
+ {:lang('PHP version:')} |
{$Think.PHP_VERSION} |
- 文件上传限制: |
+ {:lang('File upload restrictions:')} |
{:ini_get('upload_max_filesize')} |
@@ -89,22 +89,22 @@
- | 软件信息 |
+ {:lang('Software information')} |
- | 软件版本: |
+ {:lang('Software version:')} |
v{$config.system_version} |
- | 使用手册: |
+ {:lang('User manual:')} |
https://www.kancloud.cn/wispx/lsky-pro/content |
- | 仓库地址: |
+ {:lang('Warehouse address:')} |
https://github.com/wisp-x/lsky-pro |
- | 联系作者: |
+ {:lang('Contact author:')} |
i@wispx.cn |
diff --git a/application/index/view/admin/system/index.html b/application/index/view/admin/system/index.html
index 9761585e..2a040347 100644
--- a/application/index/view/admin/system/index.html
+++ b/application/index/view/admin/system/index.html
@@ -1,6 +1,6 @@
{extend name="common:base" /}
-{block name="title"}系统管理 - {$config.site_name}{/block}
+{block name="title"}{:lang('System management')} - {$config.site_name}{/block}
{block name="main"}
@@ -9,18 +9,17 @@
- 系统配置,统计代码中注意要使用<script></script>标签,不设置可为空。
- 基础配置如果出现无法保存的情况请检查请求是否被防火墙拦截。
+ {:lang('System management tips')}
{foreach $configs as $key => $value}
@@ -28,7 +27,7 @@
@@ -70,9 +69,9 @@
- | 变量名 |
- 示例 |
- 说明 |
+ {:lang('Variable name')} |
+ {:lang('Example')} |
+ {:lang('Explain')} |
@@ -94,9 +93,9 @@
- | 变量名 |
- 示例 |
- 说明 |
+ {:lang('Variable name')} |
+ {:lang('Example')} |
+ {:lang('Explain')} |
@@ -128,7 +127,7 @@
});
$('#test-send-mail').click(function () {
- mdui.prompt('请输入邮箱',
+ mdui.prompt(lang('Please input email'),
function (value) {
app.request("{:url('admin/system/testMail')}", {email: value});
},
@@ -136,8 +135,8 @@
},
{
- confirmText: '确定',
- cancelText: '取消'
+ confirmText: lang('Confirm'),
+ cancelText: lang('Cancel')
}
);
});
diff --git a/application/index/view/admin/users/index.html b/application/index/view/admin/users/index.html
index 7449a798..b26c6949 100644
--- a/application/index/view/admin/users/index.html
+++ b/application/index/view/admin/users/index.html
@@ -1,39 +1,39 @@
{extend name="common:base" /}
-{block name="title"}用户管理 - {$config.site_name}{/block}
+{block name="title"}{:lang('User management')} - {$config.site_name}{/block}
{block name="main"}
-
共有 {$users->total()} 个用户
-
+
{:lang('There are %s users in total', [''.$users->total().''])}
+
- | 用户名 |
- 角色组 |
- 昵称 |
- 邮箱 |
- 已使用容量 |
- 总容量 |
- 账号状态 |
- 注册IP |
- 操作 |
+ {:lang('User name')} |
+ {:lang('Role group')} |
+ {:lang('Nickname')} |
+ {:lang('Email')} |
+ {:lang('Used capacity')} |
+ {:lang('Total capacity')} |
+ {:lang('Account status')} |
+ {:lang('Register IP')} |
+ {:lang('Operation')} |
@@ -53,15 +53,15 @@
{$value.quota|format_size} |
|
{$value.reg_ip} |
-
-
+
+
|
@@ -76,39 +76,39 @@
@@ -134,9 +134,9 @@
@@ -36,15 +36,23 @@
{/if}
+
+
+
{if cookie('theme') eq 'dark'}{else/}{/if}
@@ -57,48 +65,48 @@
- 首页
+ {:lang('Home')}
{if $config.open_gallery}
- 画廊
+ {:lang('Gallery')}
{/if}
{if $config.open_api}
- 接口
+ {:lang('Api')}
{/if}
{if $user}
- 我的图片
+ {:lang('My picture')}
- 设置
+ {:lang('Setting')}
{if $user.is_admin}
{/if}
@@ -139,10 +147,11 @@
Copyright © 2018 - present
Lsky Pro. All rights reserved.
{if $config.icp_number}
{$config.icp_number}.{/if}
- 请勿上传违反中国大陆和香港法律的图片,违者后果自负。
+ {:lang('Footer tip')}
{/block}
+
diff --git a/application/index/view/index/gallery.html b/application/index/view/index/gallery.html
index ad74602c..fa5c0e25 100644
--- a/application/index/view/index/gallery.html
+++ b/application/index/view/index/gallery.html
@@ -1,6 +1,6 @@
{extend name="common:base" /}
-{block name="title"}画廊 - {$config.site_name}{/block}
+{block name="title"}{:lang('Gallery')} - {$config.site_name}{/block}
{block name="css"}
@@ -43,7 +43,7 @@
{/foreach}
-
+
{/block}
@@ -64,12 +64,12 @@
$more.click(function () {
if (loading) return;
loading = true;
- $more.attr('disabled', true).text("加载中...");
+ $more.attr('disabled', true).text(lang('Loading...'));
app.ajax("", {page: page, limit: limit}, function (response) {
if (response.code) {
var data = response.data;
if (data.length === 0) {
- $more.text("我也是有底线的~");
+ $more.text(lang('No more'));
} else {
var html = '';
for (var key in data) {
@@ -89,9 +89,9 @@
$viewer.data('viewer').update();
loading = false;
if (data.length < limit) {
- $more.text("我也是有底线的~");
+ $more.text(lang('No more'));
} else {
- $more.attr('disabled', false).text("查看更多");
+ $more.attr('disabled', false).text(lang('See more'));
page++;
}
}
@@ -99,4 +99,4 @@
});
});
-{/block}
\ No newline at end of file
+{/block}
diff --git a/application/index/view/index/home.html b/application/index/view/index/home.html
index 7bd93917..d921b037 100644
--- a/application/index/view/index/home.html
+++ b/application/index/view/index/home.html
@@ -16,9 +16,9 @@
SIGN IN
-
-
-
+
+
+