From f451e65278cb9f1408e56f1a03ab456f4d48fa73 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 30 Sep 2018 13:02:07 +0200 Subject: [PATCH] Also log missing localization found in frontend (only when MODE == dev) --- controllers/SystemApiController.php | 18 ++++++++++ grocy.openapi.json | 49 ++++++++++++++++++++++++++++ public/js/grocy.js | 16 +++++++++ public/js/grocy_dbchangedhandling.js | 1 - routes.php | 1 + services/LocalizationService.php | 2 +- views/layout/default.blade.php | 1 + 7 files changed, 86 insertions(+), 2 deletions(-) diff --git a/controllers/SystemApiController.php b/controllers/SystemApiController.php index b72939a2..23664eb3 100644 --- a/controllers/SystemApiController.php +++ b/controllers/SystemApiController.php @@ -20,4 +20,22 @@ class SystemApiController extends BaseApiController 'changed_time' => $this->DatabaseService->GetDbChangedTime() )); } + + public function LogMissingLocalization(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + if (GROCY_MODE === 'dev') + { + try + { + $requestBody = $request->getParsedBody(); + + $this->LocalizationService->LogMissingLocalization(GROCY_CULTURE, $requestBody['text']); + return $this->ApiResponse(array('success' => true)); + } + catch (\Exception $ex) + { + return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); + } + } + } } diff --git a/grocy.openapi.json b/grocy.openapi.json index aa6cff46..e2bbee91 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -44,6 +44,47 @@ } } }, + "/system/log-missing-localization": { + "post": { + "description": "Logs a missing localization string (only when MODE == 'dev', so should only be called then)", + "tags": [ + "System" + ], + "requestBody": { + "description": "A valid MissingLocalizationRequest object", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/MissingLocalizationRequest" + } + } + } + }, + "responses": { + "200": { + "description": "A VoidApiActionResponse object", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/VoidApiActionResponse" + } + } + } + }, + "400": { + "description": "A VoidApiActionResponse object", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorExampleVoidApiActionResponse" + } + } + } + } + } + } + }, "/get-objects/{entity}": { "get": { "description": "Returns all objects of the given entity", @@ -2197,6 +2238,14 @@ "type": "string" } } + }, + "MissingLocalizationRequest": { + "type": "object", + "properties": { + "text": { + "type": "string" + } + } } }, "examples": { diff --git a/public/js/grocy.js b/public/js/grocy.js index 45edcc8b..be47eb16 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -3,6 +3,22 @@ var localizedText = Grocy.LocalizationStrings[text]; if (localizedText === undefined) { + if (Grocy.Mode === 'dev') + { + jsonData = {}; + jsonData.text = text; + Grocy.Api.Post('system/log-missing-localization', jsonData, + function(result) + { + // Nothing to do... + }, + function(xhr) + { + console.log(xhr) + } + ); + } + localizedText = text; } diff --git a/public/js/grocy_dbchangedhandling.js b/public/js/grocy_dbchangedhandling.js index b2261fb6..055696a2 100644 --- a/public/js/grocy_dbchangedhandling.js +++ b/public/js/grocy_dbchangedhandling.js @@ -64,7 +64,6 @@ $("#auto-reload-enabled").on("change", function() jsonData = { }; jsonData.value = value; - console.log(jsonData); Grocy.Api.Post('user/settings/auto_reload_on_db_change', jsonData, function(result) { diff --git a/routes.php b/routes.php index 28794694..25404d49 100644 --- a/routes.php +++ b/routes.php @@ -81,6 +81,7 @@ $app->group('/api', function() // System $this->get('/system/get-db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime'); + $this->post('/system/log-missing-localization', '\Grocy\Controllers\SystemApiController:LogMissingLocalization'); // Files $this->post('/files/upload/{group}', '\Grocy\Controllers\FilesApiController:Upload'); diff --git a/services/LocalizationService.php b/services/LocalizationService.php index 35f4789a..efe8e652 100644 --- a/services/LocalizationService.php +++ b/services/LocalizationService.php @@ -34,7 +34,7 @@ class LocalizationService } } - private function LogMissingLocalization(string $culture, string $text) + public function LogMissingLocalization(string $culture, string $text) { $file = GROCY_DATAPATH . "/missing_translations_$culture.json"; diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 3d3f4688..803d9be7 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -36,6 +36,7 @@