You've already forked tritonmconverter
updatev2
This commit is contained in:
205
css/style.css
205
css/style.css
@@ -21,54 +21,87 @@ body {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.settings {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
main {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.h-100 {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.row {
|
||||
margin: 0 !important;
|
||||
}
|
||||
|
||||
.gap {
|
||||
gap: .5em;
|
||||
}
|
||||
|
||||
.setting-group {
|
||||
.flex-grow {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
/*.settings {*/
|
||||
/* display: flex;*/
|
||||
/* flex-direction: column;*/
|
||||
/* gap: .5em;*/
|
||||
/*}*/
|
||||
|
||||
/*.setting-group {*/
|
||||
/* display: flex;*/
|
||||
/* width: 50%;*/
|
||||
/*}*/
|
||||
|
||||
/*.setting-group:last-child{*/
|
||||
/* flex-direction: column;*/
|
||||
/* gap: .5em;*/
|
||||
/*}*/
|
||||
|
||||
/*.input {*/
|
||||
/* display: flex;*/
|
||||
/*}*/
|
||||
|
||||
|
||||
/*.setting-group:first-child, .input {*/
|
||||
/* justify-content: space-between;*/
|
||||
/*}*/
|
||||
|
||||
|
||||
/*.setting-group label {*/
|
||||
/* display: flex;*/
|
||||
/* width: 50%;*/
|
||||
/*}*/
|
||||
|
||||
/*.setting-group input {*/
|
||||
/* width: 100%;*/
|
||||
/*}*/
|
||||
|
||||
/*.input-field {*/
|
||||
/* width: 100%;*/
|
||||
/* display: flex;*/
|
||||
/* gap: .5em;*/
|
||||
/*}*/
|
||||
|
||||
/*.args {*/
|
||||
/* width: 100%;*/
|
||||
|
||||
/* display: flex;*/
|
||||
/* gap: .5em;*/
|
||||
|
||||
/* flex-wrap: wrap;*/
|
||||
/*}*/
|
||||
|
||||
.args, .db {
|
||||
min-height: 100px;
|
||||
display: flex;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.setting-group:last-child{
|
||||
flex-direction: column;
|
||||
gap: .5em;
|
||||
}
|
||||
|
||||
.input {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
|
||||
.setting-group:first-child, .input {
|
||||
flex-wrap: wrap;
|
||||
align-content: start;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
|
||||
.setting-group label {
|
||||
display: flex;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.setting-group input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
gap: .5em;
|
||||
}
|
||||
|
||||
.args {
|
||||
width: 100%;
|
||||
|
||||
display: flex;
|
||||
gap: .5em;
|
||||
|
||||
flex-wrap: wrap;
|
||||
.db input {
|
||||
width: 49% !important;
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
.arg {
|
||||
@@ -81,6 +114,10 @@ body {
|
||||
|
||||
gap: .25em;
|
||||
align-items: center;
|
||||
line-height: 1;
|
||||
|
||||
height: fit-content;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.delete-arg {
|
||||
@@ -91,60 +128,60 @@ body {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.content {
|
||||
flex-grow: 1;
|
||||
width: 100%;
|
||||
/*.content {*/
|
||||
/* flex-grow: 1;*/
|
||||
/* width: 100%;*/
|
||||
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: .5em;
|
||||
}
|
||||
/* display: flex;*/
|
||||
/* flex-wrap: wrap;*/
|
||||
/* justify-content: space-between;*/
|
||||
/* gap: .5em;*/
|
||||
/*}*/
|
||||
|
||||
.content .buttons {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
/*.content .buttons {*/
|
||||
/* width: 100%;*/
|
||||
/* display: flex;*/
|
||||
|
||||
justify-content: space-between;
|
||||
}
|
||||
/* justify-content: space-between;*/
|
||||
/*}*/
|
||||
|
||||
.content .buttons div {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 49%;
|
||||
}
|
||||
/*.content .buttons div {*/
|
||||
/* display: flex;*/
|
||||
/* justify-content: space-between;*/
|
||||
/* align-items: center;*/
|
||||
/* width: 49%;*/
|
||||
/*}*/
|
||||
|
||||
.content textarea {
|
||||
height: 100%;
|
||||
width: 49%;
|
||||
}
|
||||
/*.content textarea {*/
|
||||
/* height: 100%;*/
|
||||
/* width: 49%;*/
|
||||
/*}*/
|
||||
|
||||
footer {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
padding: .5em;
|
||||
margin-top: .5em;
|
||||
/*footer {*/
|
||||
/* display: flex;*/
|
||||
/* width: 100%;*/
|
||||
/* padding: .5em;*/
|
||||
/* margin-top: .5em;*/
|
||||
|
||||
font-size: 12pt;
|
||||
/* font-size: 12pt;*/
|
||||
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
/* text-align: center;*/
|
||||
/* align-items: center;*/
|
||||
/* justify-content: center;*/
|
||||
|
||||
font-weight: 600;
|
||||
/* font-weight: 600;*/
|
||||
|
||||
|
||||
color: #333;
|
||||
}
|
||||
/* color: #333;*/
|
||||
/*}*/
|
||||
|
||||
footer a {
|
||||
text-decoration: none;
|
||||
/*footer a {*/
|
||||
/* text-decoration: none;*/
|
||||
|
||||
color: #333;
|
||||
transition: color .5s ease;
|
||||
}
|
||||
/* color: #333;*/
|
||||
/* transition: color .5s ease;*/
|
||||
/*}*/
|
||||
|
||||
footer a:hover {
|
||||
color: blueviolet;
|
||||
}
|
||||
/*footer a:hover {*/
|
||||
/* color: blueviolet;*/
|
||||
/*}*/
|
||||
|
||||
97
index.html
97
index.html
@@ -1,97 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Text Transformer</title>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<!-- <style>-->
|
||||
<!-- body {-->
|
||||
<!-- display: flex;-->
|
||||
<!-- flex-direction: column;-->
|
||||
<!-- font-family: Arial, sans-serif;-->
|
||||
<!-- margin: 0;-->
|
||||
<!-- padding: 0;-->
|
||||
<!-- }-->
|
||||
<!-- .settings, .container {-->
|
||||
<!-- padding: 10px;-->
|
||||
<!-- border-bottom: 1px solid #ccc;-->
|
||||
<!-- }-->
|
||||
<!-- .container {-->
|
||||
<!-- display: flex;-->
|
||||
<!-- height: calc(100vh - 100px);-->
|
||||
<!-- }-->
|
||||
<!-- .input-section, .output-section {-->
|
||||
<!-- width: 50%;-->
|
||||
<!-- padding: 10px;-->
|
||||
<!-- }-->
|
||||
<!-- textarea {-->
|
||||
<!-- width: 100%;-->
|
||||
<!-- height: 100%;-->
|
||||
<!-- resize: none;-->
|
||||
<!-- }-->
|
||||
<!-- </style>-->
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- Yandex.Metrika counter -->
|
||||
<script type="text/javascript" >
|
||||
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
|
||||
m[i].l=1*new Date();
|
||||
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
|
||||
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
|
||||
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
|
||||
|
||||
ym(97929485, "init", {
|
||||
clickmap:true,
|
||||
trackLinks:true,
|
||||
accurateTrackBounce:true,
|
||||
webvisor:true
|
||||
});
|
||||
</script>
|
||||
<noscript><div><img src="https://mc.yandex.ru/watch/97929485" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
||||
<!-- /Yandex.Metrika counter -->
|
||||
|
||||
<div class="settings">
|
||||
<div class="setting-group">
|
||||
<label for="key">Enter a key</label><input id="key" type="text" placeholder="Enter localization prefix">
|
||||
</div>
|
||||
<div class="setting-group">
|
||||
<div class="input">
|
||||
<label for="add_arg">Enter a new arg</label><input type="text" id="add_arg" placeholder="e.g. player admin arg1 arg2 end press enter">
|
||||
</div>
|
||||
<div class="args" id="args">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="buttons">
|
||||
<div class="div"><span>Input</span></div>
|
||||
<div class="div"><span>Output</span><button onclick="copyResult()">Copy to clipboard</button></div>
|
||||
</div>
|
||||
<textarea id="input" placeholder="Paste input"></textarea>
|
||||
<textarea id="output" placeholder="Copy Output" ></textarea>
|
||||
</div>
|
||||
<footer>
|
||||
<p>2023-<span id="date"></span> © <a href="https://discord.com/users/566255927926456320">DestKoder</a> & <a href="https://quickfirecorp.ru">QuickFire Corp</a> All Rights Reserved</p>
|
||||
</footer>
|
||||
<!--<div class="settings">-->
|
||||
<!-- <label for="langInput">Language Key: </label>-->
|
||||
<!-- <input type="text" id="langInput" placeholder="e.g., chatty">-->
|
||||
<!-- <br><br>-->
|
||||
<!-- <label for="argsInput">Arguments (comma-separated): </label>-->
|
||||
<!-- <input type="text" id="argsInput" placeholder="e.g., {label}, {player}, {players}">-->
|
||||
<!--</div>-->
|
||||
<!--<div class="container">-->
|
||||
<!-- <div class="input-section">-->
|
||||
<!-- <h3>Input Text</h3>-->
|
||||
<!-- <textarea id="inputText" placeholder="Paste text here..."></textarea>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="output-section">-->
|
||||
<!-- <h3>Output Text</h3>-->
|
||||
<!-- <textarea id="outputText" readonly></textarea>-->
|
||||
<!-- </div>-->
|
||||
<!--</div>-->
|
||||
<script src="js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
172
index.php
Normal file
172
index.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
if(isset($_POST['data'])){
|
||||
$data = json_decode($_POST['data'], true);
|
||||
function guidv4($data = null) {
|
||||
// Generate 16 bytes (128 bits) of random data or use the data passed into the function.
|
||||
$data = $data ?? random_bytes(16);
|
||||
assert(strlen($data) == 16);
|
||||
|
||||
// Set version to 0100
|
||||
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
|
||||
// Set bits 6-7 to 10
|
||||
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
|
||||
|
||||
// Output the 36 character UUID.
|
||||
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
|
||||
}
|
||||
|
||||
$host = $data['database']['host'];
|
||||
$port = $data['database']['port'];
|
||||
$user = $data['database']['user'];
|
||||
$pass = $data['database']['pass'];
|
||||
$database = $data['database']['base'];
|
||||
$prefix = $data['database']['pref'];
|
||||
|
||||
$link = mysqli_connect($host, $user, $pass, $database, $port);
|
||||
$link->set_charset('utf8');
|
||||
if ($link == false){
|
||||
exit(json_encode(array("success" => "false", "message"=> "Невозможно подключиться к MySQL" . mysqli_connect_error())));
|
||||
}
|
||||
|
||||
$resCollection = $link->query("SELECT * FROM `".$prefix."collections` WHERE `name` = '" . $data['collection'] . "';");
|
||||
$isSuccess = true;
|
||||
$hasCollection = mysqli_num_rows($resCollection) > 0;
|
||||
foreach($data['data'] as $key => $value){
|
||||
// echo $key . " -> "; var_dump($value); echo '<br>';
|
||||
|
||||
if($hasCollection){
|
||||
$rs = $link->query("SELECT `twin_id`, `twin_data` FROM `".$prefix."translations` WHERE `field_key` = '" . $key . "';");
|
||||
$hasLocalization = mysqli_num_rows($rs) > 0;
|
||||
|
||||
if($hasLocalization){
|
||||
//updating
|
||||
$data = mysqli_fetch_assoc($rs);
|
||||
$twinData = json_decode($data['twin_data'], true);
|
||||
$twinData['dateUpdated'] = time()*1000;
|
||||
|
||||
|
||||
$res = $link->query("UPDATE `".$prefix."translations` SET `twin_data` = '".str_replace("\"", '\\"',json_encode($twinData))."' , `content` = '".str_replace("\"", '\\"', json_encode($value, JSON_UNESCAPED_UNICODE))."' WHERE `twin_id` = '" . $data['twin_id'] . "';");
|
||||
|
||||
if(!$res) {
|
||||
exit(json_encode(array("success" => "false", "message" => "Couldn't save " . $key . ": " . $link->error)));
|
||||
break;
|
||||
}
|
||||
|
||||
}else {
|
||||
$twinData = array(
|
||||
"dateCreated" => time()*1000,
|
||||
"dateUpdated" => time()*1000,
|
||||
"archived" => false,
|
||||
"tags" => []
|
||||
);
|
||||
$twinId = guidv4();
|
||||
//inserting
|
||||
$stmt = $link->prepare("INSERT INTO `".$prefix."translations` (`collection`, `field_key`, `content`, `twin_id`, `twin_data`) VALUES (?,?,?,?,?)");
|
||||
$stmt ->bind_param("sssss", $data['collection'], $key, json_encode($value, JSON_UNESCAPED_UNICODE), $twinId, json_encode($twinData));
|
||||
$res = $stmt -> execute();
|
||||
$stmt -> close();
|
||||
if(!$res) {
|
||||
exit(json_encode(array("success" => "false", "message" => "Couldn't save " . $key . ": " . $link->error)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
$twinData = array(
|
||||
"dateCreated" => time()*1000,
|
||||
"dateUpdated" => time()*1000,
|
||||
"archived" => false,
|
||||
"tags" => []
|
||||
);
|
||||
$twinId = guidv4();
|
||||
//inserting
|
||||
$queryAddCollection = "INSERT INTO `".$prefix."collections` (`name`, `servers`, `blacklist`) VALUES ('".$data['collection']."', '[]', 1)";
|
||||
// $queryAddTranslation = "INSERT INTO `".$prefix."translations` (`collection`, `field_key`, `content`, `twin_id`, `twin_data`) VALUES ('".$data['collection']."' , '".$key."' , '".str_replace("\"", '\\"', json_encode($value, JSON_UNESCAPED_UNICODE))."' , '".$twinId."' , '".str_replace("\"", '\\"',json_encode($twinData))."');";
|
||||
$res = $link->query($queryAddCollection);
|
||||
// $res = $link->query($queryAddTranslation);
|
||||
$stmt = $link->prepare("INSERT INTO `".$prefix."translations` (`collection`, `field_key`, `content`, `twin_id`, `twin_data`) VALUES (?,?,?,?,?)");
|
||||
$stmt ->bind_param("sssss", $data['collection'], $key, json_encode($value, JSON_UNESCAPED_UNICODE), $twinId, json_encode($twinData));
|
||||
$res = $stmt -> execute();
|
||||
$stmt -> close();
|
||||
if(!$res) {
|
||||
exit(json_encode(array("success" => "false", "message" => "Couldn't save " . $key . ": " . $link->error)));
|
||||
break;
|
||||
}
|
||||
$hasCollection = true;
|
||||
}
|
||||
}
|
||||
exit(json_encode(array("success" => "true")));
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Text Transformer</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
<script src="js/jquery-3.7.1.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="row">
|
||||
<div class="col-md-6 d-flex flex-column gap">
|
||||
<div class="row justify-content-between">
|
||||
<label for="key">Enter a key</label><input class="form-control-sm w-50" id="key" type="text" placeholder="Enter collection name">
|
||||
</div>
|
||||
<div class="row justify-content-between">
|
||||
<div class="row justify-content-between w-100">
|
||||
<label for="add_arg">Enter a new arg</label><input class="form-control-sm w-50" type="text" id="add_arg" placeholder="e.g. player admin">
|
||||
</div>
|
||||
<div class="args" id="args"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="w-100 db">
|
||||
<input type="text" id="db_host" name="" class="form-control-sm w-50" placeholder="Database host">
|
||||
<input type="text" id="db_base" name="" class="form-control-sm w-50" placeholder="Database base">
|
||||
<input type="text" id="db_user" name="" class="form-control-sm w-50" placeholder="Database user">
|
||||
<input type="password" id="db_pass" name="" class="form-control-sm w-50" placeholder="Database password">
|
||||
<input type="number" id="db_port" name="" class="form-control-sm w-50" placeholder="Database port" value="3306">
|
||||
<input type="text" id="db_prefix" name="" class="form-control-sm w-50" placeholder="Triton table prefix" value="triton_">
|
||||
</div>
|
||||
<div class="row justify-content-between"><button id="reset" class="btn-sm btn-success">Новый документ</button><button id="btn" class="btn-sm btn-success">Upload translations to database</button></div>
|
||||
</div>
|
||||
</div>
|
||||
<main class="row flex-column gap">
|
||||
<div class="row justify-content-between align-items-center">
|
||||
<div class="col-md-6 d-flex justify-content-between pr-2 align-items-center">
|
||||
<span>Input</span>
|
||||
<select id="language" class="form-control w-50">
|
||||
<option value="choose" disabled selected>Choose language</option>
|
||||
<option value="ru_RU">Russia</option>
|
||||
<option value="en_GB">United Kingdom</option>
|
||||
<option value="en_US">United States of America (USA)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 d-flex justify-content-between pl-2 align-items-center">
|
||||
<span>Output</span>
|
||||
<button class="btn btn-success" onclick="copyResult()">Copy result</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row flex-grow">
|
||||
<div class="col-md-6 pr-2 h-100">
|
||||
<textarea id="input" class="w-100 form-control h-100" disabled></textarea>
|
||||
</div>
|
||||
<div class="col-md-6 pl-2 h-100">
|
||||
<textarea id="output" class="w-100 form-control h-100" disabled></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
<div class="w-100 row align-items-center justify-content-center p-2">
|
||||
<p>2023-<span id="date"></span> © <a href="https://discord.com/users/566255927926456320">DestKoder</a> & <a href="https:://quickfirecorp.ru">QuickFire Corp</a> All Rights Reserved</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="js/index.js"></script>
|
||||
<script src="js/utils.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
215
js/index.js
Normal file
215
js/index.js
Normal file
@@ -0,0 +1,215 @@
|
||||
// const lineWithValuePattern = /[a-zA-Z]:/i
|
||||
//^\s+[a-zA-Z-_]+:\s+["'A-Za-zА-Яа-я&<\{\}\>\[\]§]+|^\s+-\s+["'A-Za-zА-Яа-я&<\{\}\>\[\]§]+
|
||||
const lineWithValuePattern = /["'].*?["']|["'].*?|.*?["']/i;
|
||||
//System
|
||||
const inputEl = document.getElementById("input");
|
||||
const outputEl = document.getElementById("output");
|
||||
const collectionInput = document.getElementById("key");
|
||||
const languageSelector = document.getElementById("language");
|
||||
|
||||
//Runtime
|
||||
let collectionName;
|
||||
let currentLanguage;
|
||||
let result = {};
|
||||
let langCache = {}
|
||||
//utils
|
||||
function getArgs(){
|
||||
let args = [];
|
||||
for(let i = 0; i < argsElement.children.length; i++){
|
||||
args[i] = argsElement.children[i].children[0].innerHTML.trim().replace("<", "<").replace(">", ">");
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
function buildRegex(args){
|
||||
let regex = ""
|
||||
for(let i = 0; i < args.length; i++){
|
||||
regex += args[i];
|
||||
if(i !== args.length-1) regex += "|"
|
||||
}
|
||||
return new RegExp(regex);
|
||||
}
|
||||
|
||||
function parseResulting(value){
|
||||
// console.log(value.match(/['"].*?['"]/i));
|
||||
value = value.trim();
|
||||
let match = value.match(/^['"].*?['"]$/i)
|
||||
if(match != null){
|
||||
value = (match+"").substring(1, (match+"").length-1);
|
||||
}
|
||||
// if(value.match(/['"].*?['"]/i) != null) {
|
||||
// value = (value.match(/^['"].*?['"]$/i)+"").substring(1,);
|
||||
// }
|
||||
return value;
|
||||
}
|
||||
|
||||
//Handlers
|
||||
function switchLang(e){
|
||||
console.log(e.target.selectedOptions.item(0).value);
|
||||
currentLanguage = e.target.selectedOptions.item(0).value;
|
||||
if(currentLanguage in langCache) inputEl.value = langCache[currentLanguage];
|
||||
else {
|
||||
inputEl.value = "";
|
||||
inputEl.placeholder = "Please enter a localization for lang " + e.target.selectedOptions.item(0).innerHTML;
|
||||
}
|
||||
|
||||
handleInput()
|
||||
}
|
||||
|
||||
function switchCollectionName(e){
|
||||
collectionName = e.target.value;
|
||||
handleInput();
|
||||
}
|
||||
|
||||
function handleInput() {
|
||||
if(!collectionName){
|
||||
outputEl.value = "Please enter a Collection Name";
|
||||
return;
|
||||
}
|
||||
if(!currentLanguage){
|
||||
outputEl.value = "Waiting for select language";
|
||||
return;
|
||||
}
|
||||
|
||||
let args = getArgs();
|
||||
let lines = inputEl.value.split("\n");
|
||||
let argsRegex = buildRegex(args);
|
||||
|
||||
outputEl.value = "";
|
||||
langCache[currentLanguage] = "";
|
||||
let counter = 0;
|
||||
lines.forEach(line => {
|
||||
langCache[currentLanguage] += line +"\n";
|
||||
if(line.match(lineWithValuePattern) == null){
|
||||
outputEl.value += line + "\n";
|
||||
return;
|
||||
}
|
||||
let data = line.includes(":") ? line.split(/:(.*)/s) : line.split(/-(.*)/s);
|
||||
let key = line.includes(":") ? data[0] +": " : data[0] +"- ";
|
||||
let value = data[1];
|
||||
// console.log(data);
|
||||
if(args === undefined || args.length === 0 || value.match(argsRegex) == null){
|
||||
//No args...
|
||||
let locId = collectionName + "_" + counter;
|
||||
outputEl.value += key + '\'[lang]' + locId + "[/lang]\'\n"
|
||||
// lang[currentLanguage] += key + value +"\n";
|
||||
// if(!(locId in data)) result[locId] = {};
|
||||
if(!(locId in result)) result[locId] = {};
|
||||
result[locId][currentLanguage] = parseResulting(value);
|
||||
counter++;
|
||||
return;
|
||||
}
|
||||
|
||||
let re = /[%<\[<\{]{1}[a-zA-Z_-]+[%>\]\}]{1}/g;
|
||||
let locId = collectionName + "_" + counter;
|
||||
outputEl.value += key + "'[lang]" +locId+"[args]";
|
||||
let m;
|
||||
let newVal = value;
|
||||
let argNum = 1;
|
||||
do {
|
||||
m = re.exec(value);
|
||||
if (m) {
|
||||
if(args.indexOf(m+"") > -1){
|
||||
outputEl.value+= "[arg]" + m + "[/arg]";
|
||||
newVal = newVal.replace(m+"", "%"+argNum);
|
||||
argNum++;
|
||||
}
|
||||
}
|
||||
} while (m);
|
||||
if(!(locId in result)) result[locId] = {};
|
||||
result[locId][currentLanguage] = parseResulting(newVal);
|
||||
outputEl.value += "[/args][/lang]'\n";
|
||||
counter++;
|
||||
});
|
||||
}
|
||||
|
||||
let dbHost = document.getElementById("db_host")
|
||||
let dbPort = document.getElementById("db_port")
|
||||
let dbUser = document.getElementById("db_user")
|
||||
let dbPass = document.getElementById("db_pass")
|
||||
let dbBase = document.getElementById("db_base")
|
||||
let dbPref = document.getElementById("db_prefix")
|
||||
|
||||
|
||||
function loadFromCache(){
|
||||
dbHost.value = localStorage.getItem("db_host") != null ? localStorage.getItem("db_host") : "";
|
||||
dbPort.value = localStorage.getItem("db_port") != null ? localStorage.getItem("db_port") : "3306";
|
||||
dbUser.value = localStorage.getItem("db_user") != null ? localStorage.getItem("db_user") : "";
|
||||
dbPass.value = localStorage.getItem("db_pass") != null ? localStorage.getItem("db_pass") : "";
|
||||
dbBase.value = localStorage.getItem("db_base") != null ? localStorage.getItem("db_base") : "";
|
||||
dbPref.value = localStorage.getItem("db_pref") != null ? localStorage.getItem("db_pref") : "triton_";
|
||||
}
|
||||
|
||||
function reset(){
|
||||
langCache = {};
|
||||
result = {};
|
||||
currentLanguage = undefined;
|
||||
collectionName = undefined;
|
||||
|
||||
collectionInput.value = "";
|
||||
inputEl.value = "";
|
||||
$(inputEl).attr("disabled");
|
||||
outputEl.value = "Please enter a Collection Name";
|
||||
languageSelector.value = "choose";
|
||||
}
|
||||
|
||||
function saveToCache(){
|
||||
localStorage.setItem("db_host", dbHost.value);
|
||||
localStorage.setItem("db_port", dbPort.value);
|
||||
localStorage.setItem("db_user", dbUser.value);
|
||||
localStorage.setItem("db_pass", dbPass.value);
|
||||
localStorage.setItem("db_base", dbBase.value);
|
||||
localStorage.setItem("db_pref", dbPref.value);
|
||||
}
|
||||
|
||||
function uploadToDB(){
|
||||
saveToCache();
|
||||
if(!collectionName || !currentLanguage) return;
|
||||
const data = {
|
||||
"database": {
|
||||
"host": dbHost.value === undefined ? "" : dbHost.value,
|
||||
"user": dbUser.value === undefined ? "" : dbUser.value,
|
||||
"pass": dbPass.value === undefined ? "" : dbPass.value,
|
||||
"base": dbBase.value === undefined ? "" : dbBase.value,
|
||||
"pref": dbPref.value === undefined ? "" : dbPref.value,
|
||||
"port": dbPort.value === undefined ? 3306 : parseInt(dbPort.value)
|
||||
},
|
||||
"collection": collectionName,
|
||||
"data": result
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(data));
|
||||
|
||||
$.ajax({
|
||||
url: "/index.php",
|
||||
method: "POST",
|
||||
// dataType: "json",
|
||||
data: { data: JSON.stringify(data)},
|
||||
success: (data) => {
|
||||
let result = JSON.parse(data);
|
||||
if(result.success) {
|
||||
alert("Successfully saved to database");
|
||||
}else {
|
||||
alert("Error saving to database <br> " + result.message);
|
||||
}
|
||||
document.getElementById("btn").innerHTML = "Upload translations to database";
|
||||
},
|
||||
error: (e, err, err1) => {
|
||||
alert("Error saving to database: <br> ");
|
||||
console.log(err);
|
||||
console.log(err1);
|
||||
document.getElementById("btn").innerHTML = "Upload translations to database";
|
||||
},
|
||||
beforeSend: () => { document.getElementById("btn").innerHTML = "Saving to database... Please wait" }
|
||||
})
|
||||
}
|
||||
|
||||
handleInput();
|
||||
loadFromCache();
|
||||
|
||||
//Register Listeners
|
||||
collectionInput.addEventListener("input", switchCollectionName);
|
||||
languageSelector.addEventListener("change", switchLang)
|
||||
inputEl.addEventListener("input", handleInput);
|
||||
document.getElementById("btn").addEventListener("click", uploadToDB)
|
||||
document.getElementById("reset").addEventListener("click", reset);
|
||||
2
js/jquery-3.7.1.min.js
vendored
Normal file
2
js/jquery-3.7.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
130
js/main.js
130
js/main.js
@@ -1,130 +0,0 @@
|
||||
const lang = {
|
||||
langKeyEmpty: "Please enter a language key"
|
||||
}
|
||||
|
||||
const prefixInput = document.getElementById("key");
|
||||
const tagInput = document.getElementById("add_arg")
|
||||
|
||||
const argsElement = document.getElementById("args");
|
||||
|
||||
const inputEl = document.getElementById("input");
|
||||
const outputEl = document.getElementById("output");
|
||||
|
||||
function handleInput(){
|
||||
let prefix = prefixInput.value;
|
||||
console.log(prefix);
|
||||
if(!prefix){
|
||||
outputEl.value = lang.langKeyEmpty;
|
||||
return;
|
||||
}
|
||||
|
||||
let value = inputEl.value.split("\n");
|
||||
|
||||
outputEl.value = "";
|
||||
|
||||
let regex = getRegex();
|
||||
let args = getArgs();
|
||||
|
||||
let counter = 0;
|
||||
|
||||
value.forEach(line => {
|
||||
if(line.startsWith("#")) {
|
||||
outputEl.value+=line + "\n";
|
||||
return;
|
||||
}
|
||||
let isListItem = false
|
||||
if(line.match(/:\s+["']|-\s+["']/i) == null){
|
||||
outputEl.value+=line + "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
isListItem = line.match(/-\s+["']/i) !=null;
|
||||
|
||||
let matches = line.match(regex);
|
||||
let key = isListItem ? line.split("-")[0] +"- " : line.split(":")[0] + ": ";
|
||||
|
||||
if(matches == null || args.length === 0){
|
||||
outputEl.value += key + "\"[lang]"+prefix +"_"+counter+"[/lang]\"\n";
|
||||
counter++;
|
||||
return;
|
||||
}
|
||||
|
||||
let re = /[%<\[<\{]{1}[a-zA-Z_-]+[%>\]\}]{1}/g;
|
||||
|
||||
outputEl.value += key + "\"[lang]" +prefix + "_"+counter+"[args]";
|
||||
let m;
|
||||
do {
|
||||
m = re.exec(line);
|
||||
if (m) {
|
||||
if(args.indexOf(m+"") > -1){
|
||||
outputEl.value+= "[arg]" + m + "[/arg]";
|
||||
}
|
||||
}
|
||||
} while (m);
|
||||
outputEl.value += "[/args][/lang]\"\n";
|
||||
counter++;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function handleTagInput(e) {
|
||||
let tagDiv = document.createElement("div");
|
||||
tagDiv.classList.add("arg")
|
||||
let el = document.createElement("span");
|
||||
el.innerHTML = tagInput.value.replace("<", "<").replace(">", ">");
|
||||
tagDiv.append(el);
|
||||
|
||||
let tagCloser = document.createElement("span")
|
||||
tagCloser.classList.add("delete-arg");
|
||||
tagCloser.innerHTML = "X";
|
||||
tagDiv.append(tagCloser);
|
||||
|
||||
tagCloser.addEventListener("click", deleteArg);
|
||||
|
||||
argsElement.append(tagDiv);
|
||||
tagInput.value = "";
|
||||
|
||||
handleInput()
|
||||
}
|
||||
|
||||
function copyResult(){
|
||||
outputEl.focus();
|
||||
outputEl.select();
|
||||
|
||||
document.execCommand("copy");
|
||||
}
|
||||
|
||||
function deleteArg(e) {
|
||||
e.target.removeEventListener("click", deleteArg);
|
||||
e.target.parentElement.remove();
|
||||
handleInput()
|
||||
}
|
||||
|
||||
function getArgs(){
|
||||
let args = [];
|
||||
for(let i = 0; i < argsElement.children.length; i++){
|
||||
args[i] = argsElement.children[i].children[0].innerHTML.trim().replace("<", "<").replace(">", ">");
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
function getRegex(){
|
||||
let args = getArgs();
|
||||
let regex = "";
|
||||
for(let i =0; i < args.length; i ++){
|
||||
if(i !== args.length-1) regex += args[i] + "|"
|
||||
else regex += args[i];
|
||||
}
|
||||
return new RegExp(regex);
|
||||
}
|
||||
|
||||
tagInput.addEventListener("change", handleTagInput);
|
||||
prefixInput.addEventListener("input", handleInput);
|
||||
inputEl.addEventListener("input", handleInput);
|
||||
|
||||
|
||||
document.getElementById("date").innerHTML = new Date().getFullYear();
|
||||
|
||||
// (() => {
|
||||
// let dateElem = document.getElementById("date");
|
||||
// })();
|
||||
50
js/utils.js
Normal file
50
js/utils.js
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
const argsElement = document.getElementById("args");
|
||||
const tagInput = document.getElementById("add_arg");
|
||||
const selectElem = document.getElementById("language");
|
||||
|
||||
function select(e){
|
||||
selectElem.removeEventListener("change", select);
|
||||
document.getElementById("input").attributes.removeNamedItem("disabled");
|
||||
}
|
||||
|
||||
function addArg() {
|
||||
let tagDiv= document.createElement("div");
|
||||
tagDiv.classList.add("arg")
|
||||
let el = document.createElement("span");
|
||||
el.innerHTML = tagInput.value.replace("<", "<").replace(">", ">");
|
||||
tagDiv.append(el);
|
||||
|
||||
let tagCloser = document.createElement("span")
|
||||
tagCloser.classList.add("delete-arg");
|
||||
tagCloser.innerHTML = "X";
|
||||
tagDiv.append(tagCloser);
|
||||
|
||||
tagCloser.addEventListener("click", deleteArg);
|
||||
|
||||
argsElement.append(tagDiv);
|
||||
tagInput.value = "";
|
||||
|
||||
handleInput();
|
||||
}
|
||||
|
||||
function deleteArg(e) {
|
||||
e.target.removeEventListener("click", deleteArg);
|
||||
e.target.parentElement.remove();
|
||||
handleInput()
|
||||
}
|
||||
|
||||
function copyResult(){
|
||||
let attr = outputEl.attributes.getNamedItem("disabled");
|
||||
outputEl.attributes.removeNamedItem("disabled")
|
||||
outputEl.focus();
|
||||
outputEl.select();
|
||||
document.execCommand("copy");
|
||||
outputEl.select();
|
||||
outputEl.attributes.setNamedItem(attr);
|
||||
}
|
||||
|
||||
tagInput.addEventListener("change", addArg);
|
||||
selectElem.addEventListener("change", select);
|
||||
|
||||
document.getElementById("date").innerHTML = new Date().getFullYear();
|
||||
Reference in New Issue
Block a user