Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions packages/core/actions/config/update-translation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

list($params, $providers) = eQual::announce([
'description' => 'This is the core_config_update-translation controller created with core_config_create-controller.',
'response' => [
'charset' => 'utf-8',
'accept-origin' => '*'
],
'params' => [
"package" => [
"description" => "name of the package of the entity",
"type" => "string",
"required" => true
],
"entity" => [
"description" => "name of the entity to edit",
"type" => "string",
"required" => true
],
"lang" => [
"description" => "lang of the translation",
"type" => "string",
"required" => true
],
"payload" => [
"type" => "text",
"default" => "{}"
],
"create_lang" => [
"type" => "boolean",
"default" => false
]
],
'access' => [
'visibility' => 'protected',
'groups' => ['users']
],
'providers' => ['context']
]);
/**
* @var \equal\php\context Context
*/
$context = $providers['context'];

$package = $params["package"];
$entity = $params["entity"];
$lang = $params["lang"];
$payload = $params["payload"];
$create = $params["create_lang"];

// Checking if package exists
if(!file_exists(QN_BASEDIR."/packages/{$package}")) {
throw new Exception('missing_package_dir', QN_ERROR_INVALID_CONFIG);
}

// Creating language folder
if(!is_dir(QN_BASEDIR."/packages/{$package}/i18n") && ($create==0) ){
throw new Exception('no_translation_folder', QN_ERROR_INVALID_CONFIG);
}
if(!is_dir(QN_BASEDIR."/packages/{$package}/i18n/{$lang}") && ($create==0)){
throw new Exception('language_does_not_exist_in_package', QN_ERROR_INVALID_CONFIG);
}
if(!is_dir(QN_BASEDIR."/packages/{$package}/i18n/{$lang}") && !mkdir(QN_BASEDIR."/packages/{$package}/i18n/{$lang}",true)) {
throw new Exception('io_error', QN_ERROR_INVALID_CONFIG);
}

$parts = explode("\\",$entity);

$filename = array_pop($parts).".json";

$dir = implode("/",$parts);

if(!is_dir(QN_BASEDIR."/packages/{$package}/i18n/{$lang}/{$dir}")) {
if($create == 0) {
throw new Exception('this_traduction_does_not_exist', QN_ERROR_INVALID_CONFIG);
}
mkdir(QN_BASEDIR."/packages/{$package}/i18n/{$lang}/{$dir}",true);
}

$json = json_decode($payload,true);

if($json === null) {
throw new Exception('payload_not_valid', QN_ERROR_INVALID_CONFIG);
}

$pretty = json_encode($json,JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);

if(!$pretty) {
throw new Exception('payload_not_valid', QN_ERROR_INVALID_CONFIG);
}

$f = fopen(QN_BASEDIR."/packages/{$package}/i18n/{$lang}/{$dir}/{$filename}","w");

if(!$f) {
throw new Exception('io_error', QN_ERROR_INVALID_CONFIG);
}

fputs($f,$pretty);

fclose($f);

$res = file_get_contents(QN_BASEDIR."/packages/{$package}/i18n/{$lang}/{$dir}/{$filename}");

$context->httpResponse()
->body($pretty)
->status(200)
->send();
11 changes: 9 additions & 2 deletions packages/core/data/config/translations.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@
if(!isset($params['entity'])) {
throw new Exception('package_or_entity_required', QN_ERROR_MISSING_PARAM);
}
if(!class_exists($params['entity'])) {
throw new Exception('unknown_entity', QN_ERROR_INVALID_PARAM);
$temp = explode("\\", str_replace("_","\\",$params['entity']));
$pkg = array_shift($temp);
$path = implode("/",$temp);
if(
!file_exists(QN_BASEDIR."/packages/{$pkg}/classes/{$path}.class.php")
&& !file_exists(QN_BASEDIR."/packages/{$pkg}/actions/{$path}.php")
&& !file_exists(QN_BASEDIR."/packages/{$pkg}/data/{$path}.php")
) {
throw new Exception("unknown_entity", QN_ERROR_INVALID_PARAM);
}
$entity = $params['entity'];
$map_views_ids = [];
Expand Down