Skip to content

Commit f5bb4da

Browse files
committed
优化语言标识获取判断
1 parent b62f656 commit f5bb4da

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "addons package for fastadmin",
44
"homepage": "https://github.com/karsonzhang/fastadmin-addons",
55
"license": "Apache-2.0",
6-
"version": "1.3.2",
6+
"version": "1.3.3",
77
"authors": [
88
{
99
"name": "Karson",

src/addons/Controller.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ protected function _initialize()
106106
$config = get_addon_config($this->addon);
107107
$this->view->assign("config", $config);
108108

109+
$lang = $this->request->langset();
110+
$lang = preg_match("/^([a-zA-Z\-_]{2,10})\$/i", $lang) ? $lang : 'zh-cn';
111+
109112
// 加载系统语言包
110113
Lang::load([
111-
ADDON_PATH . $this->addon . DS . 'lang' . DS . $this->request->langset() . EXT,
114+
ADDON_PATH . $this->addon . DS . 'lang' . DS . $lang . EXT,
112115
]);
113116

114117
// 设置替换字符串

src/addons/Service.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ public static function download($name, $extend = [])
8989
}
9090
}
9191
} catch (TransferException $e) {
92-
throw new Exception(config('app_debug') ? $e->getMessage() : "Addon package download failed");
92+
throw new Exception("Addon package download failed");
9393
}
9494

9595
if ($write = fopen($tmpFile, 'w')) {
9696
fwrite($write, $content);
9797
fclose($write);
9898
return $tmpFile;
9999
}
100-
throw new Exception(config('app_debug') && isset($content) ? $content : "No permission to write temporary files");
100+
throw new Exception("No permission to write temporary files");
101101
}
102102

103103
/**
@@ -121,7 +121,7 @@ public static function unzip($name)
121121
$zip->openFile($file);
122122
} catch (ZipException $e) {
123123
$zip->close();
124-
throw new Exception(config('app_debug') ? $e->getMessage() : 'Unable to open the zip file');
124+
throw new Exception('Unable to open the zip file');
125125
}
126126

127127
$dir = self::getAddonDir($name);
@@ -133,7 +133,7 @@ public static function unzip($name)
133133
try {
134134
$zip->extractTo($dir);
135135
} catch (ZipException $e) {
136-
throw new Exception(config('app_debug') ? $e->getMessage() : 'Unable to extract the file');
136+
throw new Exception('Unable to extract the file');
137137
} finally {
138138
$zip->close();
139139
}
@@ -1121,9 +1121,9 @@ public static function sendRequest($url, $params = [], $method = 'POST')
11211121
$content = $body->getContents();
11221122
$json = (array)json_decode($content, true);
11231123
} catch (TransferException $e) {
1124-
throw new Exception(config('app_debug') ? $e->getMessage() : __('Network error'));
1124+
throw new Exception(__('Network error'));
11251125
} catch (\Exception $e) {
1126-
throw new Exception(config('app_debug') ? $e->getMessage() : __('Unknown data format'));
1126+
throw new Exception(__('Unknown data format'));
11271127
}
11281128
return $json;
11291129
}

0 commit comments

Comments
 (0)