From d36ac3643b1f2dac82381301bc71d5658590580e Mon Sep 17 00:00:00 2001 From: gplane Date: Sun, 1 Jan 2017 12:22:18 +0800 Subject: [PATCH] working on i18n of update --- app/Http/Controllers/UpdateController.php | 23 ++++++++++++----------- resources/lang/en/admin.yml | 9 +++++++++ resources/lang/en/options.yml | 9 +++++++++ resources/lang/zh_CN/admin.yml | 9 +++++++++ resources/lang/zh_CN/options.yml | 9 +++++++++ 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/UpdateController.php b/app/Http/Controllers/UpdateController.php index 6b6e701b..0378cf1e 100644 --- a/app/Http/Controllers/UpdateController.php +++ b/app/Http/Controllers/UpdateController.php @@ -8,6 +8,7 @@ use Utils; use Option; use ZipArchive; use App\Services\Storage; +use App\Services\OptionForm; use Illuminate\Http\Request; class UpdateController extends Controller @@ -66,16 +67,16 @@ class UpdateController extends Controller } } - $update = Option::form('update', '更新选项', function($form) + $update = Option::form('update', OptionForm::AUTO_DETECT, function($form) { - $form->checkbox('check_update', '检查更新')->label('自动检查更新并提示'); - $form->text('update_source', '更新源') - ->description('可用的更新源列表可以在这里查看:@GitHub Wiki'); + $form->checkbox('check_update', OptionForm::AUTO_DETECT)->label(OptionForm::AUTO_DETECT); + $form->text('update_source', OptionForm::AUTO_DETECT) + ->description(OptionForm::AUTO_DETECT); })->handle()->always(function($form) { try { $response = file_get_contents(option('update_source')); } catch (\Exception $e) { - $form->addMessage('无法访问当前更新源。详细信息:'.$e->getMessage(), 'danger'); + $form->addMessage(trans('admin.update.errors.connection').$e->getMessage(), 'danger'); } }); @@ -114,7 +115,7 @@ class UpdateController extends Controller if (!is_dir($update_cache)) { if (false === mkdir($update_cache)) { - exit('创建下载缓存文件夹失败,请检查目录权限。'); + exit(trans('admin.update.errors.write-permission')); } } @@ -136,7 +137,7 @@ class UpdateController extends Controller } catch (\Exception $e) { Storage::remove($tmp_path); - exit('发生错误:'.$e->getMessage()); + exit(trans('admin.update.errors.prefix').$e->getMessage()); } return json(compact('tmp_path')); @@ -168,18 +169,18 @@ class UpdateController extends Controller try { $zip->extractTo($extract_dir); } catch (\Exception $e) { - exit('发生错误:'.$e->getMessage()); + exit(trans('admin.update.errors.prefix').$e->getMessage()); } } else { - exit('更新包解压缩失败。错误代码:'.$res); + exit(trans('admin.update.errors.unzip').$res); } $zip->close(); if (Storage::copyDir($extract_dir, base_path()) !== true) { Storage::removeDir(storage_path('update_cache')); - exit('无法覆盖文件。'); + exit(trans('admin.update.errors.overwrite')); } else { @@ -189,7 +190,7 @@ class UpdateController extends Controller Log::info("[Extracter] Cleaning cache"); } - return json('更新完成', 0); + return json(trans('admin.update.complete'), 0); break; diff --git a/resources/lang/en/admin.yml b/resources/lang/en/admin.yml index 7161b8d3..36b101f2 100644 --- a/resources/lang/en/admin.yml +++ b/resources/lang/en/admin.yml @@ -113,6 +113,8 @@ plugins: empty: No result update: + complete: Update completed + info: title: Update Information @@ -147,3 +149,10 @@ update: download: downloading: Downloading update package... size: "Size of package:" + + errors: + prefix: "An error occured: " + connection: "Unable to access to current update source. Details:" + write-permission: Unable to make cache directory. Please sure permission. + unzip: "Failed to unzip update file. Error code: " + overwrite: Unable to overwrite files. diff --git a/resources/lang/en/options.yml b/resources/lang/en/options.yml index 8314df08..54f1f1fb 100644 --- a/resources/lang/en/options.yml +++ b/resources/lang/en/options.yml @@ -106,3 +106,12 @@ return_200_when_notfound: cache_expire_time: title: Cache Exipre Time hint: In seconds, 86400 = one day, 31536000 = one year + +update: + title: Check Update +check_update: + title: Check Update + label: Check update automatically and notify me. +update_source: + title: Update Source + description: 'Available update source list can be found at: @GitHub Wiki' diff --git a/resources/lang/zh_CN/admin.yml b/resources/lang/zh_CN/admin.yml index de1c9d17..01651eac 100644 --- a/resources/lang/zh_CN/admin.yml +++ b/resources/lang/zh_CN/admin.yml @@ -113,6 +113,8 @@ plugins: empty: 无结果 update: + complete: 更新完成 + info: title: 更新信息 @@ -147,3 +149,10 @@ update: download: downloading: 正在下载更新包 size: 更新包大小: + + errors: + prefix: 发生错误: + connection: 无法访问当前更新源。详细信息: + write-permission: 创建下载缓存文件夹失败,请检查目录权限。 + unzip: 更新包解压缩失败。错误代码: + overwrite: 无法覆盖文件。 diff --git a/resources/lang/zh_CN/options.yml b/resources/lang/zh_CN/options.yml index a570328e..c9e23fbc 100644 --- a/resources/lang/zh_CN/options.yml +++ b/resources/lang/zh_CN/options.yml @@ -106,3 +106,12 @@ return_200_when_notfound: cache_expire_time: title: 缓存失效时间 hint: 秒数,86400 = 一天,31536000 = 一年 + +update: + title: 更新选项 +check_update: + title: 检查更新 + label: 自动检查更新并提示 +update_source: + title: 更新源 + description: 可用的更新源列表可以在这里查看:@GitHub Wiki