Skip to content
Snippets Groups Projects
Commit 8e04c61c authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #14136 TIME 1:10 migrateCustomLang in json + move all lang files in /lang

parent 29c0043b
No related branches found
No related tags found
No related merge requests found
...@@ -4,4 +4,5 @@ php ./migrateNotificationsProperties.php ...@@ -4,4 +4,5 @@ php ./migrateNotificationsProperties.php
php ./migrateNotificationsConfig.php php ./migrateNotificationsConfig.php
php ./migrateRemoteSignatureBookConfig.php php ./migrateRemoteSignatureBookConfig.php
php ./migrateImages.php php ./migrateImages.php
php ./migrateCustomLang.php
php ./migrateCustomXml.php # mettre en dernier php ./migrateCustomXml.php # mettre en dernier
<?php
require '../../vendor/autoload.php';
chdir('../..');
$migrated = 0;
$customs = scandir('custom');
foreach ($customs as $custom) {
if (in_array($custom, ['custom.json', 'custom.xml', '.', '..'])) {
continue;
}
$customLangFolderPath = "custom/{$custom}/lang";
if (is_dir($customLangFolderPath)) {
if (!is_readable($customLangFolderPath) || !is_writable($customLangFolderPath)) {
printf("WARNING : The folder %s is not readable or not writable.\n", $customLangFolderPath);
continue;
}
$customLangFiles = scandir($customLangFolderPath);
foreach ($customLangFiles as $customLangFile) {
if (strtolower(pathinfo($customLangFile, PATHINFO_EXTENSION)) == 'ts') {
if (!is_readable($customLangFolderPath . '/' . $customLangFile) || !is_writable($customLangFolderPath . '/' . $customLangFile)) {
printf("WARNING : The file %s is not readable or not writable.\n", $customLangFolderPath . '/' . $customLangFile);
continue;
}
$fileContent = trim(file_get_contents($customLangFolderPath . '/' . $customLangFile));
$fileContent = trim(substr($fileContent, strpos($fileContent, "{"), -2)); // get content from first "{" , and remove last "};"
$jsonContent = json_decode(rtrim($fileContent, ",") . "}");
file_put_contents($customLangFolderPath . '/' . str_ireplace(".ts", ".json", $customLangFile), json_encode($jsonContent, JSON_PRETTY_PRINT));
unlink($customLangFolderPath . '/' . $customLangFile);
$migrated++;
}
}
}
}
printf($migrated . " fichier(s) custom/custom_id/lang/*.ts trouvé(s) et migré(s).\n");
...@@ -26,8 +26,8 @@ class CoreController ...@@ -26,8 +26,8 @@ class CoreController
{ {
public function getHeader(Request $request, Response $response) public function getHeader(Request $request, Response $response)
{ {
$user = UserModel::getById(['id' => $GLOBALS['id'], 'select' => ['id', 'user_id', 'firstname', 'lastname']]); $user = UserModel::getById(['id' => $GLOBALS['id'], 'select' => ['id', 'user_id', 'firstname', 'lastname']]);
$user['groups'] = UserModel::getGroupsByLogin(['login' => $GLOBALS['login']]); $user['groups'] = UserModel::getGroupsByLogin(['login' => $GLOBALS['login']]);
$user['entities'] = UserModel::getEntitiesById(['id' => $GLOBALS['id'], 'select' => ['entities.id', 'users_entities.entity_id', 'entities.entity_label', 'users_entities.user_role', 'users_entities.primary_entity']]); $user['entities'] = UserModel::getEntitiesById(['id' => $GLOBALS['id'], 'select' => ['entities.id', 'users_entities.entity_id', 'entities.entity_label', 'users_entities.user_role', 'users_entities.primary_entity']]);
return $response->withJson(['user' => $user]); return $response->withJson(['user' => $user]);
...@@ -47,7 +47,7 @@ class CoreController ...@@ -47,7 +47,7 @@ class CoreController
return $response->withJson(['hash' => null]); return $response->withJson(['hash' => null]);
} }
$hash = file_get_contents( '.git/' . $currentHead); $hash = file_get_contents('.git/' . $currentHead);
if ($hash === false) { if ($hash === false) {
return $response->withJson(['hash' => null]); return $response->withJson(['hash' => null]);
} }
...@@ -62,9 +62,9 @@ class CoreController ...@@ -62,9 +62,9 @@ class CoreController
ValidatorModel::notEmpty($args, ['userId']); ValidatorModel::notEmpty($args, ['userId']);
ValidatorModel::intVal($args, ['userId']); ValidatorModel::intVal($args, ['userId']);
$user = UserModel::getById(['id' => $args['userId'], 'select' => ['user_id']]); $user = UserModel::getById(['id' => $args['userId'], 'select' => ['user_id']]);
$GLOBALS['login'] = $user['user_id']; $GLOBALS['login'] = $user['user_id'];
$GLOBALS['id'] = $args['userId']; $GLOBALS['id'] = $args['userId'];
} }
public function externalConnectionsEnabled(Request $request, Response $response) public function externalConnectionsEnabled(Request $request, Response $response)
...@@ -172,7 +172,7 @@ class CoreController ...@@ -172,7 +172,7 @@ class CoreController
$content = 'export const LANG_'.strtoupper($body['langId']).' = '.json_encode($body['jsonContent'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES).';'; $content = 'export const LANG_'.strtoupper($body['langId']).' = '.json_encode($body['jsonContent'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES).';';
if($fp = @fopen("src/frontend/lang/lang-{$body['langId']}.ts", 'w')) { if ($fp = @fopen("src/frontend/lang/lang-{$body['langId']}.ts", 'w')) {
fwrite($fp, $content); fwrite($fp, $content);
fclose($fp); fclose($fp);
return $response->withStatus(204); return $response->withStatus(204);
...@@ -187,12 +187,12 @@ class CoreController ...@@ -187,12 +187,12 @@ class CoreController
$languages = []; $languages = [];
$arrLanguages = []; $arrLanguages = [];
foreach ($files as $value) { foreach ($files as $value) {
$languages[] = str_replace('.ts','', $value) ; $languages[] = str_replace('.ts', '', $value) ;
} }
foreach ($languages as $file) { foreach ($languages as $file) {
$langName = explode('-', $file)[1]; $langName = explode('-', $file)[1];
$path = 'src/frontend/lang/' . $file . '.ts'; $path = 'src/frontend/lang/' . $file . '.ts';
$fileContent = file_get_contents($path); $fileContent = file_get_contents($path);
$fileContent = str_replace('export const LANG_'.strtoupper($langName).' =', '', $fileContent); $fileContent = str_replace('export const LANG_'.strtoupper($langName).' =', '', $fileContent);
$fileContent = trim($fileContent); $fileContent = trim($fileContent);
...@@ -201,7 +201,7 @@ class CoreController ...@@ -201,7 +201,7 @@ class CoreController
$fileContent = str_replace(" ", "", $fileContent); $fileContent = str_replace(" ", "", $fileContent);
$fileContent = str_replace(",};", "}", $fileContent); $fileContent = str_replace(",};", "}", $fileContent);
$fileContent = rtrim($fileContent, ";"); $fileContent = rtrim($fileContent, ";");
$fileContent = json_decode($fileContent); $fileContent = json_decode($fileContent);
$arrLanguages[$langName] = $fileContent; $arrLanguages[$langName] = $fileContent;
} }
return $response->withJson(['langs' => $arrLanguages]); return $response->withJson(['langs' => $arrLanguages]);
......
...@@ -34,18 +34,16 @@ class LanguageController ...@@ -34,18 +34,16 @@ class LanguageController
$language = ['lang' => []]; $language = ['lang' => []];
if (is_file("src/frontend/lang/lang-{$args['language']}.json")) { if (is_file("src/lang/lang-{$args['language']}.json")) {
$file = file_get_contents("src/frontend/lang/lang-{$args['language']}.json"); $file = file_get_contents("src/lang/lang-{$args['language']}.json");
$language['lang'] = json_decode($file, true); $language['lang'] = json_decode($file, true);
} }
$customId = CoreConfigModel::getCustomId(); $customId = CoreConfigModel::getCustomId();
if (is_file("custom/{$customId}/src/frontend/lang/lang-{$args['language']}.json")) { if (is_file("custom/{$customId}/lang/lang-{$args['language']}.json")) {
$file = file_get_contents("custom/{$customId}/src/frontend/lang/lang-{$args['language']}.json"); $file = file_get_contents("custom/{$customId}/lang/lang-{$args['language']}.json");
$overloadedLanguage = json_decode($file, true); $overloadedLanguage = json_decode($file, true) ?? [];
foreach ($overloadedLanguage['lang'] as $key => $value) { $language['lang'] = array_merge($language['lang'], $overloadedLanguage);
$language['lang'][$key] = $value;
}
} }
if (empty($language['lang'])) { if (empty($language['lang'])) {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment