Feature: multi language (VI, EN, JA)

CR: sonh (fake)
This commit is contained in:
2021-08-23 15:19:49 +07:00
parent 7057e5b35c
commit eb88996797
37 changed files with 788 additions and 327 deletions

View File

@@ -15,9 +15,13 @@ use app\models\ListManagement;
*/
class CaptureLogsController extends Controller {
/**
* {@inheritdoc}
*/
public function init() {
parent::init();
Yii::$app->language = Yii::$app->session->get("language") ? Yii::$app->session->get("language")["name"] : "vi-VI";
if (Yii::$app->user->isGuest)
return $this->redirect(['/site/login']);
}
public function behaviors() {
return [
'verbs' => [
@@ -37,7 +41,7 @@ class CaptureLogsController extends Controller {
$t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U');
}
$this->view->title = "Lịch sử hệ thống";
$this->view->title = Yii::t("app", "LICH_SU_HE_THONG");
$searchModel = new CaptureLogsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if (!$all)
@@ -63,7 +67,9 @@ class CaptureLogsController extends Controller {
'f' => $f,
't' => $t,
// 'idAuto' => $idAuto,
"staffArray" => ListManagement::staffArray()
"staffArray" => ListManagement::staffArray(),
"typeArray" => ListManagement::typeArray(),
"genderArray" => ListManagement::genderArray(),
]);
}
@@ -108,7 +114,7 @@ class CaptureLogsController extends Controller {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
throw new NotFoundHttpException(Yii::t("app", "KHONG_TIM_THAY_THONG_TIN"));
}
}

View File

@@ -14,9 +14,9 @@ class ConfigController extends Controller {
public function init() {
parent::init();
if (Yii::$app->user->isGuest) {
Yii::$app->language = Yii::$app->session->get("language") ? Yii::$app->session->get("language")["name"] : "vi-VI";
if (Yii::$app->user->isGuest)
return $this->redirect(['/site/login']);
}
}
/**
@@ -157,12 +157,8 @@ class ConfigController extends Controller {
]
];
/**
* Lists all Script models.
* @return mixed
*/
public function actionIndex() {
$this->view->title = "Cấu hình máy chủ";
$this->view->title = Yii::t("app", "CAU_HINH_MAY_CHU");
$options = [
'http' => [
'header' => "Content-Type: application/json",
@@ -262,7 +258,7 @@ class ConfigController extends Controller {
]));
return true;
} else {
$this->view->title = "Cấu hình nhận diện";
$this->view->title = Yii::t("app", "CAU_HINH_NHAN_DIEN");
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
@@ -368,7 +364,7 @@ class ConfigController extends Controller {
} else {
Yii::$app->response->format = "json";
return [
"title" => "Reset thiết bị",
"title" => Yii::t("app", "RESET_THIET_BI"),
"form" => $this->renderPartial("reset")
];
}
@@ -387,7 +383,7 @@ class ConfigController extends Controller {
return ['status' => false, 'text' => 'error'];
if ($tempConfig['data'] === "")
return ['status' => false, 'text' => 'Cấu hình ip chưa đúng!'];
return ['status' => false, 'text' => Yii::t("app", "CAU_HINH_IP_CHUA_DUNG")];
$engineConfig = json_decode($tempConfig['data'], true);
if (count($engineConfig['data']['engines']) == 0)
@@ -412,7 +408,7 @@ class ConfigController extends Controller {
}
public function actionCauHinhThietBi() {
$this->view->title = "Cấu hình thiết bị";
$this->view->title = Yii::t("app", "CAU_HINH_THIET_BI");
return $this->render('device', [
"server_api" => \app\models\SyncUrl::findOne(['key_config' => 'server_api']),
"device_id" => \app\models\SyncUrl::findOne(['key_config' => 'device_id'])

View File

@@ -17,9 +17,13 @@ use app\models\common;
*/
class ControlLogsController extends Controller {
/**
* {@inheritdoc}
*/
public function init() {
parent::init();
Yii::$app->language = Yii::$app->session->get("language") ? Yii::$app->session->get("language")["name"] : "vi-VI";
if (Yii::$app->user->isGuest)
return $this->redirect(['/site/login']);
}
public function behaviors() {
return [
'verbs' => [
@@ -39,7 +43,7 @@ class ControlLogsController extends Controller {
$t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U');
}
$this->view->title = "Danh sách nhận diện";
$this->view->title = Yii::t("app", "DANH_SACH_NHAN_DIEN");
$searchModel = new CaptureLogsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->query->andWhere(["<>", "capture_logs.staff_id", 0]);
@@ -56,11 +60,10 @@ class ControlLogsController extends Controller {
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'statusArray' => CaptureLogs::$statusArray,
'f' => $f,
't' => $t,
'typeArray' => ListManagement::$typeArray,
'genderArray' => ListManagement::$genderArray
'typeArray' => ListManagement::typeArray(),
'genderArray' => ListManagement::genderArray()
]);
}
@@ -69,7 +72,7 @@ class ControlLogsController extends Controller {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
throw new NotFoundHttpException(Yii::t("app", "KHONG_TIM_THAY_THONG_TIN"));
}
public function actionUseFeature($id) {
@@ -81,7 +84,7 @@ class ControlLogsController extends Controller {
$url = $model->image;
$images = json_decode($listManagement->image, true);
if (count($images) >= \Yii::$app->params['maxPicture'])
return ["status" => false, "text" => "Mỗi đối tượng chỉ nhận tối đa " . \Yii::$app->params['maxPicture'] . " hình ảnh mẫu"];
return ["status" => false, "text" => Yii::t("app", "SO_ANH_MAU_TOI_DA", ["maxPicture" => \Yii::$app->params['maxPicture']])];
$add = true;
foreach ($images as $key => $value) {
if (isset($value['urlOld']) && $value['urlOld'] === $url)
@@ -119,9 +122,9 @@ class ControlLogsController extends Controller {
]);
return ["status" => true];
}
return ["status" => false, "text" => "Hình ảnh này đã được chọn làm mẫu cho đối tượng này!"];
return ["status" => false, "text" => Yii::t("app", "ANH_MAU_DA_DUOC_CHON")];
}
return ["status" => false, "text" => "Đối tượng không tồn tại!"];
return ["status" => false, "text" => Yii::t("app", "DOI_TUONG_KHONG_TON_TAI")];
}
}

View File

@@ -147,4 +147,14 @@ class DashboardController extends Controller {
return $this->redirect(Yii::$app->request->hostInfo . "/BiFace_Server_Lite/web/du-lieu.xlsx");
}
public function actionChangeLanguage($lang) {
if (Yii::$app->request->isAjax) {
$language = \app\models\common::allLanguage();
foreach ($language as $key => $value) {
if ($value['name'] === $lang)
return Yii::$app->session->set("language", $value);
}
}
}
}

View File

@@ -17,9 +17,13 @@ use yii\helpers\FileHelper;
*/
class ListManagementController extends Controller {
/**
* {@inheritdoc}
*/
public function init() {
parent::init();
Yii::$app->language = Yii::$app->session->get("language") ? Yii::$app->session->get("language")["name"] : "vi-VI";
if (Yii::$app->user->isGuest)
return $this->redirect(['/site/login']);
}
public function behaviors() {
return [
'verbs' => [
@@ -34,7 +38,7 @@ class ListManagementController extends Controller {
public function actionIndex($from = "", $to = "", $name = "", $type = "all", $gender = "all", $id = "") {
$f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U');
$t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U');
$this->view->title = "Quản lý mẫu";
$this->view->title = Yii::t("app", "QUAN_LY_MAU");
$searchModel = new ListManagementSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if ($from !== "" && $to !== "") {
@@ -77,8 +81,8 @@ class ListManagementController extends Controller {
'dataProvider' => $dataProvider,
'f' => $f,
't' => $t,
'typeArray' => ListManagement::$typeArray,
'genderArray' => ListManagement::$genderArray,
'typeArray' => ListManagement::typeArray(),
'genderArray' => ListManagement::genderArray(),
// 'idAuto' => $idAuto,
"staffArray" => ListManagement::staffArray(),
"updating" => $updating
@@ -121,7 +125,7 @@ class ListManagementController extends Controller {
if ($listManagement) {
$images = json_decode($listManagement->image, true);
if (count($images) >= \Yii::$app->params['maxPicture'])
return ["status" => false, "text" => "Mỗi đối tượng chỉ nhận tối đa " . \Yii::$app->params['maxPicture'] . " hình ảnh mẫu"];
return ["status" => false, "text" => Yii::t("app", "SO_ANH_MAU_TOI_DA", ["maxPicture" => \Yii::$app->params['maxPicture']])];
$add = true;
foreach ($images as $key => $value) {
if (isset($value['urlOld']) && $value['urlOld'] === $url)
@@ -166,7 +170,7 @@ class ListManagementController extends Controller {
]);
return ["status" => true];
}
return ["status" => false, "text" => "Hình ảnh này đã được chọn làm mẫu cho đối tượng này!"];
return ["status" => false, "text" => Yii::t("app", "ANH_MAU_DA_DUOC_CHON")];
} else {
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face";
@@ -318,7 +322,7 @@ class ListManagementController extends Controller {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
throw new NotFoundHttpException(Yii::t("app", "KHONG_TIM_THAY_THONG_TIN"));
}
public function actionBatchDelete() {
@@ -392,7 +396,7 @@ class ListManagementController extends Controller {
"title" => $data['ip'],
"form" => $this->renderPartial("list", [
"results" => $results,
"typeArray" => ListManagement::$typeArray,
"typeArray" => ListManagement::typeArray(),
"filters" => $filters,
"ip" => $data['ip']
])
@@ -428,7 +432,7 @@ class ListManagementController extends Controller {
}
Yii::$app->response->format = "json";
return [
"title" => "<i class='fa fa-download'></i> Đồng bộ từ máy chủ",
"title" => "<i class='fa fa-download'></i> " . Yii::t("app", "DONG_BO_TU_MAY_CHU"),
"form" => $this->renderPartial("list-server", [
"datas" => $datas['data'],
"filters" => $filters,
@@ -683,7 +687,7 @@ class ListManagementController extends Controller {
$filters[$value->staff_id] = $value->code . " - " . $value->name . " - " . $value->address;
}
return [
"title" => "<i class='fa fa-upload'></i> Đồng bộ lên máy chủ",
"title" => "<i class='fa fa-upload'></i> " . Yii::t("app", "DONG_BO_LEN_MAY_CHU"),
"form" => $this->renderPartial("list-to-server", [
"datas" => $datas,
"filters" => $filters
@@ -717,7 +721,7 @@ class ListManagementController extends Controller {
}
}
if (count($images) == 0)
return ["status" => true, "text" => "Dữ liệu không đổi"];
return ["status" => true, "text" => Yii::t("app", "DU_LIEU_KHONG_DOI")];
$items = [
"id" => $StaffInfo->staff_id,

View File

@@ -19,12 +19,12 @@ class UserController extends Controller {
public function init() {
parent::init();
if (Yii::$app->user->isGuest) {
Yii::$app->language = Yii::$app->session->get("language") ? Yii::$app->session->get("language")["name"] : "vi-VI";
if (Yii::$app->user->isGuest)
return $this->redirect(['/site/login']);
}
if (!Yii::$app->user->can("administrator")) {
if (!Yii::$app->user->can("administrator"))
return $this->redirect(["/dashboard"]);
}
}
/**
@@ -86,11 +86,6 @@ class UserController extends Controller {
}
}
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate() {
if (!Yii::$app->user->can("administrator")) {
Yii::$app->response->format = "json";
@@ -142,13 +137,6 @@ class UserController extends Controller {
}
}
/**
* Updates an existing User model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id) {
if (!Yii::$app->user->can("administrator")) {
Yii::$app->response->format = "json";
@@ -196,13 +184,6 @@ class UserController extends Controller {
}
}
/**
* Deletes an existing User model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id) {
if (!Yii::$app->user->can("administrator")) {
throw new \yii\web\ForbiddenHttpException(Yii::t("app", "Bạn không có quyền truy cập!"));
@@ -213,19 +194,12 @@ class UserController extends Controller {
return $this->redirect(['index']);
}
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = User::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
throw new NotFoundHttpException(Yii::t("app", "KHONG_TIM_THAY_THONG_TIN"));
}
public function actionProfiles() {
@@ -234,7 +208,7 @@ class UserController extends Controller {
}
$model = $this->findModel(Yii::$app->user->id);
$this->view->title = Yii::t("app", "Thông tin cá nhân");
$this->view->title = Yii::t("app", "THONG_TIN_CA_NHAN");
$this->view->params['breadcrumbs'][] = $this->view->title;
return $this->render('profiles', [
@@ -264,7 +238,7 @@ class UserController extends Controller {
if (Yii::$app->user->isGuest) {
return $this->redirect(['/site/login']);
}
$this->view->title = Yii::t("app", "Đổi mật khẩu");
$this->view->title = Yii::t("app", "DOI_MAT_KHAU");
$this->view->params['breadcrumbs'][] = $this->view->title;
return $this->render('password', [