Also log missing localization found in frontend (only when MODE == dev)

This commit is contained in:
Bernd Bestel
2018-09-30 13:02:07 +02:00
parent 176333df5b
commit f451e65278
7 changed files with 86 additions and 2 deletions

View File

@@ -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());
}
}
}
}

View File

@@ -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": {

View File

@@ -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;
}

View File

@@ -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)
{

View File

@@ -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');

View File

@@ -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";

View File

@@ -36,6 +36,7 @@
<script>
var Grocy = { };
Grocy.Components = { };
Grocy.Mode = '{{ GROCY_MODE }}';
Grocy.BaseUrl = '{{ $U('/') }}';
Grocy.LocalizationStrings = {!! json_encode($localizationStrings) !!};
Grocy.ActiveNav = '@yield('activeNav', '')';