Language plugin translation #361

This commit is contained in:
Jokob-sk
2023-08-17 07:33:48 +10:00
parent 39eb7fff1e
commit f35550663d
5 changed files with 36 additions and 52 deletions

View File

@@ -162,7 +162,7 @@ function cacheStrings()
});
// handle strings and translations from plugins
$.get('api/table_language_strings.json', function(res) {
$.get('api/table_plugins_language_strings.json', function(res) {
data = res["data"];
@@ -193,9 +193,14 @@ function getString (key) {
}
result = getCache(`pia_lang_${key}_${lang_code}`, true);
if(isEmpty(result))
{
console.log(`pia_lang_${key}_${lang_code}`)
console.log(key)
result = getCache(`pia_lang_${key}_en_us`, true);
console.log(result)
}
return result;

View File

@@ -136,38 +136,6 @@ function saveData (id) {
});
}
// -----------------------------------------------------------------------------
// Get translated string
function localize (obj, key) {
currLangCode = getCookie("language")
result = ""
en_us = ""
if(obj.localized && obj.localized.includes(key))
{
for(i=0;i<obj[key].length;i++)
{
code = obj[key][i]["language_code"]
if( code == 'en_us')
{
en_us = obj[key][i]["string"]
}
if(code == currLangCode)
{
result = obj[key][i]["string"]
}
}
}
result == "" ? result = en_us : result ;
return result;
}
// -----------------------------------------------------------------------------
pluginDefinitions = []
@@ -218,10 +186,11 @@ function generateTabs()
if(pluginObj.show_ui) // hiding plugins where specified
{
prefix = pluginObj.unique_prefix;
$('#tabs-location').append(
`<li class=" left-nav ${activetab}">
<a class=" col-sm-12 " href="#${pluginObj.unique_prefix}" data-plugin-prefix="${pluginObj.unique_prefix}" id="${pluginObj.unique_prefix}_id" data-toggle="tab" >
${localize(pluginObj, 'icon')} ${localize(pluginObj, 'display_name')}
<a class=" col-sm-12 " href="#${prefix}" data-plugin-prefix="${prefix}" id="${prefix}_id" data-toggle="tab" >
${getString(`${prefix}_icon`)} ${getString(`${prefix}_display_name`)}
</a>
</li>`
);
@@ -238,13 +207,14 @@ function generateTabs()
evRows = ""
obRows = ""
hiRows = ""
prefix = pluginObj.unique_prefix;
// Generate the header
$.each(pluginObj["database_column_definitions"], function(index, colDef){
if(colDef.show == true) // select only the ones to show
{
colDefinitions.push(colDef)
headersHtml += `<th class="${colDef.css_classes}" >${localize(colDef, "name" )}</th>`
headersHtml += `<th class="${colDef.css_classes}" >${getString(`${prefix}_${colDef.column}_name` )}</th>`
}
});
@@ -252,7 +222,7 @@ function generateTabs()
var eveCount = 0;
for(i=0;i<pluginUnprocessedEvents.length;i++)
{
if(pluginUnprocessedEvents[i].Plugin == pluginObj.unique_prefix)
if(pluginUnprocessedEvents[i].Plugin == prefix)
{
clm = ""
@@ -271,7 +241,7 @@ function generateTabs()
for(i=pluginHistory.length-1;i >= 0;i--) // from latest to the oldest
{
if(pluginHistory[i].Plugin == pluginObj.unique_prefix)
if(pluginHistory[i].Plugin == prefix)
{
if(histCount < 50) // only display 50 entries to optimize performance
{
@@ -293,7 +263,7 @@ function generateTabs()
var obCount = 0;
for(var i=0;i<pluginObjects.length;i++)
{
if(pluginObjects[i].Plugin == pluginObj.unique_prefix)
if(pluginObjects[i].Plugin == prefix)
{
if(shouldBeShown(pluginObjects[i], pluginObj)) // filter TODO
{
@@ -313,11 +283,11 @@ function generateTabs()
$('#tabs-content-location').append(
`
<div id="${pluginObj.unique_prefix}" class="tab-pane ${activetab}">
<div id="${prefix}" class="tab-pane ${activetab}">
<div class="nav-tabs-custom" style="margin-bottom: 0px">
<ul class="nav nav-tabs">
<li class="active" >
<a href="#objectsTarget_${pluginObj.unique_prefix}" data-toggle="tab" >
<a href="#objectsTarget_${prefix}" data-toggle="tab" >
<i class="fa fa-cube"></i> <?= lang('Plugins_Objects');?> (${obCount})
@@ -325,7 +295,7 @@ function generateTabs()
</li>
<li >
<a href="#eventsTarget_${pluginObj.unique_prefix}" data-toggle="tab" >
<a href="#eventsTarget_${prefix}" data-toggle="tab" >
<i class="fa fa-bolt"></i> <?= lang('Plugins_Unprocessed_Events');?> (${eveCount})
@@ -333,7 +303,7 @@ function generateTabs()
</li>
<li >
<a href="#historyTarget_${pluginObj.unique_prefix}" data-toggle="tab" >
<a href="#historyTarget_${prefix}" data-toggle="tab" >
<i class="fa fa-clock"></i> <?= lang('Plugins_History');?> (${histCountDisplayed} <?= lang('Plugins_Out_of');?> ${histCount})
@@ -346,7 +316,7 @@ function generateTabs()
<div class="tab-content">
<div id="objectsTarget_${pluginObj.unique_prefix}" class="tab-pane ${activetab}">
<div id="objectsTarget_${prefix}" class="tab-pane ${activetab}">
<table class="table table-striped" data-my-dbtable="Plugins_Objects">
<tbody>
<tr>
@@ -356,10 +326,10 @@ function generateTabs()
</tbody>
</table>
<div class="plugin-obj-purge">
<button class="btn btn-primary" onclick="purgeAll('${pluginObj.unique_prefix}', 'Plugins_Objects' )"><?= lang('Plugins_DeleteAll');?></button>
<button class="btn btn-primary" onclick="purgeAll('${prefix}', 'Plugins_Objects' )"><?= lang('Plugins_DeleteAll');?></button>
</div>
</div>
<div id="eventsTarget_${pluginObj.unique_prefix}" class="tab-pane">
<div id="eventsTarget_${prefix}" class="tab-pane">
<table class="table table-striped" data-my-dbtable="Plugins_Events">
<tbody>
@@ -370,10 +340,10 @@ function generateTabs()
</tbody>
</table>
<div class="plugin-obj-purge">
<button class="btn btn-primary" onclick="purgeAll('${pluginObj.unique_prefix}', 'Plugins_Events' )"><?= lang('Plugins_DeleteAll');?></button>
<button class="btn btn-primary" onclick="purgeAll('${prefix}', 'Plugins_Events' )"><?= lang('Plugins_DeleteAll');?></button>
</div>
</div>
<div id="historyTarget_${pluginObj.unique_prefix}" class="tab-pane">
<div id="historyTarget_${prefix}" class="tab-pane">
<table class="table table-striped" data-my-dbtable="Plugins_History">
<tbody>
@@ -384,7 +354,7 @@ function generateTabs()
</tbody>
</table>
<div class="plugin-obj-purge">
<button class="btn btn-primary" onclick="purgeAll('${pluginObj.unique_prefix}', 'Plugins_History' )"><?= lang('Plugins_DeleteAll');?></button>
<button class="btn btn-primary" onclick="purgeAll('${prefix}', 'Plugins_History' )"><?= lang('Plugins_DeleteAll');?></button>
</div>
</div>
@@ -393,7 +363,7 @@ function generateTabs()
<div class='plugins-description'>
${localize(pluginObj, 'description')}
${getString(prefix + '_description')}
<span>
<a href="https://github.com/jokob-sk/Pi.Alert/tree/main/front/plugins/${pluginObj.code_name}" target="_blank"><?= lang('Gen_ReadDocs');?></a>

View File

@@ -34,7 +34,7 @@ def update_api(db, isNotification = False, updateOnlyDataSources = []):
["plugins_events", sql_plugins_events],
["plugins_history", sql_plugins_history],
["plugins_objects", sql_plugins_objects],
["language_strings", sql_language_strings],
["plugins_language_strings", sql_language_strings],
["custom_endpoint", conf.API_CUSTOM_SQL],
]

View File

@@ -252,8 +252,16 @@ def importConfigs (db):
conf.mySchedules.append(schedule_class(pref, newSchedule, newSchedule.next(), False))
# Collect settings related language strings
# Creates an entry with key ARPSCAN_CMD_name
collect_lang_strings(db, set, pref + "_" + set["function"])
# Collect column related language strings
for clmn in plugin.get('database_column_definitions', []):
# Creates an entry with key ARPSCAN_Object_PrimaryID_name
collect_lang_strings(db, clmn, pref + "_" + clmn.get("column", ""))
conf.plugins_once_run = False
# -----------------
# Plugins END

View File

@@ -301,6 +301,7 @@ def execute_plugin(db, plugin, pluginsState = plugins_state() ):
sql.executemany ("""INSERT INTO Plugins_History ("Plugin", "Object_PrimaryID", "Object_SecondaryID", "DateTimeCreated", "DateTimeChanged", "Watched_Value1", "Watched_Value2", "Watched_Value3", "Watched_Value4", "Status" ,"Extra", "UserData", "ForeignKey") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", sqlParams)
db.commitDB()
# create objects
pluginsState = process_plugin_events(db, plugin, pluginsState)
# update API endpoints
@@ -532,7 +533,7 @@ def process_plugin_events(db, plugin, pluginsState):
sql.execute ("INSERT INTO Plugins_Events (Plugin, Object_PrimaryID, Object_SecondaryID, DateTimeCreated, DateTimeChanged, Watched_Value1, Watched_Value2, Watched_Value3, Watched_Value4, Status, Extra, UserData, ForeignKey) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", (plugObj.pluginPref, plugObj.primaryId , plugObj.secondaryId , createdTime, plugObj.changed , plugObj.watched1 , plugObj.watched2 , plugObj.watched3 , plugObj.watched4 , plugObj.status , plugObj.extra, plugObj.userData, plugObj.foreignKey ))
# Perform databse table mapping if enabled for the plugin
# Perform database table mapping if enabled for the plugin
if len(pluginEvents) > 0 and "mapped_to_table" in plugin:
# Initialize an empty list to store SQL parameters.